diff options
author | crupest <crupest@outlook.com> | 2022-02-16 17:00:33 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-02-16 17:00:33 +0800 |
commit | 674e8af2e92074b71c77e656a54244ce2693460c (patch) | |
tree | d109201e4204011fe9e714ff81490674b2f7b042 /src/theme_builder/components/properties/SelectPropertyEditor.h | |
parent | 43a297f30c03180427db435bb25a1a4b51ea847a (diff) | |
download | cru-674e8af2e92074b71c77e656a54244ce2693460c.tar.gz cru-674e8af2e92074b71c77e656a54244ce2693460c.tar.bz2 cru-674e8af2e92074b71c77e656a54244ce2693460c.zip |
...
Diffstat (limited to 'src/theme_builder/components/properties/SelectPropertyEditor.h')
-rw-r--r-- | src/theme_builder/components/properties/SelectPropertyEditor.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/theme_builder/components/properties/SelectPropertyEditor.h b/src/theme_builder/components/properties/SelectPropertyEditor.h new file mode 100644 index 00000000..a67cb80f --- /dev/null +++ b/src/theme_builder/components/properties/SelectPropertyEditor.h @@ -0,0 +1,47 @@ +#pragma once +#include "cru/ui/components/Component.h" +#include "cru/ui/components/Select.h" +#include "cru/ui/controls/FlexLayout.h" +#include "cru/ui/controls/TextBlock.h" + +namespace cru::theme_builder::components::properties { +class SelectPropertyEditor : public ui::components::Component { + public: + using PropertyType = Index; + + SelectPropertyEditor(); + ~SelectPropertyEditor() override; + + public: + ui::controls::Control* GetRootControl() override { return &container_; } + + String GetLabel() const { return label_.GetText(); } + void SetLabel(String label) { label_.SetText(std::move(label)); } + + Index GetSelectedIndex() const { return select_.GetSelectedIndex(); } + void SetSelectedIndex(Index index, bool trigger_change = true) { + if (trigger_change == false) suppress_next_change_event_ = true; + select_.SetSelectedIndex(index); + } + + std::vector<String> GetItems() const { return select_.GetItems(); } + void SetItems(std::vector<String> items) { + select_.SetItems(std::move(items)); + } + + Index GetValue() const { return GetSelectedIndex(); } + void SetValue(Index value, bool trigger_change = true) { + SetSelectedIndex(value, trigger_change); + } + + IEvent<std::nullptr_t>* ChangeEvent() { return &change_event_; } + + private: + ui::controls::FlexLayout container_; + ui::controls::TextBlock label_; + ui::components::Select select_; + + bool suppress_next_change_event_ = false; + Event<std::nullptr_t> change_event_; +}; +} // namespace cru::theme_builder::components::properties |