From 1dab244aaad8694ba37ef43caedd8c8ba0310c00 Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 5 Nov 2018 20:54:48 +0800 Subject: ... --- src/ui/control.h | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) (limited to 'src/ui/control.h') diff --git a/src/ui/control.h b/src/ui/control.h index e88228d0..25cd5c0a 100644 --- a/src/ui/control.h +++ b/src/ui/control.h @@ -5,9 +5,9 @@ #include #include #include -#include #include "base.h" +#include "format.h" #include "ui_base.h" #include "layout_base.h" #include "events/ui_event.h" @@ -63,6 +63,8 @@ namespace cru public: //*************** region: tree *************** + //TODO! + //virtual StringView GetControlType() const = 0; bool IsContainer() const { @@ -75,17 +77,8 @@ namespace cru return parent_; } - //Traverse the children - void ForeachChild(Function&& predicate) const; - void ForeachChild(Function&& predicate) const; - - //Return a vector of all children. This function will create a - //temporary copy of vector of children. If you just want to - //traverse all children, just call ForeachChild. - Vector GetChildren() const - { - return children_; - } + //Return a immutable vector of all children. + const std::vector& GetChildren() const; //Add a child at tail. void AddChild(Control* control); @@ -109,7 +102,7 @@ namespace cru } //Traverse the tree rooted the control including itself. - void TraverseDescendants(Function&& predicate); + void TraverseDescendants(const std::function& predicate); //*************** region: position and size *************** // Position and size part must be isolated from layout part. @@ -187,12 +180,12 @@ namespace cru //*************** region: border *************** - BorderProperty::Ptr GetBorderProperty() const + BorderProperty& GetBorderProperty() { return border_property_; } - void SetBorderProperty(BorderProperty::Ptr border_property); + void InvalidateBorder(); bool IsBordered() const { @@ -216,7 +209,7 @@ namespace cru } catch (const std::bad_any_cast&) { - throw std::runtime_error(fmt::format("Key \"{}\" is not of the type {}.", ToUtf8String(key), typeid(T).name())); + throw std::runtime_error(Format("Key \"{}\" is not of the type {}.", ToUtf8String(key), typeid(T).name())); } } @@ -234,6 +227,8 @@ namespace cru //*************** region: cursor *************** + //TODO! + /* Cursor::Ptr GetCursor() const { return cursor_; @@ -242,6 +237,7 @@ namespace cru void SetCursor(const Cursor::Ptr& cursor); Cursor::Ptr GetCursorInherit(); + */ //*************** region: events *************** @@ -380,7 +376,7 @@ namespace cru private: Control * parent_ = nullptr; - Vector children_{}; + std::vector children_{}; // When position is changed and notification hasn't been // sent, it will be the old position. When position is changed @@ -406,8 +402,7 @@ namespace cru Size desired_size_ = Size::Zero(); bool is_bordered_ = false; - BorderProperty::Ptr border_property_; - PropertyChangedNotifyObject::PropertyChangedHandlerPtr border_property_changed_listener_; + BorderProperty border_property_; std::unordered_map additional_properties_{}; @@ -461,6 +456,6 @@ namespace cru return control; } - constexpr std::initializer_list ControlList(std::initializer_list &&li) { return li; } + using ControlList = std::initializer_list; } } -- cgit v1.2.3