gempyre
1.7.1
|
Represents all HTML elements on UI. More...
#include <gempyre.h>
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. | |
Element & | operator= (const Element &other) |
Copy operator. | |
Element & | operator= (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 Ui & | ui () const |
Get Ui. | |
Ui & | ui () |
Get Ui. | |
std::string | id () const |
Get id of element. | |
Element & | subscribe (std::string_view name, const SubscribeFunction &handler, const std::vector< std::string > &properties={}, const std::chrono::milliseconds &throttle=0ms) |
Subscribe UI event. More... | |
Element & | set_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... | |
Element & | set_attribute (std::string_view attr, std::string_view value) |
Set HTML a attribute of this element. More... | |
Element & | set_attribute (std::string_view attr) |
Set HTML a attribute of this element. More... | |
std::optional< Attributes > | attributes () const |
Get this element attributes. | |
Element & | set_style (std::string_view style, std::string_view value) |
Set CSS style of this element. More... | |
Element & | remove_attribute (std::string_view attr) |
Remove attribute. More... | |
std::optional< Values > | styles (const std::vector< std::string > &keys) const |
Get element styles. More... | |
std::optional< Elements > | children () const |
Get element children. | |
std::optional< Values > | values () 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< Rect > | rect () const |
Get this element UI rect. I.e area it occupies on screen (if applicable) | |
std::optional< Element > | parent () const |
Parent of this element. If query fails, element is root or parent id is not set, nullopt is returned. | |
Friends | |
class | GempyreInternal |
Represents all HTML elements on UI.
using Gempyre::Element::Rect = Gempyre::Rect |
compatibility
using Gempyre::Element::SubscribeFunction = std::function<void(const Event&)> |
Callback function for event subscriptions.
Gempyre::Element::Element | ( | Ui & | ui, |
std::string_view | id | ||
) |
Constructor for existing elements.
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.
Gempyre::Element::Element | ( | Ui & | ui, |
std::string_view | id, | ||
std::string_view | htmlElement, | ||
const Element & | parent | ||
) |
Constructor for exiting elements.
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 |
Constructor for exiting elements.
ui | - ui ref |
htmlElement | - element type |
parent | - parent element where this element is created |
HtmlStream Gempyre::Element::html_stream | ( | ) |
get a stream that writes to html part of this element
Element& Gempyre::Element::remove_attribute | ( | std::string_view | attr | ) |
Element& Gempyre::Element::set_attribute | ( | std::string_view | attr | ) |
Set HTML a attribute of this element.
attr | - attribute name |
Element& Gempyre::Element::set_attribute | ( | std::string_view | attr, |
std::string_view | value | ||
) |
Set HTML a attribute of this element.
attr | - attribute name |
value | - attribute value |
Element& Gempyre::Element::set_html | ( | std::string_view | htmlText | ) |
Set HTML text value of the element.
htmlText | - HTML encoded string |
Element& Gempyre::Element::set_style | ( | std::string_view | style, |
std::string_view | value | ||
) |
Set CSS style of this element.
style | - style name |
value | - CSS style value |
std::optional<Values> Gempyre::Element::styles | ( | const std::vector< std::string > & | keys | ) | const |
Get element styles.
keys | - style keys to fetch. |
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.
name | - name of the event. |
handler | - function executed on event. |
properties | - optional, event properties to listen. |
throttle | - optional, throttle callback calls |
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.