diff options
author | crupest <crupest@outlook.com> | 2022-02-16 22:42:34 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-02-16 22:42:34 +0800 |
commit | f75ab0bd662c73d15057d746347d09bf94a992a6 (patch) | |
tree | 91efc33de481edf5304001d80b914b69cc0fb338 /src | |
parent | 2711b7032cafdc9bdbd6ae06db0325c91e6e7f63 (diff) | |
download | cru-f75ab0bd662c73d15057d746347d09bf94a992a6.tar.gz cru-f75ab0bd662c73d15057d746347d09bf94a992a6.tar.bz2 cru-f75ab0bd662c73d15057d746347d09bf94a992a6.zip |
...
Diffstat (limited to 'src')
18 files changed, 91 insertions, 21 deletions
diff --git a/src/osx/graphics/quartz/TextLayout.cpp b/src/osx/graphics/quartz/TextLayout.cpp index 5d44c2e1..6013efba 100644 --- a/src/osx/graphics/quartz/TextLayout.cpp +++ b/src/osx/graphics/quartz/TextLayout.cpp @@ -1,12 +1,12 @@ #include "cru/osx/graphics/quartz/TextLayout.h" #include "cru/common/Base.h" +#include "cru/common/Format.h" #include "cru/common/StringUtil.h" #include "cru/osx/Convert.h" #include "cru/osx/graphics/quartz/Convert.h" #include "cru/osx/graphics/quartz/Resource.h" #include "cru/platform/Check.h" #include "cru/platform/graphics/Base.h" -#include "cru/common/Format.h" #include <algorithm> #include <limits> diff --git a/src/osx/gui/Window.mm b/src/osx/gui/Window.mm index e9de3ac7..7c64cc07 100644 --- a/src/osx/gui/Window.mm +++ b/src/osx/gui/Window.mm @@ -373,9 +373,7 @@ bool OsxWindow::ReleaseMouse() { return true; } void OsxWindow::SetCursor(std::shared_ptr<ICursor> cursor) { p_->cursor_ = CheckPlatform<OsxCursor>(cursor, GetPlatformId()); - if (p_->mouse_in_) { - p_->UpdateCursor(); - } + p_->UpdateCursor(); } void OsxWindow::SetToForeground() { diff --git a/src/theme_builder/CMakeLists.txt b/src/theme_builder/CMakeLists.txt index a0597d7b..cbd180bf 100644 --- a/src/theme_builder/CMakeLists.txt +++ b/src/theme_builder/CMakeLists.txt @@ -8,6 +8,7 @@ add_executable(cru_theme_builder components/conditions/CompoundConditionEditor.cpp components/conditions/ConditionEditor.cpp components/conditions/FocusConditionEditor.cpp + components/conditions/NoConditionEditor.cpp components/properties/CheckBoxPropertyEditor.cpp components/properties/ColorPropertyEditor.cpp components/properties/CornerRadiusPropertyEditor.cpp diff --git a/src/theme_builder/components/MainWindow.cpp b/src/theme_builder/components/MainWindow.cpp index 59e2dae8..d2a4c765 100644 --- a/src/theme_builder/components/MainWindow.cpp +++ b/src/theme_builder/components/MainWindow.cpp @@ -23,6 +23,9 @@ MainWindow::MainWindow() { style_rule_set_editor_.BindStyleRuleSet( preview_button_.GetStyleRuleSet()->GetParent()); main_layout_.AddChild(style_rule_set_editor_.GetRootControl()); + + main_layout_.SetChildLayoutData(0, {0, 0}); + main_layout_.SetChildLayoutData(1, {1, 1}); } MainWindow::~MainWindow() {} diff --git a/src/theme_builder/components/StyleRuleSetEditor.cpp b/src/theme_builder/components/StyleRuleSetEditor.cpp index 57671776..b5e6de91 100644 --- a/src/theme_builder/components/StyleRuleSetEditor.cpp +++ b/src/theme_builder/components/StyleRuleSetEditor.cpp @@ -6,6 +6,9 @@ namespace cru::theme_builder { using namespace cru::ui::controls; StyleRuleSetEditor::StyleRuleSetEditor() { + scroll_view_.SetChild(&container_); + + rules_layout_.SetFlexDirection(ui::controls::FlexDirection::Vertical); container_.AddChild(&rules_layout_); container_.AddChild(&add_button_); @@ -13,7 +16,7 @@ StyleRuleSetEditor::StyleRuleSetEditor() { add_button_text_.SetText(u"+"); add_button_.ClickEvent()->AddSpyOnlyHandler([this] { - auto rule_set = ui::style::StyleRule(ui::style::AndCondition::Create({}), + auto rule_set = ui::style::StyleRule(ui::style::NoCondition::Create(), ui::style::CompoundStyler::Create({})); style_rule_set_->AddStyleRule(rule_set); style_rule_editors_.push_back(std::make_unique<StyleRuleEditor>()); @@ -22,7 +25,7 @@ StyleRuleSetEditor::StyleRuleSetEditor() { }); } -StyleRuleSetEditor::~StyleRuleSetEditor() { rules_layout_.RemoveFromParent(); } +StyleRuleSetEditor::~StyleRuleSetEditor() { scroll_view_.RemoveFromParent(); } void StyleRuleSetEditor::BindStyleRuleSet( std::shared_ptr<ui::style::StyleRuleSet> rule_set) { diff --git a/src/theme_builder/components/StyleRuleSetEditor.h b/src/theme_builder/components/StyleRuleSetEditor.h index cb77d71e..c58a7a3d 100644 --- a/src/theme_builder/components/StyleRuleSetEditor.h +++ b/src/theme_builder/components/StyleRuleSetEditor.h @@ -4,6 +4,7 @@ #include "cru/ui/controls/Button.h" #include "cru/ui/controls/Control.h" #include "cru/ui/controls/FlexLayout.h" +#include "cru/ui/controls/ScrollView.h" #include "cru/ui/style/StyleRuleSet.h" namespace cru::theme_builder { @@ -17,13 +18,14 @@ class StyleRuleSetEditor : public ui::components::Component { ~StyleRuleSetEditor() override; public: - ui::controls::Control* GetRootControl() override { return &container_; } + ui::controls::Control* GetRootControl() override { return &scroll_view_; } void BindStyleRuleSet(std::shared_ptr<ui::style::StyleRuleSet> rule_set); private: std::shared_ptr<ui::style::StyleRuleSet> style_rule_set_; + ui::controls::ScrollView scroll_view_; ui::controls::FlexLayout container_; ui::controls::FlexLayout rules_layout_; std::vector<std::unique_ptr<StyleRuleEditor>> style_rule_editors_; diff --git a/src/theme_builder/components/conditions/CompoundConditionEditor.cpp b/src/theme_builder/components/conditions/CompoundConditionEditor.cpp index c53b2b69..b4f0b458 100644 --- a/src/theme_builder/components/conditions/CompoundConditionEditor.cpp +++ b/src/theme_builder/components/conditions/CompoundConditionEditor.cpp @@ -3,6 +3,7 @@ #include "ClickStateConditionEditor.h" #include "ConditionEditor.h" #include "FocusConditionEditor.h" +#include "NoConditionEditor.h" #include "cru/common/ClonablePtr.h" #include "cru/ui/style/Condition.h" @@ -32,13 +33,9 @@ CompoundConditionEditor::CompoundConditionEditor() { GetContainer()->AddChild(&children_container_); GetContainer()->AddChild(add_child_button_.GetRootControl()); add_child_button_.SetButtonText(u"+"); - add_child_button_.SetMenuItems({ - u"And Condtion", - u"Or Condtion", - u"Click State Condtion", - u"Focus Condtion", - u"Checked Condtion", - }); + add_child_button_.SetMenuItems({u"And Condition", u"Or Condition", + u"Click State Condition", u"Focus Condition", + u"Checked Condition", u"No Condition"}); add_child_button_.MenuItemSelectedEvent()->AddHandler([this](Index index) { std::unique_ptr<ConditionEditor> editor; switch (index) { @@ -57,6 +54,9 @@ CompoundConditionEditor::CompoundConditionEditor() { case 4: editor = std::make_unique<CheckedConditionEditor>(); break; + case 5: + editor = std::make_unique<NoConditionEditor>(); + break; default: break; } diff --git a/src/theme_builder/components/conditions/ConditionEditor.cpp b/src/theme_builder/components/conditions/ConditionEditor.cpp index f5edf674..8ffd33a5 100644 --- a/src/theme_builder/components/conditions/ConditionEditor.cpp +++ b/src/theme_builder/components/conditions/ConditionEditor.cpp @@ -3,6 +3,8 @@ #include "ClickStateConditionEditor.h" #include "CompoundConditionEditor.h" #include "FocusConditionEditor.h" +#include "NoConditionEditor.h" +#include "cru/common/Exception.h" #include "cru/ui/controls/FlexLayout.h" namespace cru::theme_builder::components::conditions { @@ -24,6 +26,10 @@ std::unique_ptr<ConditionEditor> CreateConditionEditor( auto result = std::make_unique<OrConditionEditor>(); result->SetValue(or_condition); return result; + } else if (auto no_condition = + dynamic_cast<ui::style::NoCondition*>(condition)) { + auto result = std::make_unique<NoConditionEditor>(); + return result; } else if (auto click_state_condition = dynamic_cast<ui::style::ClickStateCondition*>(condition)) { auto result = std::make_unique<ClickStateConditionEditor>(); @@ -40,7 +46,7 @@ std::unique_ptr<ConditionEditor> CreateConditionEditor( result->SetValue(checked_condition); return result; } else { - return nullptr; + throw Exception(u"Unknown condition type"); } } } // namespace cru::theme_builder::components::conditions diff --git a/src/theme_builder/components/conditions/NoConditionEditor.cpp b/src/theme_builder/components/conditions/NoConditionEditor.cpp new file mode 100644 index 00000000..a5087159 --- /dev/null +++ b/src/theme_builder/components/conditions/NoConditionEditor.cpp @@ -0,0 +1,7 @@ +#include "NoConditionEditor.h" + +namespace cru::theme_builder::components::conditions { +NoConditionEditor::NoConditionEditor() { SetLabel(u"No condition"); } + +NoConditionEditor::~NoConditionEditor() {} +} // namespace cru::theme_builder::components::conditions diff --git a/src/theme_builder/components/conditions/NoConditionEditor.h b/src/theme_builder/components/conditions/NoConditionEditor.h new file mode 100644 index 00000000..da5f99b0 --- /dev/null +++ b/src/theme_builder/components/conditions/NoConditionEditor.h @@ -0,0 +1,22 @@ +#pragma once +#include "ConditionEditor.h" +#include "cru/common/ClonablePtr.h" +#include "cru/ui/style/Condition.h" + +namespace cru::theme_builder::components::conditions { +class NoConditionEditor : public ConditionEditor { + public: + NoConditionEditor(); + ~NoConditionEditor() override; + + public: + ClonablePtr<ui::style::Condition> GetCondition() override { + return ui::style::NoCondition::Create(); + } + + IEvent<std::nullptr_t>* ChangeEvent() override { return &change_event_; } + + private: + Event<std::nullptr_t> change_event_; +}; +} // namespace cru::theme_builder::components::conditions diff --git a/src/theme_builder/components/stylers/CompoundStylerEditor.cpp b/src/theme_builder/components/stylers/CompoundStylerEditor.cpp index 27a29c59..69fd0824 100644 --- a/src/theme_builder/components/stylers/CompoundStylerEditor.cpp +++ b/src/theme_builder/components/stylers/CompoundStylerEditor.cpp @@ -14,7 +14,7 @@ CompoundStylerEditorChild::CompoundStylerEditorChild( remove_button_.SetChild(&remove_button_text_); remove_button_text_.SetText(u"-"); - container_.AddChild(editor->GetRootControl()); + container_.AddChild(styler_editor_->GetRootControl()); remove_button_.ClickEvent()->AddSpyOnlyHandler( [this] { this->remove_event_.Raise(nullptr); }); diff --git a/src/theme_builder/components/stylers/StylerEditor.cpp b/src/theme_builder/components/stylers/StylerEditor.cpp index 9c7852d4..4f3238e2 100644 --- a/src/theme_builder/components/stylers/StylerEditor.cpp +++ b/src/theme_builder/components/stylers/StylerEditor.cpp @@ -28,7 +28,7 @@ std::unique_ptr<StylerEditor> CreateStylerEditor(ui::style::Styler* styler) { editor->SetValue(cursor_styler); return editor; } else { - return nullptr; + throw Exception(u"Unknown styler type"); } } } // namespace cru::theme_builder::components::stylers diff --git a/src/ui/controls/Control.cpp b/src/ui/controls/Control.cpp index ba43b2b8..a66b605f 100644 --- a/src/ui/controls/Control.cpp +++ b/src/ui/controls/Control.cpp @@ -27,7 +27,7 @@ Control::Control() { }); } -Control::~Control() {} +Control::~Control() { ReleaseMouse(); } host::WindowHost* Control::GetWindowHost() const { auto parent = GetParent(); diff --git a/src/ui/host/RoutedEventDispatch.h b/src/ui/host/RoutedEventDispatch.h index ae1421ee..2ab51645 100644 --- a/src/ui/host/RoutedEventDispatch.h +++ b/src/ui/host/RoutedEventDispatch.h @@ -25,6 +25,8 @@ void DispatchEvent( controls::Control* const original_sender, events::RoutedEvent<EventArgs>* (controls::Control::*event_ptr)(), controls::Control* const last_receiver, Args&&... args) { + if (original_sender == nullptr) return; + CRU_UNUSED(event_name) if (original_sender == last_receiver) { @@ -41,7 +43,9 @@ void DispatchEvent( auto parent = original_sender; while (parent != last_receiver) { receive_list.push_back(parent); - parent = parent->GetParent(); + auto p = parent->GetParent(); + assert(!(p == nullptr && last_receiver != nullptr)); + parent = p; } if constexpr (debug_flags::routed_event) { diff --git a/src/ui/host/WindowHost.cpp b/src/ui/host/WindowHost.cpp index 6849d000..91b5f438 100644 --- a/src/ui/host/WindowHost.cpp +++ b/src/ui/host/WindowHost.cpp @@ -53,6 +53,8 @@ bool IsAncestor(controls::Control* control, controls::Control* ancestor) { // Ancestor at last. std::vector<controls::Control*> GetAncestorList(controls::Control* control) { + if (control == nullptr) return {}; + std::vector<controls::Control*> l; while (control != nullptr) { l.push_back(control); diff --git a/src/ui/render/FlexLayoutRenderObject.cpp b/src/ui/render/FlexLayoutRenderObject.cpp index 6475d005..0699768a 100644 --- a/src/ui/render/FlexLayoutRenderObject.cpp +++ b/src/ui/render/FlexLayoutRenderObject.cpp @@ -181,6 +181,10 @@ Size FlexLayoutMeasureContentImpl( total_shrink_factor += layout_data[i].shrink_factor; } + if (total_shrink_factor == 0.0f) { + break; + } + for (Index i : shrink_list) { const auto child = children[i]; const float shrink_length = layout_data[i].shrink_factor / @@ -208,7 +212,7 @@ Size FlexLayoutMeasureContentImpl( const Size new_size = child->GetDesiredSize(); const float new_main_length = GetMain(new_size, direction_tag); - if (new_main_length > new_measure_length) { + if (new_main_length >= new_measure_length) { to_remove.push_back(i); } } @@ -269,7 +273,7 @@ Size FlexLayoutMeasureContentImpl( const Size new_size = child->GetDesiredSize(); const float new_main_length = GetMain(new_size, direction_tag); - if (new_main_length < new_measure_length) { + if (new_main_length <= new_measure_length) { to_remove.push_back(i); } } @@ -309,6 +313,8 @@ Size FlexLayoutMeasureContentImpl( std::max(preferred_cross_length.GetLengthOr0(), child_max_cross_length); child_max_cross_length = std::max(min_cross_length.GetLengthOr0(), child_max_cross_length); + child_max_cross_length = + std::min(max_cross_length.GetLengthOrMax(), child_max_cross_length); for (Index i = 0; i < child_count; i++) { auto child_layout_data = layout_data[i]; diff --git a/src/ui/render/RenderObject.cpp b/src/ui/render/RenderObject.cpp index 67bbae12..6c09ce99 100644 --- a/src/ui/render/RenderObject.cpp +++ b/src/ui/render/RenderObject.cpp @@ -6,6 +6,19 @@ #include "cru/ui/host/WindowHost.h" namespace cru::ui::render { + +void RenderObject::SetParent(RenderObject* new_parent) { +#ifdef CRU_DEBUG + // In case there is a cycle. + auto parent = new_parent; + while (parent) { + assert(parent != this); + parent = parent->GetParent(); + } +#endif + parent_ = new_parent; +} + void RenderObject::SetAttachedControl(controls::Control* new_control) { auto old_control = control_; control_ = new_control; diff --git a/src/ui/render/TextRenderObject.cpp b/src/ui/render/TextRenderObject.cpp index a64c96d2..82f314bd 100644 --- a/src/ui/render/TextRenderObject.cpp +++ b/src/ui/render/TextRenderObject.cpp @@ -216,10 +216,13 @@ Size TextRenderObject::OnMeasureContent(const MeasureRequirement& requirement, result.width = std::max(result.width, preferred_size.width.GetLengthOr0()); result.width = std::max(result.width, requirement.min.width.GetLengthOr0()); + result.width = std::min(result.width, requirement.max.width.GetLengthOrMax()); result.height = std::max(result.height, preferred_size.height.GetLengthOr0()); result.height = std::max(result.height, requirement.min.height.GetLengthOr0()); + result.height = + std::min(result.height, requirement.max.height.GetLengthOrMax()); return result; } |