21 const std::string& label,
22 std::function<
void()> onClick)
24 auto entityRes = registry.
spawn();
26 log::error(
"Failed to spawn button entity: {}", entityRes.error().message());
27 throw std::runtime_error(std::string(
"Failed to spawn button entity: ") + std::string(entityRes.error().message()));
46 const std::string& content,
47 const std::string& fontPath,
48 unsigned int fontSize,
49 const std::uint8_t zIndex,
50 const color& textColor)
52 auto entityRes = registry.
spawn();
54 log::error(
"Failed to spawn text entity: {}", entityRes.error().message());
55 throw std::runtime_error(std::string(
"Failed to spawn text entity: ") + std::string(entityRes.error().message()));
66 text.
red = textColor.
r;
68 text.
blue = textColor.
b;
82 std::function<
void(
float)> onChange)
84 auto entityRes = registry.
spawn();
86 log::error(
"Failed to spawn slider entity: {}", entityRes.error().message());
87 throw std::runtime_error(std::string(
"Failed to spawn slider entity: ") + std::string(entityRes.error().message()));
110 const std::vector<std::string>& options,
111 const int selectedIndex,
112 std::function<
void(
int index)> onSelect)
114 auto entityRes = registry.
spawn();
116 log::error(
"Failed to spawn dropdown entity: {}", entityRes.error().message());
117 throw std::runtime_error(std::string(
"Failed to spawn dropdown entity: ") + std::string(entityRes.error().message()));
128 dropdown.
onSelect = [options, onSelect](
int index) {
129 if (index < 0 || index >=
static_cast<int>(options.size())) {
130 log::warning(
"Dropdown selection index {} is out of bounds", index);
146 const std::string& fontPath,
147 unsigned int fontSize,
149 const std::string& placeholder,
150 std::function<
void(
const std::string&)> onSubmit,
151 std::function<
void(
const std::string&)> onChange)
153 auto entityRes = registry.
spawn();
155 log::error(
"Failed to spawn text input entity: {}", entityRes.error().message());
156 throw std::runtime_error(std::string(
"Failed to spawn text input entity: ") + std::string(entityRes.error().message()));
180 const std::string& texturePath,
188 auto entityRes = registry.
spawn();
190 log::error(
"Failed to spawn sprite preview entity: {}", entityRes.error().message());
191 throw std::runtime_error(std::string(
"Failed to spawn sprite preview entity: ") + std::string(entityRes.error().message()));
200 spritePreview.
scale = scale;
202 spritePreview.
rectTop = rectTop;
205 spritePreview.
zIndex = zIndex;
static ecs::Entity createTextInput(ecs::Registry ®istry, const position &position, const size &size, const std::string &fontPath, unsigned int fontSize, const int maxLength=64, const std::string &placeholder="", std::function< void(const std::string &)> onSubmit=nullptr, std::function< void(const std::string &)> onChange=nullptr)
static ecs::Entity createSpritePreview(ecs::Registry ®istry, const position &position, const std::string &texturePath, int rectLeft, int rectTop, int rectWidth, int rectHeight, float scale=2.0f, int zIndex=0)
Create a sprite preview UI component.
static ecs::Entity createText(ecs::Registry ®istry, const position &position, const std::string &content, const std::string &fontPath, unsigned int fontSize, const std::uint8_t zIndex=0, const color &textColor={255, 255, 255})
static ecs::Entity createButton(ecs::Registry ®istry, const position &position, const size &size, const std::string &label, std::function< void()> onClick=nullptr)
Create a button UI component.
static ecs::Entity createDropdown(ecs::Registry ®istry, const position &position, const size &size, const std::vector< std::string > &options, const int selectedIndex, std::function< void(int index)> onSelect=nullptr)
static ecs::Entity createSlider(ecs::Registry ®istry, const position &position, const size &size, float minValue, float maxValue, float initialValue, std::function< void(float)> onChange=nullptr)
Represents an entity in the ECS (Entity-Component-System) architecture.
auto spawn(void) -> std::expected< Entity, rtp::Error >
auto add(Entity entity, Args &&...args) -> std::expected< std::reference_wrapper< T >, rtp::Error >
void error(LogFmt< std::type_identity_t< Args >... > fmt, Args &&...args) noexcept
Log an error message.
void warning(LogFmt< std::type_identity_t< Args >... > fmt, Args &&...args) noexcept
Log a warning message.
Represents the position of a UI component.
Represents the size of a UI component.
Component for dropdown menu selection.
int selectedIndex
Currently selected option.
Vec2f position
Position of the dropdown.
std::function< void(int)> onSelect
Callback when option selected.
std::vector< std::string > options
Available options.
Vec2f size
Size of the dropdown button.
Component for a draggable slider control.
Vec2f position
Position of the slider.
float currentValue
Current value.
Vec2f size
Size of the slider.
float minValue
Minimum value.
float maxValue
Maximum value.
std::function< void(float)> onChange
Callback when value changes.
Component for displaying a sprite preview in the UI.
float x
X position for rendering.
int rectHeight
Height of sprite in texture.
float scale
Scale factor for display.
int rectTop
Top coordinate in texture.
int rectWidth
Width of sprite in texture.
std::string texturePath
Path to the texture file.
float y
Y position for rendering.
int zIndex
Rendering order.
int rectLeft
Left coordinate in texture.
std::function< void(const std::string &)> onChange
std::function< void(const std::string &)> onSubmit
Component representing text to render.
uint8_t green
Green component.
int zIndex
Rendering order.
uint8_t blue
Blue component.
Vec2f position
Position of the text.
uint8_t red
Red component.
unsigned int fontSize
Font size.
std::string fontPath
Path to the font file.
std::string content
Text content.