aboutsummaryrefslogtreecommitdiff
path: root/src/ui/components
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-12-09 23:15:15 +0800
committercrupest <crupest@outlook.com>2020-12-09 23:15:15 +0800
commit04e3fee3fc584c2c7562b29c375cedcf020bcbc6 (patch)
tree446393055dfcd2430107d9861b78fdd92759c9f3 /src/ui/components
parenta7b2a80edb224e3e1371571ab46ffad252e2e252 (diff)
downloadcru-04e3fee3fc584c2c7562b29c375cedcf020bcbc6.tar.gz
cru-04e3fee3fc584c2c7562b29c375cedcf020bcbc6.tar.bz2
cru-04e3fee3fc584c2c7562b29c375cedcf020bcbc6.zip
...
Diffstat (limited to 'src/ui/components')
-rw-r--r--src/ui/components/Component.cpp5
-rw-r--r--src/ui/components/Menu.cpp57
2 files changed, 62 insertions, 0 deletions
diff --git a/src/ui/components/Component.cpp b/src/ui/components/Component.cpp
new file mode 100644
index 00000000..5b62ffc9
--- /dev/null
+++ b/src/ui/components/Component.cpp
@@ -0,0 +1,5 @@
+#include "cru/ui/components/Component.hpp"
+
+namespace cru::ui::components {
+
+}
diff --git a/src/ui/components/Menu.cpp b/src/ui/components/Menu.cpp
new file mode 100644
index 00000000..ea9dcdb6
--- /dev/null
+++ b/src/ui/components/Menu.cpp
@@ -0,0 +1,57 @@
+#include "cru/ui/components/Menu.hpp"
+#include "cru/ui/controls/Button.hpp"
+#include "cru/ui/controls/FlexLayout.hpp"
+#include "cru/ui/controls/TextBlock.hpp"
+
+#include <string>
+
+namespace cru::ui::components {
+MenuItem::MenuItem() {
+ container_ = controls::Button::Create();
+ text_ = controls::TextBlock::Create();
+ container_->SetChild(text_);
+}
+
+MenuItem::MenuItem(std::u16string text) : MenuItem() {
+ SetText(std::move(text));
+}
+
+MenuItem::~MenuItem() {
+ if (!container_->GetWindowHost()) {
+ delete container_;
+ delete text_;
+ }
+}
+
+void MenuItem::SetText(std::u16string text) { text_->SetText(std::move(text)); }
+
+Menu::Menu() { container_ = controls::FlexLayout::Create(); }
+
+Menu::~Menu() {
+ if (!container_->GetWindowHost()) {
+ delete container_;
+ }
+
+ for (auto item : items_) {
+ delete item;
+ }
+}
+
+void Menu::AddItem(Component* item, gsl::index index) {
+ Expects(index >= 0 && index <= GetItemCount());
+
+ items_.insert(items_.cbegin() + index, item);
+ container_->AddChild(item->GetRootControl(), index);
+}
+
+Component* Menu::RemoveItem(gsl::index index) {
+ Expects(index >= 0 && index < GetItemCount());
+
+ Component* item = items_[index];
+
+ items_.erase(items_.cbegin() + index);
+ container_->RemoveChild(index);
+
+ return item;
+}
+} // namespace cru::ui::components