aboutsummaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-12-09 23:14:48 +0800
committercrupest <crupest@outlook.com>2020-12-09 23:14:48 +0800
commita7b2a80edb224e3e1371571ab46ffad252e2e252 (patch)
tree4ddebbbc61fba75c72e4dbb9ae5ca7341e07f292 /src/ui
parenta9cd77f9af0a3541f31460981cb0515ba43f5a1e (diff)
downloadcru-a7b2a80edb224e3e1371571ab46ffad252e2e252.tar.gz
cru-a7b2a80edb224e3e1371571ab46ffad252e2e252.tar.bz2
cru-a7b2a80edb224e3e1371571ab46ffad252e2e252.zip
...
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/CMakeLists.txt4
-rw-r--r--src/ui/component/Component.cpp5
-rw-r--r--src/ui/component/Menu.cpp57
3 files changed, 66 insertions, 0 deletions
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index d183fdbb..28200eb5 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -6,6 +6,8 @@ add_library(cru_ui STATIC
Helper.cpp
UiManager.cpp
+ components/Component.cpp
+ components/Menu.cpp
controls/Button.cpp
controls/Container.cpp
controls/ContentControl.cpp
@@ -43,6 +45,8 @@ target_sources(cru_ui PUBLIC
${CRU_UI_INCLUDE_DIR}/Base.hpp
${CRU_UI_INCLUDE_DIR}/DebugFlags.hpp
${CRU_UI_INCLUDE_DIR}/UiManager.hpp
+ ${CRU_UI_INCLUDE_DIR}/components/Component.hpp
+ ${CRU_UI_INCLUDE_DIR}/components/Menu.hpp
${CRU_UI_INCLUDE_DIR}/controls/Base.hpp
${CRU_UI_INCLUDE_DIR}/controls/Button.hpp
${CRU_UI_INCLUDE_DIR}/controls/Container.hpp
diff --git a/src/ui/component/Component.cpp b/src/ui/component/Component.cpp
new file mode 100644
index 00000000..5b62ffc9
--- /dev/null
+++ b/src/ui/component/Component.cpp
@@ -0,0 +1,5 @@
+#include "cru/ui/components/Component.hpp"
+
+namespace cru::ui::components {
+
+}
diff --git a/src/ui/component/Menu.cpp b/src/ui/component/Menu.cpp
new file mode 100644
index 00000000..ea9dcdb6
--- /dev/null
+++ b/src/ui/component/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