gempyre  1.7.1
Gempyre::Ui Class Reference

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. More...
 
 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. More...
 
 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. More...
 
 ~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. More...
 
ReloadFunction on_reload (const ReloadFunction &onReloadFunction)
 The callback is called on UI reload. More...
 
OpenFunction on_open (const OpenFunction &onOpenFunction)
 The callback is called on UI open. More...
 
ErrorFunction on_error (const ErrorFunction &onErrorFunction)
 The callback called on UI error. More...
 
void run ()
 Starts the event loop. More...
 
void set_logging (bool logging)
 Set browser to verbose mode. More...
 
void eval (std::string_view eval)
 Executes eval string in UI context. More...
 
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. More...
 
TimerId start_periodic (const std::chrono::milliseconds &ms, const std::function< void(TimerId id)> &timerFunc)
 Start a periodic timer. More...
 
TimerId start_periodic (const std::chrono::milliseconds &ms, const std::function< void()> &timerFunc)
 Start a periodic timer. More...
 
TimerId after (const std::chrono::milliseconds &ms, const std::function< void(TimerId id)> &timerFunc)
 Starts a single shot timer. More...
 
TimerId after (const std::chrono::milliseconds &ms, const std::function< void()> &timerFunc)
 Starts a single shot timer. More...
 
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::Elementsby_class (std::string_view className) const
 Get elements by class name.
 
std::optional< Element::Elementsby_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. More...
 
bool add_file (std::string_view url, std::string_view file)
 Add a file data into Gempyre to be accessed via url. More...
 
std::optional< std::string > add_file (std::string_view file)
 Add a file data into Gempyre to be accessed via url. More...
 
bool add_data (std::string_view url, const std::vector< uint8_t > &data)
 Add a data into Gempyre to be accessed via url. More...
 
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. More...
 
static Ui::FileMap to_file_map (const std::vector< std::string > &filenames)
 Read list files as a maps.
 

Friends

class Element
 

Detailed Description

The application UI.

Constructor & Destructor Documentation

◆ Ui() [1/3]

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.

Parameters
filemapresource map used
indexHtmlpage to show
portoptional
rootoptional

◆ Ui() [2/3]

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.

Parameters
filemapresource map used.
indexHtmlpage to show.
browserbrowser to use.
browser_paramsparams passed to browse.
portoptional
rootoptional

◆ Ui() [3/3]

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.

Parameters
filemapresource map used.
indexHtmlpage to show.
titlewindow title.
widthwindow width - this may be less than a window client area.
heightwindow height - this may be less than a window client area.
flagsflags passed to the window - see UiFlags.
ui_paramsextra parameters passed to the window.
portoptional
rootoptional

Member Function Documentation

◆ add_data()

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.

Parameters
urlstring bound to data.
datadata to write.
Returns

◆ add_file() [1/3]

static std::optional<std::string> Gempyre::Ui::add_file ( FileMap map,
std::string_view  filename 
)
static

Add file data into map to be added as a map.

Parameters
mapresource data.
filenamefilename to read.
Returns
name bound to the file

◆ add_file() [2/3]

std::optional<std::string> Gempyre::Ui::add_file ( std::string_view  file)

Add a file data into Gempyre to be accessed via url.

Parameters
filefilename to read.
Returns
success.

◆ add_file() [3/3]

bool Gempyre::Ui::add_file ( std::string_view  url,
std::string_view  file 
)

Add a file data into Gempyre to be accessed via url.

Parameters
urlstring bound to data.
filefilename to read.
Returns
success.

◆ after() [1/2]

TimerId Gempyre::Ui::after ( const std::chrono::milliseconds &  ms,
const std::function< void()> &  timerFunc 
)

Starts a single shot timer.

Parameters
msperiod
timerFunc- callback
Returns
timer id that can be used to cancel this timer.

◆ after() [2/2]

TimerId Gempyre::Ui::after ( const std::chrono::milliseconds &  ms,
const std::function< void(TimerId id)> &  timerFunc 
)

Starts a single shot timer.

Parameters
msperiod
timerFunc- callback
Returns
timer id that can be used to cancel this timer.

◆ eval()

void Gempyre::Ui::eval ( std::string_view  eval)

Executes eval string in UI context.

Parameters
evalJavascript to be executed.

◆ on_error()

ErrorFunction Gempyre::Ui::on_error ( const ErrorFunction onErrorFunction)

The callback called on UI error.

Parameters
onErrorFunction
Returns
previous error function

◆ on_exit()

ExitFunction Gempyre::Ui::on_exit ( const ExitFunction onExitFunction)

The callback is called before before the eventloop exit.

Parameters
onExitFunction
Returns
previous exit function.

◆ on_open()

OpenFunction Gempyre::Ui::on_open ( const OpenFunction onOpenFunction)

The callback is called on UI open.

Parameters
onOpenFunction
Returns
previous open function

this function is 1st function that is called when UI is initialized. Hence it can used for tasks that requires fetching information from UI.

See also
run.

◆ on_reload()

ReloadFunction Gempyre::Ui::on_reload ( const ReloadFunction onReloadFunction)

The callback is called on UI reload.

Parameters
onReloadFunction
Returns
previous reload function.

◆ open()

void Gempyre::Ui::open ( std::string_view  url,
std::string_view  name = "" 
)

Opens an url in the UI view.

Parameters
urladdress
nametitle

◆ resource()

std::optional<std::vector<uint8_t> > Gempyre::Ui::resource ( std::string_view  url) const

Read a resource.

Parameters
urlresource name.
Returns
resource as bytes.

◆ run()

void Gempyre::Ui::run ( )

Starts the event loop.

The window or browser UI is called only after 'run' and callbacks can be received. this also means that no queries can be done before, therefore it is suggested that initialization of UI is finalished in

See also
onOpenFunction callback. 'run' return on UI exit.

◆ set_logging()

void Gempyre::Ui::set_logging ( bool  logging)

Set browser to verbose mode.

Parameters
logging

◆ start_periodic() [1/2]

TimerId Gempyre::Ui::start_periodic ( const std::chrono::milliseconds &  ms,
const std::function< void()> &  timerFunc 
)

Start a periodic timer.

Parameters
msperiod.
timerFunccallback
Returns
timer id that can be used to cancel this timer.

◆ start_periodic() [2/2]

TimerId Gempyre::Ui::start_periodic ( const std::chrono::milliseconds &  ms,
const std::function< void(TimerId id)> &  timerFunc 
)

Start a periodic timer.

Parameters
msperiod.
timerFunccallback
Returns
timer id that can be used to cancel this timer.

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