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 (widthandheight) 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:trueif the event was handled,falseotherwise.
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:trueif the rendering was successful,falseotherwise.
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):trueto enable the component,falseto 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 returningtrueif the component should be enabled,falseotherwise.
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:trueif the component is enabled,falseotherwise.
Destructorβ
virtual ~UIComponent();
Cleans up the component. Override this method to release resources when the component is destroyed.
Comments