Files
dusklight/src/dusk/ui/button.hpp
T
Luke Street 79b1f4ab4d Customizable data directory & migration (#1059)
* Customizable data directory & migration

* Add file/dir rename fast-path

* Write data_location.json to base path on Windows; fix UTF-8 custom paths

* Build fix

* Another build fix

* Android data directory selection

* Fix CMake target ref
2026-05-11 22:57:59 -06:00

53 lines
1.3 KiB
C++

#pragma once
#include "component.hpp"
namespace dusk::ui {
using ButtonCallback = std::function<void()>;
class Button : public FluentComponent<Button> {
public:
struct Props {
Rml::String text;
};
Button(Rml::Element* parent, Props props, const Rml::String& tagName = "button");
Button(Rml::Element* parent, Rml::String text, const Rml::String& tagName = "button")
: Button(parent, Props{std::move(text)}, tagName) {}
void set_text(const Rml::String& text);
Button& on_pressed(ButtonCallback callback);
const Rml::String& get_text() const { return mProps.text; }
private:
void update_props(Props props);
Props mProps;
};
class ControlledButton : public Button {
public:
struct Props {
Rml::String text;
std::function<bool()> isSelected;
std::function<bool()> isDisabled;
};
ControlledButton(Rml::Element* parent, Props props, const Rml::String& tagName = "button")
: Button(parent, {std::move(props.text)}, tagName),
mIsSelected(std::move(props.isSelected)),
mIsDisabled(std::move(props.isDisabled)) {}
void update() override;
bool selected() const override;
bool disabled() const override;
private:
std::function<bool()> mIsSelected;
std::function<bool()> mIsDisabled;
};
} // namespace dusk::ui