#pragma once #include "component.hpp" #include "ui.hpp" #include #include namespace dusk::ui { using SelectButtonCallback = std::function; class SelectButton : public FluentComponent { public: struct Props { Rml::String key; Rml::String value; bool modified = false; }; SelectButton(Rml::Element* parent, Props props); virtual bool modified() const; void set_modified(bool value); void set_value_label(const Rml::String& value); SelectButton& on_pressed(SelectButtonCallback callback); protected: void update_props(Props props); virtual bool handle_nav_command(NavCommand cmd); Props mProps; Rml::Element* mKeyElem = nullptr; Rml::Element* mValueElem = nullptr; }; class BaseControlledSelectButton : public SelectButton { public: BaseControlledSelectButton(Rml::Element* parent, Props props) : SelectButton(parent, std::move(props)) {} void update() override; protected: virtual Rml::String format_value() = 0; }; class ControlledSelectButton : public BaseControlledSelectButton { public: struct Props { Rml::String key; std::function getValue; std::function isDisabled; std::function isModified; }; ControlledSelectButton(Rml::Element* parent, Props props) : BaseControlledSelectButton(parent, {std::move(props.key)}), mGetValue(std::move(props.getValue)), mIsDisabled(std::move(props.isDisabled)), mIsModified(std::move(props.isModified)) {} bool modified() const override; bool disabled() const override; protected: Rml::String format_value() override; std::function mGetValue; std::function mIsDisabled; std::function mIsModified; }; } // namespace dusk::ui