API Documentation
Public Member Functions | List of all members
nkWinUi::Component Class Referenceabstract

Base class for any graphical component. More...

Inheritance diagram for nkWinUi::Component:
nkExport::Exportable nkWinUi::Button nkWinUi::CheckBox nkWinUi::ComboBox nkWinUi::ContextMenu nkWinUi::EditBox nkWinUi::FileExplorer nkWinUi::GroupBox nkWinUi::ImageDisplay nkWinUi::ListBox nkWinUi::LogWin nkWinUi::MultiLineEdit nkWinUi::ProgressBar nkWinUi::ScrollBar nkWinUi::Slider nkWinUi::Static nkWinUi::TabWindow nkWinUi::ToolBar nkWinUi::TreeView nkWinUi::Window

Public Member Functions

 Component (System *system) noexcept
 
virtual ~Component ()
 
LayoutgetLayout () const
 
ThemegetTheme () const
 
FontgetFont () const
 
nkMaths::Point getPositionInParent () const
 
nkMaths::Point getPositionInScreen () const
 
float getWidth () const
 
float getHeight () const
 
nkMaths::Rectangle getAreaInParent () const
 
nkMaths::Rectangle getAreaInScreen () const
 
virtual nkMaths::Point getBorderExtents () const
 
virtual float getBorderExtent (BORDER_KIND border) const
 
virtual float getLayoutAllowedWidth () const
 
virtual float getLayoutAllowedHeight () const
 
virtual float getLayoutAllowedOffsetX () const
 
virtual float getLayoutAllowedOffsetY () const
 
bool isInitialized () const
 
SystemgetSystem () const
 
ComponentgetParentComponent () const
 
COMPONENT_TYPE getComponentType () const
 
nkMemory::StringView getComponentName () const
 
bool getVisibility () const
 
virtual nkMemory::StringView getLabel () const
 
void * getData () const
 
bool isEnabled () const
 
bool isForegroundWindow () const
 
virtual unsigned int getZDepth () const
 
bool getVisibleOnLoad () const
 
std::function< bool(Component *)> getCloseCallback () const
 
std::function< void(Component *, bool)> getVisibilityCallback () const
 
std::function< void(Component *, const ClickEventData &)> getClickCallback () const
 
std::function< void(Component *, const WheelEventData &)> getWheelCallback () const
 
std::function< void(Component *, const KeyEventData &)> getKeyCallback () const
 
virtual LayoutsetLayout (LAYOUT_TYPE layoutType)
 
virtual void setTheme (Theme *theme)
 
virtual void setFont (Font *font)
 
virtual void setPositionInParent (nkMaths::Point position)
 
virtual void setPositionInScreen (nkMaths::Point position)
 
virtual void setSize (float width, float height)
 
virtual void setWidth (float width)
 
virtual void setHeight (float height)
 
void setMinSize (float width, float height)
 
void setMaxSize (float width, float height)
 
void setRatio (float widthOverHeight)
 
virtual void setAreaInParent (const nkMaths::Rectangle &area)
 
virtual void setAreaInScreen (const nkMaths::Rectangle &area)
 
virtual void setParentComponent (Component *parent, bool makeItVisible=true)
 
virtual void setLabel (nkMemory::StringView label)
 
void setComponentName (nkMemory::StringView name)
 
virtual void setVisibility (bool value)
 
void setData (void *data)
 
void setEnabled (bool value)
 
void setVisibleOnLoad (bool value)
 
void setCloseCallback (std::function< bool(Component *caller)> callback)
 
void setVisibilityCallback (std::function< void(Component *caller, bool visibility)> callback)
 
void setClickCallback (std::function< void(Component *caller, const ClickEventData &eventData)> callback)
 
void setWheelCallback (std::function< void(Component *caller, const WheelEventData &eventData)> callback)
 
void setKeyCallback (std::function< void(Component *caller, const KeyEventData &eventData)> callback)
 
void addChild (Component *child, bool makeItVisible=true)
 
void removeChild (Component *child)
 
void removeChild (unsigned int index)
 
ComponentgetChild (unsigned int index)
 
unsigned int getChildIndex (Component *child)
 
void unloadWithChildren ()
 
void loadWithChildren ()
 
void updateZDepth ()
 
void bringToForeground ()
 
void focusWindow ()
 
nkMaths::Point getCoordRelativeFromAbsolute (nkMaths::Point absCoords)
 
nkMaths::Point getCoordAbsoluteFromRelative (nkMaths::Point relCoords)
 
virtual void load ()=0
 
virtual void unload ()=0
 
void reload ()
 
virtual void updateWindow ()
 
nkImages::Image paintToImage (bool withFrame=false)
 
void simulateEvent (const InputDescriptor &inputDescription)
 
virtual void onSized ()
 
virtual void exportClassToTree (nkExport::Node *rootNode) override
 
virtual void exportIntrospection (nkExport::Node *rootNode)
 
virtual void importClassFromTree (nkExport::Node *rootNode) override
 
- Public Member Functions inherited from nkExport::Exportable
 Exportable () noexcept
 
virtual ~Exportable ()
 

Detailed Description

Base class for any graphical component.

Constructor & Destructor Documentation

◆ Component()

nkWinUi::Component::Component ( System system)
noexcept

Constructor.

Parameters
systemThe parent system in which the component will live.
Remarks
See ComponentManager::createOrRetrieve().

◆ ~Component()

virtual nkWinUi::Component::~Component ( )
virtual

Destructor.

Member Function Documentation

◆ getLayout()

Layout* nkWinUi::Component::getLayout ( ) const
Returns
The layout currently associated to the component.

◆ getTheme()

Theme* nkWinUi::Component::getTheme ( ) const
Returns
The currently overridden theme for the component.

◆ getFont()

Font* nkWinUi::Component::getFont ( ) const
Returns
The currently overridden font for the component.

◆ getPositionInParent()

nkMaths::Point nkWinUi::Component::getPositionInParent ( ) const
Returns
The component's position, relative to its parent.

◆ getPositionInScreen()

nkMaths::Point nkWinUi::Component::getPositionInScreen ( ) const
Returns
The component's position, absolute, on screen.

◆ getWidth()

float nkWinUi::Component::getWidth ( ) const
Returns
Current component's width.

◆ getHeight()

float nkWinUi::Component::getHeight ( ) const
Returns
Current component's height.

◆ getAreaInParent()

nkMaths::Rectangle nkWinUi::Component::getAreaInParent ( ) const
Returns
Current component's occupied area, in pixels, relative to its parent.

◆ getAreaInScreen()

nkMaths::Rectangle nkWinUi::Component::getAreaInScreen ( ) const
Returns
Current component's occupied area, in pixels, relative to the screen.

◆ getBorderExtents()

virtual nkMaths::Point nkWinUi::Component::getBorderExtents ( ) const
virtual
Returns
the size of components borders, in pixels.

◆ getBorderExtent()

virtual float nkWinUi::Component::getBorderExtent ( BORDER_KIND  border) const
virtual

Provides with a designated border's pixel size.

Parameters
borderThe border to retrieve the pixel size from.
Returns
The designated border's pixel size.

◆ getLayoutAllowedWidth()

virtual float nkWinUi::Component::getLayoutAllowedWidth ( ) const
virtual
Returns
The width the layout is allowed to take to organize children components.

Reimplemented in nkWinUi::GroupBox.

◆ getLayoutAllowedHeight()

virtual float nkWinUi::Component::getLayoutAllowedHeight ( ) const
virtual
Returns
The height the layout is allowed to take to organize children components.

Reimplemented in nkWinUi::GroupBox.

◆ getLayoutAllowedOffsetX()

virtual float nkWinUi::Component::getLayoutAllowedOffsetX ( ) const
virtual
Returns
The offset for x position the layout is allowed to take to organize children components.

Reimplemented in nkWinUi::GroupBox.

◆ getLayoutAllowedOffsetY()

virtual float nkWinUi::Component::getLayoutAllowedOffsetY ( ) const
virtual
Returns
The offset for y position the layout is allowed to take to organize children components.

Reimplemented in nkWinUi::GroupBox.

◆ isInitialized()

bool nkWinUi::Component::isInitialized ( ) const
Returns
Whether component is initialized (successful call to load() has been made).

◆ getSystem()

System* nkWinUi::Component::getSystem ( ) const
Returns
The system the component is living in.

◆ getParentComponent()

Component* nkWinUi::Component::getParentComponent ( ) const
Returns
The component's parent.

◆ getComponentType()

COMPONENT_TYPE nkWinUi::Component::getComponentType ( ) const
Returns
The type of the component.

◆ getComponentName()

nkMemory::StringView nkWinUi::Component::getComponentName ( ) const
Returns
The name of the component.

◆ getVisibility()

bool nkWinUi::Component::getVisibility ( ) const
Returns
Whether the component is visible (true) or not (false).

◆ getLabel()

virtual nkMemory::StringView nkWinUi::Component::getLabel ( ) const
virtual
Returns
Currently set component's label.

◆ getData()

void* nkWinUi::Component::getData ( ) const
Returns
Currently set user data, attached to the component.

◆ isEnabled()

bool nkWinUi::Component::isEnabled ( ) const
Returns
If the component is enabled (true) or not (false).

◆ isForegroundWindow()

bool nkWinUi::Component::isForegroundWindow ( ) const
Returns
Whether the component is in foreground (true) or not (false).

◆ getZDepth()

virtual unsigned int nkWinUi::Component::getZDepth ( ) const
virtual
Returns
The z depth of the component.

◆ getVisibleOnLoad()

bool nkWinUi::Component::getVisibleOnLoad ( ) const
Returns
Whether the component is flagged as needing to be visible (true) or not (false), after a call to load().

◆ getCloseCallback()

std::function<bool (Component*)> nkWinUi::Component::getCloseCallback ( ) const
Returns
The currently used callback for a closing request event.

◆ getVisibilityCallback()

std::function<void (Component*, bool)> nkWinUi::Component::getVisibilityCallback ( ) const
Returns
The currently used callback for a visibility change event.

◆ getClickCallback()

std::function<void (Component*, const ClickEventData&)> nkWinUi::Component::getClickCallback ( ) const
Returns
The currently used callback for mouse click events.

◆ getWheelCallback()

std::function<void (Component*, const WheelEventData&)> nkWinUi::Component::getWheelCallback ( ) const
Returns
The currently used callback for mouse wheel events.

◆ getKeyCallback()

std::function<void (Component*, const KeyEventData&)> nkWinUi::Component::getKeyCallback ( ) const
Returns
The currently used callback for key events.

◆ setLayout()

virtual Layout* nkWinUi::Component::setLayout ( LAYOUT_TYPE  layoutType)
virtual

Sets the component's layout type by instantiating a new layout, and returns it for populating.

Parameters
layoutTypeThe type of layout the component should instantiate.
Returns
The layout newly assigned.
Remarks
This function will replace any existing layout, and start with a fresh one. The component is the owner of the layout.

Reimplemented in nkWinUi::TabWindow.

◆ setTheme()

virtual void nkWinUi::Component::setTheme ( Theme theme)
virtual

Sets an overridden theme to use for the component. The global theme to use through the application can be set using ThemeManager::setActiveTheme. However, if a sub-set of components needs to use a specific theme, it can be overridden through this setter.

Parameters
themeThe theme to use rather than the active one, or nullptr to revert back to the default one.

◆ setFont()

virtual void nkWinUi::Component::setFont ( Font font)
virtual

Sets and overridden font to use for text rendering.

Parameters
fontThe font to use, or nullptr to revert back to the default font.

◆ setPositionInParent()

virtual void nkWinUi::Component::setPositionInParent ( nkMaths::Point  position)
virtual

Change the component's position, relative to the parent.

Parameters
positionThe position to assign, in pixels.

◆ setPositionInScreen()

virtual void nkWinUi::Component::setPositionInScreen ( nkMaths::Point  position)
virtual

Change the component's position, relative to screen (absolute).

Parameters
positionThe position to assign, in pixels.

◆ setSize()

virtual void nkWinUi::Component::setSize ( float  width,
float  height 
)
virtual

Change the component's size.

Parameters
widthThe width to assign, in pixels.
heightThe height to assign, in pixels.

◆ setWidth()

virtual void nkWinUi::Component::setWidth ( float  width)
virtual

Change the component's width.

Parameters
widthThe width to assign, in pixels.

◆ setHeight()

virtual void nkWinUi::Component::setHeight ( float  height)
virtual

Change the component's height.

Parameters
heightThe height to assign, in pixels.

◆ setMinSize()

void nkWinUi::Component::setMinSize ( float  width,
float  height 
)

Assign a minimum size the component should have.

Parameters
widthThe minimum width possible, in pixels. -1 symbolizes "no limit".
heightThe minimum height possible, in pixels. -1 symbolizes "no limit".

◆ setMaxSize()

void nkWinUi::Component::setMaxSize ( float  width,
float  height 
)

Assign a maximum size the component should have.

Parameters
widthThe maximum width possible, in pixels. -1 symbolizes "no limit".
heightThe maximum height possible, in pixels. -1 symbolizes "no limit".

◆ setRatio()

void nkWinUi::Component::setRatio ( float  widthOverHeight)

Assign a ratio the component has to respect.

Parameters
widthOverHeightThe ratio, as width / height.

◆ setAreaInParent()

virtual void nkWinUi::Component::setAreaInParent ( const nkMaths::Rectangle area)
virtual

Assign an area the component should cover, relative to its parent.

Parameters
areaThe area, in pixels, to cover.

◆ setAreaInScreen()

virtual void nkWinUi::Component::setAreaInScreen ( const nkMaths::Rectangle area)
virtual

Assign an area the component should cover, relative to the screen.

Parameters
areaThe area, in pixels, to cover.

◆ setParentComponent()

virtual void nkWinUi::Component::setParentComponent ( Component parent,
bool  makeItVisible = true 
)
virtual

Changes the parent component.

Parameters
parentThe parent component to assign.
makeItVisibleIf the component should be made visible within the parent, if the parent is visible.

◆ setLabel()

virtual void nkWinUi::Component::setLabel ( nkMemory::StringView  label)
virtual

Changes the label of the component. This can be the title of a nkWinUi::Window, the txt of a nkWinUi::EditBox...

Parameters
labelThe text to assign.

◆ setComponentName()

void nkWinUi::Component::setComponentName ( nkMemory::StringView  name)

Sets the component name.

Parameters
nameThe name to assign.
Remarks
In theory, this should not be called by external code. Used by the nkWinUi::ComponentManager upon component's creation.

◆ setVisibility()

virtual void nkWinUi::Component::setVisibility ( bool  value)
virtual

Sets whether this component should be visible.

Parameters
valueIf the component should be visible on screen (true) or not (false).

◆ setData()

void nkWinUi::Component::setData ( void *  data)

Attach user data to the component.

Parameters
dataThe user data to attach to the component.
Remarks
The component will not be responsible for freeing the user data. External code needs to take care of it.

◆ setEnabled()

void nkWinUi::Component::setEnabled ( bool  value)

Sets whether the component is enabled or not.

Parameters
valueIf it is enabled (true) or not (false).
Remarks
A disabled component often appears grayed out, with no interaction possible.

◆ setVisibleOnLoad()

void nkWinUi::Component::setVisibleOnLoad ( bool  value)

Sets whether a component should be visible after its load operation, or not. This can be used to load components but keep them hidden until further notice.

Parameters
valueIf the component should be visible (true) or not (false).

◆ setCloseCallback()

void nkWinUi::Component::setCloseCallback ( std::function< bool(Component *caller)>  callback)

Sets the callback whenever a close request happens. Such a request can happen when unload is called, or using the component's UI itself if offered.

Parameters
callbackThe callback to use. The argument is the calling component. The return boolean should be true to allow unloading, or false to prevent it.

◆ setVisibilityCallback()

void nkWinUi::Component::setVisibilityCallback ( std::function< void(Component *caller, bool visibility)>  callback)

Sets the callback for a visibility change event.

Parameters
callbackThe callback to use. The first argument is the calling component, and the second the new visibility status.

◆ setClickCallback()

void nkWinUi::Component::setClickCallback ( std::function< void(Component *caller, const ClickEventData &eventData)>  callback)

Sets the callback for a mouse click event.

Parameters
callbackThe callback to use. The first argument is the calling component, and the second the event information.

◆ setWheelCallback()

void nkWinUi::Component::setWheelCallback ( std::function< void(Component *caller, const WheelEventData &eventData)>  callback)

Sets the callback for a mouse wheel event while the component is focused.

Parameters
callbackThe callback to use. The first argument is the calling component, and the second the event information.

◆ setKeyCallback()

void nkWinUi::Component::setKeyCallback ( std::function< void(Component *caller, const KeyEventData &eventData)>  callback)

Sets the callback for a key event while the component is focused.

Parameters
callbackThe callback to use. The first argument is the calling component, and the second the event information.

◆ addChild()

void nkWinUi::Component::addChild ( Component child,
bool  makeItVisible = true 
)

Add a child component.

Parameters
childThe component that should become a child.
makeItVisibleIf the child component has to become visible if the parent is also visible.

◆ removeChild() [1/2]

void nkWinUi::Component::removeChild ( Component child)

Removes a child.

Parameters
childThe child component that should not be a child anymore.

◆ removeChild() [2/2]

void nkWinUi::Component::removeChild ( unsigned int  index)

Removes a child.

Parameters
indexThe index of the child component, in the children list, that should be removed.
Remarks
An out of bounds index results in a no-op.

◆ getChild()

Component* nkWinUi::Component::getChild ( unsigned int  index)

Returns a child component.

Parameters
indexThe child component at given index, in the children list.
Returns
The designated child component if index is valid, nullptr else.

◆ getChildIndex()

unsigned int nkWinUi::Component::getChildIndex ( Component child)

Returns the index in the list of one child component.

Parameters
childThe child component chich index is needed.
Returns
The index attached in the list if component is a child, an invalid one (> to children count) else.
Remarks
Index is potentially invalidated if a child is removed in between. However, adding a child won't invalidate it.

◆ unloadWithChildren()

void nkWinUi::Component::unloadWithChildren ( )

Unloads the component along with its children.

◆ loadWithChildren()

void nkWinUi::Component::loadWithChildren ( )

Loads the component along with its children.

◆ updateZDepth()

void nkWinUi::Component::updateZDepth ( )

Updates the depth of the component. Computed from the component's hierarchy.

◆ bringToForeground()

void nkWinUi::Component::bringToForeground ( )

Brings the component to the foreground.

◆ focusWindow()

void nkWinUi::Component::focusWindow ( )

Puts the component into focus.

◆ getCoordRelativeFromAbsolute()

nkMaths::Point nkWinUi::Component::getCoordRelativeFromAbsolute ( nkMaths::Point  absCoords)

Converts given coordinates from absolute in screen to relative to the component.

Parameters
absCoordsThe absolute coordinates to convert.
Returns
The coordinate now relative to the component.

◆ getCoordAbsoluteFromRelative()

nkMaths::Point nkWinUi::Component::getCoordAbsoluteFromRelative ( nkMaths::Point  relCoords)

Converts given coordinates from relative to the component to absolute in screen.

Parameters
relCoordsThe relative coordinates to convert.
Returns
The coordinate now absolute in screen.

◆ load()

virtual void nkWinUi::Component::load ( )
pure virtual

Loads the component. This will trigger the initialization of the component in the windowing system.

◆ unload()

virtual void nkWinUi::Component::unload ( )
pure virtual

Unloads the component. This will make the component release resources from the windowing system.

◆ reload()

void nkWinUi::Component::reload ( )

Reloads the component. Shorthand for unload() followed by load().

◆ updateWindow()

virtual void nkWinUi::Component::updateWindow ( )
virtual

Update the window for changes that could have occurred.

◆ paintToImage()

nkImages::Image nkWinUi::Component::paintToImage ( bool  withFrame = false)
Returns
An offscreen rendering of the component.
Parameters
withFrameWhether the non-client area, aka frame, should also be included in the image.
Remarks
Currently, all components are compatible except for :

◆ simulateEvent()

void nkWinUi::Component::simulateEvent ( const InputDescriptor inputDescription)

Simulates an event within the component, fitting the description given. Using this, it is possible to automatically hover components, or automatically generate keyboard events. Note that simulating an event will not impact the system's input system (cursor or focus).

Parameters
inputDescriptionThe description of the input to simulate.

◆ onSized()

virtual void nkWinUi::Component::onSized ( )
virtual

Component's callback for resize events.

◆ exportClassToTree()

virtual void nkWinUi::Component::exportClassToTree ( nkExport::Node rootNode)
overridevirtual

A basic exporting capability.

Parameters
rootNodeThe root of the tree to export into.

Implements nkExport::Exportable.

Reimplemented in nkWinUi::ContextMenu.

◆ exportIntrospection()

virtual void nkWinUi::Component::exportIntrospection ( nkExport::Node rootNode)
virtual

A basic exporting capability, for components inheriting. Components inheriting this class should rather reimplement this function to export their internal data.

Parameters
rootNodeThe root of the tree to export into.

Reimplemented in nkWinUi::TreeView, nkWinUi::ListBox, nkWinUi::TabWindow, nkWinUi::ComboBox, nkWinUi::Slider, nkWinUi::FileExplorer, nkWinUi::Window, nkWinUi::Static, nkWinUi::ImageDisplay, nkWinUi::EditBox, and nkWinUi::LogWin.

◆ importClassFromTree()

virtual void nkWinUi::Component::importClassFromTree ( nkExport::Node rootNode)
overridevirtual

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