From 4bc40b874d63442faf42fecc789f15db0a80e440 Mon Sep 17 00:00:00 2001 From: crupest Date: Fri, 2 Apr 2021 20:36:15 +0800 Subject: ... --- include/cru/ui/UiManager.hpp | 12 +++++++ include/cru/ui/render/ScrollBar.hpp | 68 +++++++++++++++++++++++-------------- 2 files changed, 55 insertions(+), 25 deletions(-) (limited to 'include') diff --git a/include/cru/ui/UiManager.hpp b/include/cru/ui/UiManager.hpp index 6c0d9500..b9af0065 100644 --- a/include/cru/ui/UiManager.hpp +++ b/include/cru/ui/UiManager.hpp @@ -2,10 +2,15 @@ #include "Base.hpp" #include "controls/Base.hpp" +#include "cru/platform/graphics/Brush.hpp" +#include "cru/ui/helper/ClickDetector.hpp" +#include "render/ScrollBar.hpp" #include "style/StyleRuleSet.hpp" +#include #include #include +#include namespace cru::ui { struct ThemeResources { @@ -18,6 +23,13 @@ struct ThemeResources { style::StyleRuleSet text_box_style; style::StyleRuleSet menu_item_style; + + std::shared_ptr scroll_bar_colllapsed_thumb_brush; + std::unordered_map< + render::ScrollBarBrushUsageKind, + std::unordered_map>> + scroll_bar_brushes; }; class UiManager : public Object { diff --git a/include/cru/ui/render/ScrollBar.hpp b/include/cru/ui/render/ScrollBar.hpp index 3293e9d0..f72aef9b 100644 --- a/include/cru/ui/render/ScrollBar.hpp +++ b/include/cru/ui/render/ScrollBar.hpp @@ -3,16 +3,19 @@ #include "cru/common/Base.hpp" #include "cru/common/Event.hpp" #include "cru/platform/graphics/Base.hpp" +#include "cru/platform/graphics/Brush.hpp" #include "cru/platform/graphics/Geometry.hpp" #include "cru/platform/graphics/Painter.hpp" #include "cru/platform/gui/Cursor.hpp" #include "cru/platform/gui/UiApplication.hpp" #include "cru/ui/Base.hpp" #include "cru/ui/controls/Control.hpp" +#include "cru/ui/helper/ClickDetector.hpp" #include #include #include +#include namespace cru::ui::render { class ScrollRenderObject; @@ -34,6 +37,8 @@ enum class ScrollBarAreaKind { Thumb }; +enum class ScrollBarBrushUsageKind { Arrow, ArrowBackground, Slot, Thumb }; + class ScrollBar : public Object { public: ScrollBar(gsl::not_null render_object, @@ -61,23 +66,27 @@ class ScrollBar : public Object { void UninstallHandlers() { InstallHandlers(nullptr); } gsl::not_null> - GetCollapsedThumbBrush() const; - gsl::not_null> - GetExpandedThumbBrush() const; - gsl::not_null> - GetExpandedSlotBrush() const; - gsl::not_null> - GetExpandedArrowBrush() const; - gsl::not_null> - GetExpandedArrowBackgroundBrush() const; + GetCollapsedThumbBrush(); + // Brush could be nullptr to use the theme brush. + void SetCollapsedThumbBrush( + std::shared_ptr brush); + gsl::not_null> GetBrush( + ScrollBarBrushUsageKind kind, helper::ClickState click_state); + // Brush could be nullptr to use the theme brush. + void SetBrush(ScrollBarBrushUsageKind kind, helper::ClickState click_state, + std::shared_ptr brush); protected: void OnDraw(platform::graphics::IPainter* painter, bool expand); - virtual void DrawUpArrow(platform::graphics::IPainter* painter, - const Rect& area) = 0; - virtual void DrawDownArrow(platform::graphics::IPainter* painter, - const Rect& area) = 0; + virtual void DrawUpArrow( + platform::graphics::IPainter* painter, const Rect& area, + gsl::not_null arrow_brush, + gsl::not_null background_brush) = 0; + virtual void DrawDownArrow( + platform::graphics::IPainter* painter, const Rect& area, + gsl::not_null arrow_brush, + gsl::not_null background_brush) = 0; std::optional ExpandedHitTest(const Point& point); @@ -113,10 +122,11 @@ class ScrollBar : public Object { bool is_expanded_ = false; std::shared_ptr collapsed_thumb_brush_; - std::shared_ptr expanded_thumb_brush_; - std::shared_ptr expanded_slot_brush_; - std::shared_ptr expanded_arrow_brush_; - std::shared_ptr expanded_arrow_background_brush_; + std::unordered_map< + ScrollBarBrushUsageKind, + std::unordered_map>> + brushes_; Rect move_thumb_thumb_original_rect_; std::optional move_thumb_start_; @@ -141,10 +151,14 @@ class HorizontalScrollBar : public ScrollBar { ~HorizontalScrollBar() override = default; protected: - void DrawUpArrow(platform::graphics::IPainter* painter, - const Rect& area) override; - void DrawDownArrow(platform::graphics::IPainter* painter, - const Rect& area) override; + void DrawUpArrow( + platform::graphics::IPainter* painter, const Rect& area, + gsl::not_null arrow_brush, + gsl::not_null background_brush) override; + void DrawDownArrow( + platform::graphics::IPainter* painter, const Rect& area, + gsl::not_null arrow_brush, + gsl::not_null background_brush) override; bool IsShowBar() override; @@ -166,10 +180,14 @@ class VerticalScrollBar : public ScrollBar { ~VerticalScrollBar() override = default; protected: - void DrawUpArrow(platform::graphics::IPainter* painter, - const Rect& area) override; - void DrawDownArrow(platform::graphics::IPainter* painter, - const Rect& area) override; + void DrawUpArrow( + platform::graphics::IPainter* painter, const Rect& area, + gsl::not_null arrow_brush, + gsl::not_null background_brush) override; + void DrawDownArrow( + platform::graphics::IPainter* painter, const Rect& area, + gsl::not_null arrow_brush, + gsl::not_null background_brush) override; bool IsShowBar() override; -- cgit v1.2.3