GUIFramework 1.1.0
Framework for desktop GUI applications in C++.
Loading...
Searching...
No Matches
gui_framework::GUIFramework Class Reference

Singleton with GUIFramework settings and some functionality. More...

#include <GUIFramework.h>

Classes

struct  hotkeyData
 

Public Member Functions

std::unique_ptr< threading::Future > addTask (const std::function< void()> &task, const std::function< void()> &callback=nullptr)
 Add task to thread pool. Thread safe method.
 
std::unique_ptr< threading::Future > addTask (const std::function< void()> &task, std::function< void()> &&callback)
 Add task to thread pool. Thread safe method.
 
std::unique_ptr< threading::Future > addTask (std::function< void()> &&task, const std::function< void()> &callback=nullptr)
 Add task to thread pool. Thread safe method.
 
std::unique_ptr< threading::Future > addTask (std::function< void()> &&task, std::function< void()> &&callback)
 Add task to thread pool. Thread safe method.
 
size_t registerHotkey (hotkeys::keys key, const std::function< void()> &onClick, const std::vector< hotkeys::additionalKeys > &additionalKeys={})
 Only works in thread, that call runMainLoop from WindowHolder. Thread safe register hotkey.
 
size_t registerHotkey (hotkeys::keys key, const std::string &functionName, const std::string &moduleName, const std::vector< hotkeys::additionalKeys > &additionalKeys={})
 Only works in thread, that call runMainLoop from WindowHolder. Thread safe register hotkey.
 
bool unregisterHotkey (size_t hotkeyId)
 Thread safe unregister hotkey.
 
bool unregisterHotkey (uint32_t key, const std::vector< hotkeys::additionalKeys > &additionalKeys={})
 Thread safe unregister hotkey.
 
std::vector< hotkeyDatagetRegisteredHotkeys ()
 Thread safe get hotkeys.
 
void loadModule (const std::string &moduleName, const std::filesystem::path &pathToModule)
 Load module with some sort of data.
 
void unloadModule (const std::string &moduleName)
 Unload module.
 
bool isExist (BaseComponent *component)
 Check if component created. If component destroyed after you call findComponent, you may have not valid pointer.
 
std::vector< json::utility::jsonObject > serializeHotkeys ()
 Serialize hotkeys.
 
void deserializeHotkeys (const json::utility::jsonObject &description)
 Deserialize hotkeys.
 
bool isModulesLoaded () const
 Check if modules are loaded. You can call getCantLoadedModules() to check if loaded modules have failed.
 
void changeLocalization (const std::string &language) const
 Change localization for all components.
 
const std::unordered_map< size_t, smartPointerType< utility::BaseComponentCreator > > & getCreators () const
 Get all current registered creators.
 
const std::unordered_map< size_t, smartPointerType< interfaces::IDeserializer > > & getDeserializers () const
 Get all current registered deserializers.
 
const json::JSONParser & getJSONSettings () const
 Get settings from gui_framework.json.
 
const std::unordered_map< std::string, HMODULE, localization::utility::StringViewHash, localization::utility::StringViewEqual > & getModules () const
 Get all loaded modules.
 
const std::unordered_map< std::string, std::string > & getModulesPaths () const
 Get all loaded modules paths.
 
std::vector< std::string > getCantLoadedModules ()
 List of all exceptions in load modules process.
 
HMODULE operator[] (const std::string &moduleName) const
 Get handle to specific module.
 
template<typename T = BaseComponent>
T * findComponent (HWND handle)
 Thread safe.
 
template<typename T = BaseComponent>
T * findComponent (const std::wstring &componentName)
 Thread safe.
 
template<std::derived_from< BaseComponent > T, std::derived_from< utility::BaseComponentCreator > CreatorT, typename... Args>
void addCreator (Args &&... args)
 Add derived from BaseComponentCreator creator.
 
template<std::derived_from< BaseComponent > T, std::derived_from< interfaces::IDeserializer > DeserializerT, typename... Args>
void addDeserializer (Args &&... args)
 Add derived from IDeserializer deserializer.
 

Static Public Member Functions

static GUIFrameworkget ()
 Singleton instance access.
 
static void runOnUIThread (const std::function< void()> &function)
 Run function in UI thread. Functions processed only when window in main UI thread has focus.
 
static void runOnUIThread (std::function< void()> &&function)
 Run function in UI thread. Functions processed only when window in main UI thread has focus.
 
static void restartApplication (int exitCode=0)
 Restart application with given exit code.
 
static DWORD getUIThreadId ()
 Getter for UI thread id.
 
static std::string getGUIFrameworkVersion ()
 Get current GUIFramework version.
 

Friends

class BaseComponent
 
class WindowHolder
 
class BaseDialogBox
 
class BaseMainWindow
 
struct std::default_delete< GUIFramework >
 

Detailed Description

Singleton with GUIFramework settings and some functionality.

Definition at line 23 of file GUIFramework.h.

Member Function Documentation

◆ addCreator()

template<std::derived_from< BaseComponent > T, std::derived_from< utility::BaseComponentCreator > CreatorT, typename... Args>
void gui_framework::GUIFramework::addCreator ( Args &&... args)

Add derived from BaseComponentCreator creator.

Definition at line 323 of file GUIFramework.h.

◆ addDeserializer()

template<std::derived_from< BaseComponent > T, std::derived_from< interfaces::IDeserializer > DeserializerT, typename... Args>
void gui_framework::GUIFramework::addDeserializer ( Args &&... args)

Add derived from IDeserializer deserializer.

Definition at line 329 of file GUIFramework.h.

◆ addTask() [1/4]

std::unique_ptr< threading::Future > gui_framework::GUIFramework::addTask ( const std::function< void()> & task,
const std::function< void()> & callback = nullptr )

Add task to thread pool. Thread safe method.

Parameters
taskTask function
callbackAfter execution task callback function
Exceptions
std::runtime_errorCan't find threadsCount setting in gui_framework.json

◆ addTask() [2/4]

std::unique_ptr< threading::Future > gui_framework::GUIFramework::addTask ( const std::function< void()> & task,
std::function< void()> && callback )

Add task to thread pool. Thread safe method.

Parameters
taskTask function
callbackAfter execution task callback function
Exceptions
std::runtime_errorCan't find threadsCount setting in gui_framework.json

◆ addTask() [3/4]

std::unique_ptr< threading::Future > gui_framework::GUIFramework::addTask ( std::function< void()> && task,
const std::function< void()> & callback = nullptr )

Add task to thread pool. Thread safe method.

Parameters
taskTask function
callbackAfter execution task callback function
Exceptions
std::runtime_errorCan't find threadsCount setting in gui_framework.json

◆ addTask() [4/4]

std::unique_ptr< threading::Future > gui_framework::GUIFramework::addTask ( std::function< void()> && task,
std::function< void()> && callback )

Add task to thread pool. Thread safe method.

Parameters
taskTask function
callbackAfter execution task callback function
Exceptions
std::runtime_errorCan't find threadsCount setting in gui_framework.json

◆ changeLocalization()

void gui_framework::GUIFramework::changeLocalization ( const std::string & language) const

Change localization for all components.

Parameters
languageNew language

Definition at line 950 of file GUIFramework.cpp.

◆ deserializeHotkeys()

void gui_framework::GUIFramework::deserializeHotkeys ( const json::utility::jsonObject & description)

Deserialize hotkeys.

Parameters
descriptionDescription of holder window with 'hotkeys' object

Definition at line 921 of file GUIFramework.cpp.

◆ findComponent() [1/2]

template<typename T >
T * gui_framework::GUIFramework::findComponent ( const std::wstring & componentName)

Thread safe.

Parameters
componentName
Returns
Found component or nullptr

Definition at line 313 of file GUIFramework.h.

◆ findComponent() [2/2]

template<typename T >
T * gui_framework::GUIFramework::findComponent ( HWND handle)

Thread safe.

Parameters
handle
Returns
Found component or nullptr

Definition at line 303 of file GUIFramework.h.

◆ get()

static GUIFramework & gui_framework::GUIFramework::get ( )
static

Singleton instance access.

Returns
Singleton instance
Exceptions
json::exceptions::CantFindValueExceptionUnable to find setting in gui_framework.json on first GUIFramework::get() call @excepiton std::runtime_error Can't find gui_framework.json

◆ getCantLoadedModules()

vector< string > gui_framework::GUIFramework::getCantLoadedModules ( )

List of all exceptions in load modules process.

Returns

Definition at line 989 of file GUIFramework.cpp.

◆ getCreators()

const unordered_map< size_t, smartPointerType< utility::BaseComponentCreator > > & gui_framework::GUIFramework::getCreators ( ) const

Get all current registered creators.

Returns
creators

Definition at line 964 of file GUIFramework.cpp.

◆ getDeserializers()

const unordered_map< size_t, smartPointerType< interfaces::IDeserializer > > & gui_framework::GUIFramework::getDeserializers ( ) const

Get all current registered deserializers.

Returns
deserializers

Definition at line 969 of file GUIFramework.cpp.

◆ getGUIFrameworkVersion()

string gui_framework::GUIFramework::getGUIFrameworkVersion ( )
static

Get current GUIFramework version.

Returns
Current version GUIFramework version

Definition at line 697 of file GUIFramework.cpp.

◆ getJSONSettings()

const json::JSONParser & gui_framework::GUIFramework::getJSONSettings ( ) const

Get settings from gui_framework.json.

Returns
jsonSettings

Definition at line 974 of file GUIFramework.cpp.

◆ getModules()

const unordered_map< string, HMODULE, localization::utility::StringViewHash, localization::utility::StringViewEqual > & gui_framework::GUIFramework::getModules ( ) const

Get all loaded modules.

Returns

Definition at line 979 of file GUIFramework.cpp.

◆ getModulesPaths()

const unordered_map< string, string > & gui_framework::GUIFramework::getModulesPaths ( ) const

Get all loaded modules paths.

Returns

Definition at line 984 of file GUIFramework.cpp.

◆ getRegisteredHotkeys()

vector< GUIFramework::hotkeyData > gui_framework::GUIFramework::getRegisteredHotkeys ( )

Thread safe get hotkeys.

Returns
Registered hotkeys

Definition at line 833 of file GUIFramework.cpp.

◆ getUIThreadId()

DWORD gui_framework::GUIFramework::getUIThreadId ( )
static

Getter for UI thread id.

Returns
uiThreadId

Definition at line 692 of file GUIFramework.cpp.

◆ isExist()

bool gui_framework::GUIFramework::isExist ( BaseComponent * component)

Check if component created. If component destroyed after you call findComponent, you may have not valid pointer.

Parameters
componentValue from
Returns
true if exist, false otherwise

Definition at line 880 of file GUIFramework.cpp.

◆ isModulesLoaded()

bool gui_framework::GUIFramework::isModulesLoaded ( ) const

Check if modules are loaded. You can call getCantLoadedModules() to check if loaded modules have failed.

Returns

Definition at line 943 of file GUIFramework.cpp.

◆ loadModule()

void gui_framework::GUIFramework::loadModule ( const std::string & moduleName,
const std::filesystem::path & pathToModule )

Load module with some sort of data.

Parameters
moduleNameName of that module
pathToModulePath to that module @excepiton FileDoesNotExist
Exceptions
CantLoadModule

◆ operator[]()

HMODULE gui_framework::GUIFramework::operator[] ( const std::string & moduleName) const

Get handle to specific module.

Parameters
moduleName
Returns
Exceptions
std::out_of_range

Definition at line 996 of file GUIFramework.cpp.

◆ registerHotkey() [1/2]

size_t gui_framework::GUIFramework::registerHotkey ( hotkeys::keys key,
const std::function< void()> & onClick,
const std::vector< hotkeys::additionalKeys > & additionalKeys = {} )

Only works in thread, that call runMainLoop from WindowHolder. Thread safe register hotkey.

Parameters
keyValue from keys enum or https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
onClickFunction to call
additionalKeys
Returns
Hotkey id

◆ registerHotkey() [2/2]

size_t gui_framework::GUIFramework::registerHotkey ( hotkeys::keys key,
const std::string & functionName,
const std::string & moduleName,
const std::vector< hotkeys::additionalKeys > & additionalKeys = {} )

Only works in thread, that call runMainLoop from WindowHolder. Thread safe register hotkey.

Parameters
keyValue from keys enum or https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
functionNameName of function to call
moduleNameName of module where function store
additionalKeys
Returns
Hotkey id
Exceptions
CantFindFunctionFromModuleException
std::out_of_rangeCan't find moduleName in loaded modules

◆ restartApplication()

void gui_framework::GUIFramework::restartApplication ( int exitCode = 0)
static

Restart application with given exit code.

Parameters
exitCodeExit code for previous application
Exceptions
GetLastErrorException

Definition at line 660 of file GUIFramework.cpp.

◆ runOnUIThread() [1/2]

static void gui_framework::GUIFramework::runOnUIThread ( const std::function< void()> & function)
static

Run function in UI thread. Functions processed only when window in main UI thread has focus.

Parameters
functionFunction that will run in UI thread

◆ runOnUIThread() [2/2]

static void gui_framework::GUIFramework::runOnUIThread ( std::function< void()> && function)
static

Run function in UI thread. Functions processed only when window in main UI thread has focus.

Parameters
functionFunction that will run in UI thread

◆ serializeHotkeys()

vector< json::utility::jsonObject > gui_framework::GUIFramework::serializeHotkeys ( )

Serialize hotkeys.

Returns
JSON array with hotkeys data

Definition at line 885 of file GUIFramework.cpp.

◆ unloadModule()

void gui_framework::GUIFramework::unloadModule ( const std::string & moduleName)

Unload module.

Parameters
moduleNameName of module to unload

Definition at line 866 of file GUIFramework.cpp.

◆ unregisterHotkey() [1/2]

bool gui_framework::GUIFramework::unregisterHotkey ( size_t hotkeyId)

Thread safe unregister hotkey.

Parameters
hotkeyIdReturn value from registerHotkey
Returns
Is successed

Definition at line 789 of file GUIFramework.cpp.

◆ unregisterHotkey() [2/2]

bool gui_framework::GUIFramework::unregisterHotkey ( uint32_t key,
const std::vector< hotkeys::additionalKeys > & additionalKeys = {} )

Thread safe unregister hotkey.

Parameters
keyValue from https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
additionalKeys
Returns
Is successed

Definition at line 811 of file GUIFramework.cpp.

Friends And Related Symbol Documentation

◆ BaseComponent

friend class BaseComponent
friend

Definition at line 294 of file GUIFramework.h.

◆ BaseDialogBox

friend class BaseDialogBox
friend

Definition at line 296 of file GUIFramework.h.

◆ BaseMainWindow

friend class BaseMainWindow
friend

Definition at line 297 of file GUIFramework.h.

◆ std::default_delete< GUIFramework >

friend struct std::default_delete< GUIFramework >
friend

Definition at line 297 of file GUIFramework.h.

◆ WindowHolder

friend class WindowHolder
friend

Definition at line 295 of file GUIFramework.h.


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