|
gempyre 1.8.7
|
The application UI. More...
#include <gempyre.h>
Public Types | |
| enum | UiFlags : unsigned { NoResize = 0x1 , FullScreen = 0x2 , Hidden = 0x4 , Frameless = 0x8 , Minimized = 0x10 , OnTop = 0x20 , ConfirmClose = 0x40 , TextSelect = 0x80 , EasyDrag = 0x100 , Transparent = 0x200 } |
| UI flags for a Window UI. | |
| using | FileMap = std::vector< std::pair< std::string, std::string > > |
| Resource map type. | |
| using | ExitFunction = std::function< void()> |
| Function called on exit. | |
| using | ReloadFunction = std::function< void()> |
| Function called on reload. (page reload) | |
| using | OpenFunction = std::function< void()> |
| Function called on open.x. | |
| using | ErrorFunction = std::function< void(const std::string &element, const std::string &info)> |
| Function called on UI error. | |
Public Member Functions | |
| Ui (const FileMap &filemap, std::string_view indexHtml, unsigned short port=UseDefaultPort, std::string_view root=UseDefaultRoot) | |
| Create UI using default ui app or gempyre.conf. | |
| Ui (const FileMap &filemap, std::string_view indexHtml, std::string_view browser, std::string_view browser_params, unsigned short port=UseDefaultPort, std::string_view root=UseDefaultRoot) | |
| Create a browser UI using given ui app and command line. | |
| Ui (const FileMap &filemap, std::string_view indexHtml, std::string_view title, int width, int height, unsigned flags=0, const std::unordered_map< std::string, std::string > &ui_params={}, unsigned short port=UseDefaultPort, std::string_view root=UseDefaultRoot) | |
| Create a window UI. | |
| ~Ui () | |
| Destructor. | |
| Ui (const Ui &other)=delete | |
| Ui (Ui &&other)=delete | |
| void | exit () |
| Application gracefully finish the event loop and exits. | |
| void | close () |
| Requires Client window to close (that cause the application to close). | |
| ExitFunction | on_exit (const ExitFunction &onExitFunction) |
| The callback is called before before the eventloop exit. | |
| ReloadFunction | on_reload (const ReloadFunction &onReloadFunction) |
| The callback is called on UI reload. | |
| OpenFunction | on_open (const OpenFunction &onOpenFunction) |
| The callback is called on UI open. | |
| ErrorFunction | on_error (const ErrorFunction &onErrorFunction) |
| The callback called on UI error. | |
| void | run () |
| Starts the event loop. | |
| void | set_logging (bool logging) |
| Set browser to verbose mode. | |
| void | eval (std::string_view eval) |
| Executes eval string in UI context. | |
| void | debug (std::string_view msg) |
| Send a debug message to UI. Message is get received is set_logging is true. | |
| void | alert (std::string_view msg) |
| Show an alert window. | |
| void | open (std::string_view url, std::string_view name="") |
| Opens an url in the UI view. | |
| TimerId | start_periodic (const std::chrono::milliseconds &ms, const std::function< void(TimerId id)> &timerFunc) |
| Start a periodic timer. | |
| TimerId | start_periodic (const std::chrono::milliseconds &ms, const std::function< void()> &timerFunc) |
| Start a periodic timer. | |
| TimerId | after (const std::chrono::milliseconds &ms, const std::function< void(TimerId id)> &timerFunc) |
| Starts a single shot timer. | |
| TimerId | after (const std::chrono::milliseconds &ms, const std::function< void()> &timerFunc) |
| Starts a single shot timer. | |
| bool | cancel_timer (TimerId timerId) |
| Stop a timer. | |
| Element | root () const |
| Get a (virtual) root element. | |
| std::string | address_of (std::string_view filepath) const |
| Get a local file path an URL, can be used with open. | |
| std::optional< Element::Elements > | by_class (std::string_view className) const |
| Get elements by class name. | |
| std::optional< Element::Elements > | by_name (std::string_view className) const |
| Get elements by name. | |
| std::optional< std::pair< std::chrono::microseconds, std::chrono::microseconds > > | ping () const |
| Test function to measure round trip time. | |
| std::optional< std::vector< uint8_t > > | resource (std::string_view url) const |
| Read a resource. | |
| bool | add_file (std::string_view url, std::string_view file) |
| Add a file data into Gempyre to be accessed via url. | |
| std::optional< std::string > | add_file (std::string_view file) |
| Add a file data into Gempyre to be accessed via url. | |
| bool | add_data (std::string_view url, const std::vector< uint8_t > &data) |
| Add a data into Gempyre to be accessed via url. | |
| void | begin_batch () |
| Starts an UI write batch, no messages are sent to USER until endBatch. | |
| void | end_batch () |
| Ends an UI read batch, push all stored messages at once. | |
| void | set_timer_on_hold (bool on_hold) |
| Set all timers to hold. Can be used to pause UI actions. | |
| bool | is_timer_on_hold () const |
| Tells if timers are on hold. | |
| std::optional< double > | device_pixel_ratio () const |
| Get an native UI device pixel ratio. | |
| void | set_application_icon (const uint8_t *data, size_t dataLen, std::string_view type) |
| Set application icon, fail silently if backend wont support. | |
| void | resize (int width, int height) |
| Resize, fail silently if backend wont support. | |
| void | set_title (std::string_view name) |
| Set title, fail silently if backend wont support. | |
| void | flush () |
| Write pending requests to UI - e.g. when eventloop thread is blocked. | |
| bool | available (std::string_view id) const |
| test if Element can be accessed. Note that in false it's may be in HTML, but not available in DOM tree. | |
Static Public Member Functions | |
| static std::optional< std::string > | add_file (FileMap &map, std::string_view filename) |
| Add file data into map to be added as a map. | |
| static Ui::FileMap | to_file_map (const std::vector< std::string > &filenames) |
| Read list files as a maps. | |
Friends | |
| class | Element |
The application UI.
| Gempyre::Ui::Ui | ( | const FileMap & | filemap, |
| std::string_view | indexHtml, | ||
| unsigned short | port = UseDefaultPort, |
||
| std::string_view | root = UseDefaultRoot |
||
| ) |
Create UI using default ui app or gempyre.conf.
| filemap | resource map used |
| indexHtml | page to show |
| port | optional |
| root | optional |
| Gempyre::Ui::Ui | ( | const FileMap & | filemap, |
| std::string_view | indexHtml, | ||
| std::string_view | browser, | ||
| std::string_view | browser_params, | ||
| unsigned short | port = UseDefaultPort, |
||
| std::string_view | root = UseDefaultRoot |
||
| ) |
Create a browser UI using given ui app and command line.
| filemap | resource map used. |
| indexHtml | page to show. |
| browser | browser to use. |
| browser_params | params passed to browse. |
| port | optional |
| root | optional |
| Gempyre::Ui::Ui | ( | const FileMap & | filemap, |
| std::string_view | indexHtml, | ||
| std::string_view | title, | ||
| int | width, | ||
| int | height, | ||
| unsigned | flags = 0, |
||
| const std::unordered_map< std::string, std::string > & | ui_params = {}, |
||
| unsigned short | port = UseDefaultPort, |
||
| std::string_view | root = UseDefaultRoot |
||
| ) |
Create a window UI.
| filemap | resource map used. |
| indexHtml | page to show. |
| title | window title. |
| width | window width - this may be less than a window client area. |
| height | window height - this may be less than a window client area. |
| flags | flags passed to the window - see UiFlags. |
| ui_params | extra parameters passed to the window. |
| port | optional |
| root | optional |
| bool Gempyre::Ui::add_data | ( | std::string_view | url, |
| const std::vector< uint8_t > & | data | ||
| ) |
Add a data into Gempyre to be accessed via url.
| url | string bound to data. |
| data | data to write. |
|
static |
Add file data into map to be added as a map.
| map | resource data. |
| filename | filename to read. |
| std::optional< std::string > Gempyre::Ui::add_file | ( | std::string_view | file | ) |
Add a file data into Gempyre to be accessed via url.
| file | filename to read. |
| bool Gempyre::Ui::add_file | ( | std::string_view | url, |
| std::string_view | file | ||
| ) |
Add a file data into Gempyre to be accessed via url.
| url | string bound to data. |
| file | filename to read. |
| TimerId Gempyre::Ui::after | ( | const std::chrono::milliseconds & | ms, |
| const std::function< void()> & | timerFunc | ||
| ) |
Starts a single shot timer.
| ms | period |
| timerFunc | - callback |
| TimerId Gempyre::Ui::after | ( | const std::chrono::milliseconds & | ms, |
| const std::function< void(TimerId id)> & | timerFunc | ||
| ) |
Starts a single shot timer.
| ms | period |
| timerFunc | - callback |
| void Gempyre::Ui::eval | ( | std::string_view | eval | ) |
Executes eval string in UI context.
| eval | Javascript to be executed. |
| ErrorFunction Gempyre::Ui::on_error | ( | const ErrorFunction & | onErrorFunction | ) |
The callback called on UI error.
| onErrorFunction |
| ExitFunction Gempyre::Ui::on_exit | ( | const ExitFunction & | onExitFunction | ) |
The callback is called before before the eventloop exit.
| onExitFunction |
| OpenFunction Gempyre::Ui::on_open | ( | const OpenFunction & | onOpenFunction | ) |
The callback is called on UI open.
| onOpenFunction |
this function is 1st function that is called when UI is initialized. Hence it can used for tasks that requires fetching information from UI.
| ReloadFunction Gempyre::Ui::on_reload | ( | const ReloadFunction & | onReloadFunction | ) |
The callback is called on UI reload.
| onReloadFunction |
| void Gempyre::Ui::open | ( | std::string_view | url, |
| std::string_view | name = "" |
||
| ) |
Opens an url in the UI view.
| url | address |
| name | title |
| std::optional< std::vector< uint8_t > > Gempyre::Ui::resource | ( | std::string_view | url | ) | const |
Read a resource.
| url | resource name. |
| void Gempyre::Ui::run | ( | ) |
| void Gempyre::Ui::set_logging | ( | bool | logging | ) |
Set browser to verbose mode.
| logging |
| TimerId Gempyre::Ui::start_periodic | ( | const std::chrono::milliseconds & | ms, |
| const std::function< void()> & | timerFunc | ||
| ) |
Start a periodic timer.
| ms | period. |
| timerFunc | callback |
| TimerId Gempyre::Ui::start_periodic | ( | const std::chrono::milliseconds & | ms, |
| const std::function< void(TimerId id)> & | timerFunc | ||
| ) |
Start a periodic timer.
| ms | period. |
| timerFunc | callback |