diff options
Diffstat (limited to 'include/cru')
-rw-r--r-- | include/cru/common/event.hpp | 5 | ||||
-rw-r--r-- | include/cru/ui/controls/button.hpp | 51 | ||||
-rw-r--r-- | include/cru/ui/controls/flex_layout.hpp | 2 | ||||
-rw-r--r-- | include/cru/ui/render/border_render_object.hpp | 4 | ||||
-rw-r--r-- | include/cru/ui/render/flex_layout_render_object.hpp | 22 | ||||
-rw-r--r-- | include/cru/ui/render/render_object.hpp | 11 | ||||
-rw-r--r-- | include/cru/ui/render/text_render_object.hpp | 4 | ||||
-rw-r--r-- | include/cru/ui/render/window_render_object.hpp | 2 |
8 files changed, 52 insertions, 49 deletions
diff --git a/include/cru/common/event.hpp b/include/cru/common/event.hpp index 12c0d0cd..33b2e3f6 100644 --- a/include/cru/common/event.hpp +++ b/include/cru/common/event.hpp @@ -183,6 +183,7 @@ struct EventRevokerDestroyer { class EventRevokerGuard { public: + EventRevokerGuard() = default; explicit EventRevokerGuard(EventRevoker&& revoker) : revoker_(new EventRevoker(std::move(revoker))) {} EventRevokerGuard(const EventRevokerGuard& other) = delete; @@ -200,6 +201,10 @@ class EventRevokerGuard { void Release() { revoker_.release(); } + void Reset(EventRevoker&& revoker) { + revoker_.reset(new EventRevoker(std::move(revoker))); + } + private: std::unique_ptr<EventRevoker, details::EventRevokerDestroyer> revoker_; }; // namespace cru diff --git a/include/cru/ui/controls/button.hpp b/include/cru/ui/controls/button.hpp index b5cca7dc..0fad0035 100644 --- a/include/cru/ui/controls/button.hpp +++ b/include/cru/ui/controls/button.hpp @@ -13,15 +13,25 @@ class BorderRenderObject; } namespace cru::ui::controls { -struct ButtonBorderStyle { +using render::CornerRadius; + +struct ButtonStateStyle { + std::shared_ptr<platform::graph::Brush> border_brush; + Thickness border_thickness; + CornerRadius corner_radius; + std::shared_ptr<platform::graph::Brush> foreground_brush; + std::shared_ptr<platform::graph::Brush> background_brush; +}; + +struct ButtonStyle { // corresponds to ButtonState::Normal - render::BorderStyle normal; + ButtonStateStyle normal; // corresponds to ButtonState::Hover - render::BorderStyle hover; + ButtonStateStyle hover; // corresponds to ButtonState::Press - render::BorderStyle press; + ButtonStateStyle press; // corresponds to ButtonState::PressCancel - render::BorderStyle press_cancel; + ButtonStateStyle press_cancel; }; enum class ButtonState { @@ -32,7 +42,7 @@ enum class ButtonState { // mouse is pressed in it Press, // mouse is pressed outside button - PressCancel, + PressCancel, }; class Button : public ContentControl { @@ -58,31 +68,8 @@ class Button : public ContentControl { render::RenderObject* GetRenderObject() const override; public: - render::BorderStyle GetNormalBorderStyle() const { - return border_style_.normal; - } - void SetNormalBorderStyle(render::BorderStyle newStyle) { - border_style_.normal = std::move(newStyle); - } - - render::BorderStyle GetHoverBorderStyle() const { - return border_style_.hover; - } - void SetHoverBorderStyle(render::BorderStyle newStyle) { - border_style_.hover = std::move(newStyle); - } - - render::BorderStyle GetPressBorderStyle() const { - return border_style_.press; - } - void SetPressBorderStyle(render::BorderStyle newStyle) { - border_style_.press = std::move(newStyle); - } - - ButtonBorderStyle GetBorderStyle() const { return border_style_; } - void SetBorderStyle(ButtonBorderStyle newStyle) { - border_style_ = std::move(newStyle); - } + const ButtonStyle& GetStyle() const { return style_; } + void SetStyle(ButtonStyle style); ButtonState GetState() const { return state_; } @@ -115,7 +102,7 @@ class Button : public ContentControl { MouseButton trigger_button_ = MouseButton::Left; - ButtonBorderStyle border_style_; + ButtonStyle style_; ClickDetector click_detector_; }; diff --git a/include/cru/ui/controls/flex_layout.hpp b/include/cru/ui/controls/flex_layout.hpp index 128a79b0..d8d92d08 100644 --- a/include/cru/ui/controls/flex_layout.hpp +++ b/include/cru/ui/controls/flex_layout.hpp @@ -42,7 +42,6 @@ class FlexLayout : public LayoutControl { void SetContentMainAlign(FlexMainAlignment value) { if (value == GetContentMainAlign()) return; render_object_->SetContentMainAlign(value); - if (const auto window = GetWindow()) window->InvalidateLayout(); } FlexDirection GetFlexDirection() const { @@ -52,7 +51,6 @@ class FlexLayout : public LayoutControl { void SetFlexDirection(FlexDirection direction) { if (direction == GetFlexDirection()) return; render_object_->SetFlexDirection(direction); - if (const auto window = GetWindow()) window->InvalidateLayout(); } FlexChildLayoutData GetChildLayoutData(Control* control); diff --git a/include/cru/ui/render/border_render_object.hpp b/include/cru/ui/render/border_render_object.hpp index 18809f91..e21ce34c 100644 --- a/include/cru/ui/render/border_render_object.hpp +++ b/include/cru/ui/render/border_render_object.hpp @@ -106,13 +106,13 @@ class BorderRenderObject : public RenderObject { RenderObject* HitTest(const Point& point) override; protected: - void OnSizeChanged(const Size& old_size, const Size& new_size) override; - void OnMeasureCore(const Size& available_size) override; void OnLayoutCore(const Rect& rect) override; Size OnMeasureContent(const Size& available_size) override; void OnLayoutContent(const Rect& content_rect) override; + void OnAfterLayout() override; + private: RenderObject* GetChild() const { return GetChildren().empty() ? nullptr : GetChildren()[0]; diff --git a/include/cru/ui/render/flex_layout_render_object.hpp b/include/cru/ui/render/flex_layout_render_object.hpp index 68ffc89e..7b71b96e 100644 --- a/include/cru/ui/render/flex_layout_render_object.hpp +++ b/include/cru/ui/render/flex_layout_render_object.hpp @@ -15,7 +15,7 @@ namespace internal { constexpr int align_start = 0; constexpr int align_end = align_start + 1; constexpr int align_center = align_end + 1; -//constexpr int align_stretch = align_center + 1; +// constexpr int align_stretch = align_center + 1; } // namespace internal enum class FlexMainAlignment { @@ -27,7 +27,7 @@ enum class FlexCrossAlignment { Start = internal::align_start, End = internal::align_end, Center = internal::align_center, -// Stretch = internal::align_stretch + // Stretch = internal::align_stretch }; struct FlexChildLayoutData { @@ -50,19 +50,33 @@ class FlexLayoutRenderObject : public RenderObject { ~FlexLayoutRenderObject() override = default; FlexDirection GetFlexDirection() const { return direction_; } - void SetFlexDirection(FlexDirection direction) { direction_ = direction; } + void SetFlexDirection(FlexDirection direction) { + direction_ = direction; + InvalidateLayout(); + } FlexMainAlignment GetContentMainAlign() const { return content_main_align_; } void SetContentMainAlign(FlexMainAlignment align) { content_main_align_ = align; + InvalidateLayout(); } FlexCrossAlignment GetItemCrossAlign() const { return item_cross_align_; } void SetItemCrossAlign(FlexCrossAlignment align) { item_cross_align_ = align; + InvalidateLayout(); + } + + FlexChildLayoutData GetChildLayoutData(int position) { + assert(position >= 0 && position < child_layout_data_.size()); + return child_layout_data_[position]; } - FlexChildLayoutData* GetChildLayoutData(int position); + void SetChildLayoutData(int position, const FlexChildLayoutData& data) { + assert(position >= 0 && position < child_layout_data_.size()); + child_layout_data_[position] = data; + InvalidateLayout(); + } void Draw(platform::graph::Painter* painter) override; diff --git a/include/cru/ui/render/render_object.hpp b/include/cru/ui/render/render_object.hpp index 2394bf97..befaa3ec 100644 --- a/include/cru/ui/render/render_object.hpp +++ b/include/cru/ui/render/render_object.hpp @@ -59,11 +59,7 @@ class RenderObject : public Object { Point GetOffset() const { return offset_; } void SetOffset(const Point& offset) { offset_ = offset; } Size GetSize() const { return size_; } - void SetSize(const Size& size) { - const auto old_size = size_; - size_ = size; - OnSizeChanged(old_size, size); - } + void SetSize(const Size& size) { size_ = size; } Thickness GetMargin() const { return margin_; } void SetMargin(const Thickness& margin) { margin_ = margin; } @@ -109,13 +105,14 @@ class RenderObject : public Object { // default is to invalidate both layout and paint virtual void OnRemoveChild(RenderObject* removed_child, int position); - virtual void OnSizeChanged(const Size& old_size, const Size& new_size); - virtual void OnMeasureCore(const Size& available_size); virtual void OnLayoutCore(const Rect& rect); virtual Size OnMeasureContent(const Size& available_size) = 0; virtual void OnLayoutContent(const Rect& content_rect) = 0; + virtual void OnAfterLayout(); + static void NotifyAfterLayoutRecursive(RenderObject* render_object); + Rect GetContentRect() const; private: diff --git a/include/cru/ui/render/text_render_object.hpp b/include/cru/ui/render/text_render_object.hpp index 054d9b47..a10e3b74 100644 --- a/include/cru/ui/render/text_render_object.hpp +++ b/include/cru/ui/render/text_render_object.hpp @@ -53,11 +53,11 @@ class TextRenderObject : public RenderObject { RenderObject* HitTest(const Point& point) override; protected: - void OnSizeChanged(const Size& old_size, const Size& new_size) override; - Size OnMeasureContent(const Size& available_size) override; void OnLayoutContent(const Rect& content_rect) override; + void OnAfterLayout() override; + private: std::shared_ptr<platform::graph::Brush> brush_; std::shared_ptr<platform::graph::Font> font_; diff --git a/include/cru/ui/render/window_render_object.hpp b/include/cru/ui/render/window_render_object.hpp index 431f7025..2260c293 100644 --- a/include/cru/ui/render/window_render_object.hpp +++ b/include/cru/ui/render/window_render_object.hpp @@ -40,6 +40,8 @@ class WindowRenderObject : public RenderObject { private: Window* window_; + EventRevokerGuard after_layout_event_guard_; + std::unique_ptr<IRenderHost> render_host_; }; } // namespace cru::ui::render |