diff options
author | crupest <crupest@outlook.com> | 2018-12-05 16:37:58 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2018-12-05 16:37:58 +0800 |
commit | 8898aee6c70bde922ee5de2a6213a44798525a16 (patch) | |
tree | 90b6fc6eb526e2421458f942f390906d6a48a628 /src/ui/control.hpp | |
parent | 01b0378ed32eb2011863393892717483004cc375 (diff) | |
download | cru-8898aee6c70bde922ee5de2a6213a44798525a16.tar.gz cru-8898aee6c70bde922ee5de2a6213a44798525a16.tar.bz2 cru-8898aee6c70bde922ee5de2a6213a44798525a16.zip |
...
Diffstat (limited to 'src/ui/control.hpp')
-rw-r--r-- | src/ui/control.hpp | 45 |
1 files changed, 13 insertions, 32 deletions
diff --git a/src/ui/control.hpp b/src/ui/control.hpp index b2dad9fd..8dd1898d 100644 --- a/src/ui/control.hpp +++ b/src/ui/control.hpp @@ -28,19 +28,22 @@ namespace cru::ui bool vertical_stretchable = true; }; + struct AdditionalLayoutInfo + { + Point total_offset = Point::Zero(); + }; //the position cache struct ControlPositionCache { //The lefttop relative to the ancestor. - Point lefttop_position_absolute; + Point lefttop_position_absolute = Point::Zero(); }; class Control : public Object { friend class Window; - friend class LayoutManager; protected: struct GeometryInfo @@ -110,21 +113,14 @@ namespace cru::ui void TraverseDescendants(const std::function<void(Control*)>& predicate); //*************** region: position and size *************** - // Position and size part must be isolated from layout part. - // All the operations in this part must be done independently. - // And layout part must use api of this part. //Get the lefttop relative to its parent. virtual Point GetPositionRelative(); - //Set the lefttop relative to its parent. - virtual void SetPositionRelative(const Point& position); - //Get the actual size. virtual Size GetSize(); - //Set the actual size directly without re-layout. - virtual void SetSize(const Size& size); + virtual void SetRect(const Rect& rect); //Get lefttop relative to ancestor. This is only valid when //attached to window. Notice that the value is cached. @@ -203,7 +199,7 @@ namespace cru::ui void Measure(const Size& available_size, const AdditionalMeasureInfo& additional_info); - void Layout(const Rect& rect); + void Layout(const Rect& rect, const AdditionalLayoutInfo& additional_info); Size GetDesiredSize() const; @@ -281,8 +277,6 @@ namespace cru::ui Event<events::DrawEventArgs> draw_background_event; Event<events::DrawEventArgs> draw_foreground_event; - Event<events::PositionChangedEventArgs> position_changed_event; - Event<events::SizeChangedEventArgs> size_changed_event; //*************** region: tree event *************** protected: @@ -305,6 +299,8 @@ namespace cru::ui //*************** region: position and size event *************** protected: + virtual void OnRectChange(const Rect& old_rect, const Rect& new_rect); + void RegenerateGeometryInfo(); const GeometryInfo& GetGeometryInfo() const @@ -322,22 +318,14 @@ namespace cru::ui //*************** region: layout *************** private: Size OnMeasureCore(const Size& available_size, const AdditionalMeasureInfo& additional_info); - void OnLayoutCore(const Rect& rect); + void OnLayoutCore(const Rect& rect, const AdditionalLayoutInfo& additional_info); protected: virtual Size OnMeasureContent(const Size& available_size, const AdditionalMeasureInfo& additional_info); - virtual void OnLayoutContent(const Rect& rect); + virtual void OnLayoutContent(const Rect& rect, const AdditionalLayoutInfo& additional_info); - // Called by Layout after set position and size. - virtual void AfterLayoutSelf(); private: - // Only for layout manager to use. - // Check if the old position is updated to current position. - // If not, then a notify of position change and update will - // be done. - void CheckAndNotifyPositionChanged(); - void ThrowIfNotContainer() const { if (!is_container_) @@ -352,15 +340,8 @@ namespace cru::ui Control * parent_ = nullptr; std::vector<Control*> children_{}; - // When position is changed and notification hasn't been - // sent, it will be the old position. When position is changed - // more than once, it will be the oldest position since last - // notification. If notification has been sent, it will be updated - // to position_. - Point old_position_ = Point::Zero(); - Point position_ = Point::Zero(); - Size size_ = Size::Zero(); - + Rect rect_{}; + ControlPositionCache position_cache_{}; std::unordered_map<MouseButton, bool> is_mouse_click_valid_map_ |