Class: UIComponent
The UIComponent
class is a base class for building UI elements in the system. It provides methods for rendering, event handling, and managing component state.
You don't want to use this class directly. Instead, you should UI components that inherit from this class like UIButton or inherit from this class to create your own custom components.
The source file for this class is located in os/ui/UIComponents/UIComponent.h.
Methods​
GetSize
​
virtual Dimension GetSize();
Returns the size of the component. Used by the UI system to determine the component's dimensions. Override this method to provide custom dimensions.
Returns:
- [
Dimension
](../../Types/Dimension/): The dimensions (width
andheight
) of the component. Default isDimension(0, 0)
.
KeyEvent
​
virtual bool KeyEvent(Point xy, KeyInfo* keyInfo);
Handles a key event at the specified position. The UI system calls this method when a key event occurs. Override this method to process key events.
Parameters:
Returns:
bool
:true
if the event was handled,false
otherwise.
Render
​
virtual bool Render(Point origin);
Renders the component at the specified origin. The UI system calls this method to draw the component on the screen. Override this method to customize the rendering behavior.
Parameters:
origin
(Point
): The top-left corner of the component's rendering area.
Returns:
bool
:true
if the rendering was successful,false
otherwise.
SetEnabled
​
void SetEnabled(bool enabled);
Sets whether the component is enabled. You can use this method to enable or disable the component.
Parameters:
enabled
(bool
):true
to enable the component,false
to disable it.
ShouldEnable
​
void ShouldEnable(std::function<bool()> enable_func);
Sets a function to dynamically determine if the component should be enabled.
Parameters:
enable_func
(std::function<bool()>
): A function returningtrue
if the component should be enabled,false
otherwise.
IsEnabled
​
bool IsEnabled();
Checks if the component is currently enabled. If enable_func
is defined, it will override the enabled
property. This is used by the UI system to determine if the component should be rendered and respond to events.
Returns:
bool
:true
if the component is enabled,false
otherwise.
Destructor​
virtual ~UIComponent();
Cleans up the component. Override this method to release resources when the component is destroyed.
Comments