aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-03-13 17:11:08 +0800
committercrupest <crupest@outlook.com>2022-03-13 17:11:08 +0800
commit1d14ce416bb4e5651b956790b621308acf73b64c (patch)
treec7ef7d9af3afcb93d6c9168bef698b6794884877
parent8d24d87036e0208af24cf66bd31333445a4f813e (diff)
downloadcru-1d14ce416bb4e5651b956790b621308acf73b64c.tar.gz
cru-1d14ce416bb4e5651b956790b621308acf73b64c.tar.bz2
cru-1d14ce416bb4e5651b956790b621308acf73b64c.zip
...
-rw-r--r--include/cru/ui/components/Component.h3
-rw-r--r--include/cru/ui/host/WindowHost.h2
-rw-r--r--src/theme_builder/components/conditions/CompoundConditionEditor.cpp2
-rw-r--r--src/theme_builder/components/stylers/CompoundStylerEditor.cpp30
-rw-r--r--src/ui/components/Menu.cpp8
5 files changed, 35 insertions, 10 deletions
diff --git a/include/cru/ui/components/Component.h b/include/cru/ui/components/Component.h
index 64c3ef47..34add594 100644
--- a/include/cru/ui/components/Component.h
+++ b/include/cru/ui/components/Component.h
@@ -1,5 +1,6 @@
#pragma once
#include "../Base.h"
+#include "cru/common/SelfResolvable.h"
namespace cru::ui::components {
/**
@@ -7,7 +8,7 @@ namespace cru::ui::components {
* \remarks Component should respect children's Component::IsDeleteByParent
* value and decide whether to delete it.
*/
-class CRU_UI_API Component : public Object {
+class CRU_UI_API Component : public Object, public SelfResolvable<Component> {
public:
Component() = default;
diff --git a/include/cru/ui/host/WindowHost.h b/include/cru/ui/host/WindowHost.h
index b1d0c998..d88482c4 100644
--- a/include/cru/ui/host/WindowHost.h
+++ b/include/cru/ui/host/WindowHost.h
@@ -17,7 +17,7 @@ class LayoutPaintCycler;
struct AfterLayoutEventArgs {};
// The bridge between control tree and native window.
-class CRU_UI_API WindowHost : public Object {
+class CRU_UI_API WindowHost : public Object, public SelfResolvable<WindowHost> {
friend controls::Control;
CRU_DEFINE_CLASS_LOG_TAG(u"WindowHost")
diff --git a/src/theme_builder/components/conditions/CompoundConditionEditor.cpp b/src/theme_builder/components/conditions/CompoundConditionEditor.cpp
index d0105e70..1fff17cc 100644
--- a/src/theme_builder/components/conditions/CompoundConditionEditor.cpp
+++ b/src/theme_builder/components/conditions/CompoundConditionEditor.cpp
@@ -39,6 +39,8 @@ CompoundConditionEditor::CompoundConditionEditor() {
SetLabel(u"Compound Condition");
GetContainer()->AddChild(&children_container_);
+ children_container_.SetMargin({20, 0, 0, 0});
+ children_container_.SetFlexDirection(ui::controls::FlexDirection::Vertical);
children_container_.SetItemCrossAlign(
ui::controls::FlexCrossAlignment::Start);
diff --git a/src/theme_builder/components/stylers/CompoundStylerEditor.cpp b/src/theme_builder/components/stylers/CompoundStylerEditor.cpp
index e5a7f32e..f96a9a8f 100644
--- a/src/theme_builder/components/stylers/CompoundStylerEditor.cpp
+++ b/src/theme_builder/components/stylers/CompoundStylerEditor.cpp
@@ -1,6 +1,11 @@
#include "CompoundStylerEditor.h"
#include "BorderStylerEditor.h"
+#include "ContentBrushStylerEditor.h"
#include "CursorStylerEditor.h"
+#include "FontStylerEditor.h"
+#include "MarginStylerEditor.h"
+#include "PaddingStylerEditor.h"
+#include "PreferredSizeStylerEditor.h"
#include "cru/common/ClonablePtr.h"
#include "cru/ui/ThemeManager.h"
#include "cru/ui/style/Styler.h"
@@ -43,11 +48,10 @@ CompoundStylerEditor::CompoundStylerEditor() {
add_child_button_.GetButton()->SetPreferredSize({24, 24});
add_child_button_.GetButton()->SetPadding(ui::Thickness(2));
add_child_button_.GetButton()->SetIconFillColor(ui::colors::green);
- add_child_button_.SetMenuItems({
- u"Compound Styler",
- u"Border Styler",
- u"Cursor Styler",
- });
+ add_child_button_.SetMenuItems({u"Compound Styler", u"Border Styler",
+ u"Cursor Styler", u"Content Brush Styler",
+ u"Font Styler", u"Margin Styler",
+ u"Padding Styler", u"Preferred Size Styler"});
add_child_button_.MenuItemSelectedEvent()->AddHandler([this](Index index) {
std::unique_ptr<StylerEditor> editor;
switch (index) {
@@ -60,6 +64,21 @@ CompoundStylerEditor::CompoundStylerEditor() {
case 2:
editor = std::make_unique<CursorStylerEditor>();
break;
+ case 3:
+ editor = std::make_unique<ContentBrushStylerEditor>();
+ break;
+ case 4:
+ editor = std::make_unique<FontStylerEditor>();
+ break;
+ case 5:
+ editor = std::make_unique<MarginStylerEditor>();
+ break;
+ case 6:
+ editor = std::make_unique<PaddingStylerEditor>();
+ break;
+ case 7:
+ editor = std::make_unique<PreferredSizeStylerEditor>();
+ break;
default:
break;
}
@@ -93,7 +112,6 @@ ClonablePtr<ui::style::CompoundStyler> CompoundStylerEditor::GetValue() {
void CompoundStylerEditor::SetValue(ui::style::CompoundStyler* value,
bool trigger_change) {
children_.clear();
- children_container_.ClearChildren();
for (const auto& styler : value->GetChildren()) {
auto editor = CreateStylerEditor(styler.get());
ConnectChangeEvent(editor.get());
diff --git a/src/ui/components/Menu.cpp b/src/ui/components/Menu.cpp
index 078c9f3f..471654ec 100644
--- a/src/ui/components/Menu.cpp
+++ b/src/ui/components/Menu.cpp
@@ -69,8 +69,9 @@ void Menu::AddTextItemAt(String text, gsl::index index,
std::function<void()> on_click) {
MenuItem* item = new MenuItem(std::move(text));
item->SetOnClick([this, index, on_click = std::move(on_click)] {
+ auto on_item_click = on_item_click_;
on_click();
- if (on_item_click_) on_item_click_(index);
+ if (on_item_click) on_item_click(index);
});
item->SetDeleteByParent(true);
AddItemAt(item, index);
@@ -78,7 +79,10 @@ void Menu::AddTextItemAt(String text, gsl::index index,
PopupMenu::PopupMenu(controls::Control* attached_control)
: attached_control_(attached_control), popup_(attached_control) {
- menu_.SetOnItemClick([this](Index) { this->Close(); });
+ menu_.SetOnItemClick([resolver = CreateResolver()](Index) {
+ auto t = static_cast<PopupMenu*>(resolver.Resolve());
+ if (t) t->popup_.GetNativeWindow()->Close();
+ });
popup_.AddChildAt(menu_.GetRootControl(), 0);
}