#include "ui_pill_button.h" #include "ui_label.h" #include namespace recompui { static constexpr float pill_padding = 16.0f; PillButton::PillButton(Element *parent, const std::string &text, const std::string &svg_src, ButtonStyle style, PillButtonSize size) : Element(parent, Events(EventType::Click, EventType::Hover, EventType::Enable, EventType::Focus), "button") { this->style = style; this->size = size; // Borders add width to the button, so this subtracts from the base size to bring it back to the expected size. float float_size_internal = static_cast(size) - (theme::border::width * 2.0f); enable_focus(); set_display(Display::Flex); set_align_items(AlignItems::Center); set_justify_content(JustifyContent::Center); set_min_width(float_size_internal); set_width_auto(); set_padding_right(pill_padding); set_padding_left(pill_padding); set_height(float_size_internal); set_min_height(float_size_internal); set_max_height(float_size_internal); set_border_width(theme::border::width); set_border_radius(float_size_internal * 0.5f); set_border_color(theme::color::Transparent); set_cursor(Cursor::Pointer); set_color(theme::color::TextDim); set_tab_index(TabIndex::Auto); set_opacity(1.0f); hover_style.set_color(theme::color::Text); focus_style.set_color(theme::color::Text); disabled_style.set_color(theme::color::TextDim); disabled_style.set_cursor(Cursor::None); disabled_style.set_opacity(0.5f); hover_disabled_style.set_color(theme::color::TextDim); ContextId context = get_current_context(); bool has_svg = !svg_src.empty(); bool has_text = !text.empty(); if (has_svg) { float icon_size = 0; switch (size) { case PillButtonSize::Mini: icon_size = 16.0f; break; case PillButtonSize::Small: icon_size = 24.0f; break; case PillButtonSize::Medium: icon_size = 32.0f; break; case PillButtonSize::Large: default: icon_size = 32.0f; break; case PillButtonSize::XLarge: icon_size = 40.0f; break; } svg = context.create_element(this, svg_src); svg->set_width(icon_size); svg->set_image_color(theme::color::TextDim); } if (has_text) { auto label = context.create_element