gempyre  1.7.1
Gempyre::Element Class Reference

Represents all HTML elements on UI. More...

#include <gempyre.h>

Inheritance diagram for Gempyre::Element:
[legend]

Public Types

using Attributes = std::unordered_map< std::string, std::string >
 Attribute key, value pairs.
 
using Values = std::unordered_map< std::string, std::string >
 Value key, value pairs.
 
using Elements = std::vector< Element >
 Vector of Elements.
 
using SubscribeFunction = std::function< void(const Event &)>
 Callback function for event subscriptions. More...
 
using Rect = Gempyre::Rect
 compatibility More...
 

Public Member Functions

 Element (const Element &other)=default
 Copy constructor.
 
 Element (Element &&other)=default
 Move constructor.
 
Elementoperator= (const Element &other)
 Copy operator.
 
Elementoperator= (Element &&other)
 Move operator.
 
 Element (Ui &ui, std::string_view id)
 Constructor for existing elements. More...
 
 Element (Ui &ui, std::string_view id, std::string_view htmlElement, const Element &parent)
 Constructor for exiting elements. More...
 
 Element (Ui &ui, std::string_view htmlElement, const Element &parent)
 Constructor for exiting elements. More...
 
virtual ~Element ()
 Destructor.
 
const Uiui () const
 Get Ui.
 
Uiui ()
 Get Ui.
 
std::string id () const
 Get id of element.
 
Elementsubscribe (std::string_view name, const SubscribeFunction &handler, const std::vector< std::string > &properties={}, const std::chrono::milliseconds &throttle=0ms)
 Subscribe UI event. More...
 
Elementset_html (std::string_view htmlText)
 Set HTML text value of the element. More...
 
HtmlStream html_stream ()
 get a stream that writes to html part of this element More...
 
Elementset_attribute (std::string_view attr, std::string_view value)
 Set HTML a attribute of this element. More...
 
Elementset_attribute (std::string_view attr)
 Set HTML a attribute of this element. More...
 
std::optional< Attributesattributes () const
 Get this element attributes.
 
Elementset_style (std::string_view style, std::string_view value)
 Set CSS style of this element. More...
 
Elementremove_attribute (std::string_view attr)
 Remove attribute. More...
 
std::optional< Valuesstyles (const std::vector< std::string > &keys) const
 Get element styles. More...
 
std::optional< Elementschildren () const
 Get element children.
 
std::optional< Valuesvalues () const
 Applies to form elements only - receive values bound to the element.
 
std::optional< std::string > html () const
 Get HTML value bound to this element (does not apply all elements)
 
void remove ()
 Remove this element from UI.
 
std::optional< std::string > type () const
 Get this element type, mostly a HTML tag.
 
std::optional< Rectrect () const
 Get this element UI rect. I.e area it occupies on screen (if applicable)
 
std::optional< Elementparent () const
 Parent of this element. If query fails, element is root or parent id is not set, nullopt is returned.
 

Friends

class GempyreInternal
 

Detailed Description

Represents all HTML elements on UI.

Member Typedef Documentation

◆ Rect

compatibility

See also
Gempyre::Rect.

◆ SubscribeFunction

using Gempyre::Element::SubscribeFunction = std::function<void(const Event&)>

Callback function for event subscriptions.

See also
Element::subscribe.

Constructor & Destructor Documentation

◆ Element() [1/3]

Gempyre::Element::Element ( Ui ui,
std::string_view  id 
)

Constructor for existing elements.

Parameters
ui- ui ref
id- if of element assumed to exists in HTML document (or DOM)

Constructor is very lightweight and many cases its easier to create a new element rather than copy or move one.

◆ Element() [2/3]

Gempyre::Element::Element ( Ui ui,
std::string_view  id,
std::string_view  htmlElement,
const Element parent 
)

Constructor for exiting elements.

Parameters
ui- ui ref
id- assumed be unique, if id is not important to preset, use constructor without id.
htmlElement- element type
parent- parent element where this element is created

◆ Element() [3/3]

Gempyre::Element::Element ( Ui ui,
std::string_view  htmlElement,
const Element parent 
)

Constructor for exiting elements.

Parameters
ui- ui ref
htmlElement- element type
parent- parent element where this element is created

Member Function Documentation

◆ html_stream()

HtmlStream Gempyre::Element::html_stream ( )

get a stream that writes to html part of this element

Returns
a string stream

◆ remove_attribute()

Element& Gempyre::Element::remove_attribute ( std::string_view  attr)

Remove attribute.

Parameters
attr- attribute name
Returns
this Element

◆ set_attribute() [1/2]

Element& Gempyre::Element::set_attribute ( std::string_view  attr)

Set HTML a attribute of this element.

Parameters
attr- attribute name
Returns
this element

◆ set_attribute() [2/2]

Element& Gempyre::Element::set_attribute ( std::string_view  attr,
std::string_view  value 
)

Set HTML a attribute of this element.

Parameters
attr- attribute name
value- attribute value
Returns
this element

◆ set_html()

Element& Gempyre::Element::set_html ( std::string_view  htmlText)

Set HTML text value of the element.

Parameters
htmlText- HTML encoded string
Returns
this element

◆ set_style()

Element& Gempyre::Element::set_style ( std::string_view  style,
std::string_view  value 
)

Set CSS style of this element.

Parameters
style- style name
value- CSS style value
Returns
this element

◆ styles()

std::optional<Values> Gempyre::Element::styles ( const std::vector< std::string > &  keys) const

Get element styles.

Parameters
keys- style keys to fetch.

◆ subscribe()

Element& Gempyre::Element::subscribe ( std::string_view  name,
const SubscribeFunction handler,
const std::vector< std::string > &  properties = {},
const std::chrono::milliseconds &  throttle = 0ms 
)

Subscribe UI event.

Parameters
name- name of the event.
handler- function executed on event.
properties- optional, event properties to listen.
throttle- optional, throttle callback calls
Returns
this element

Listen element events. The callback properties is populated only with values listed in properties parameter. Some events (like mouse move) can emit so often that it would impact to performance, that can be eased with a suitable throttle value. If two (or more) messages are received in shorted period than throttle value, only the last is received.


The documentation for this class was generated from the following file: