diff options
author | crupest <crupest@outlook.com> | 2021-02-27 22:16:28 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-02-27 22:16:28 +0800 |
commit | 4a0c86d94a06e72be0988062d49a19c05142434a (patch) | |
tree | b99a9614a75a460ebac21e7bd79a7dea44cb8c39 | |
parent | 9c2f860ea80310f87b62a2947b4ddea5e7d85587 (diff) | |
download | cru-4a0c86d94a06e72be0988062d49a19c05142434a.tar.gz cru-4a0c86d94a06e72be0988062d49a19c05142434a.tar.bz2 cru-4a0c86d94a06e72be0988062d49a19c05142434a.zip |
...
-rw-r--r-- | include/cru/ui/Base.hpp | 4 | ||||
-rw-r--r-- | include/cru/ui/render/ScrollBar.hpp (renamed from include/cru/ui/render/ScrollBarDelegate.hpp) | 24 | ||||
-rw-r--r-- | include/cru/ui/render/ScrollRenderObject.hpp | 2 | ||||
-rw-r--r-- | src/ui/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/ui/render/ScrollBar.cpp (renamed from src/ui/render/ScrollBarDelegate.cpp) | 12 | ||||
-rw-r--r-- | src/ui/render/ScrollRenderObject.cpp | 2 |
6 files changed, 25 insertions, 23 deletions
diff --git a/include/cru/ui/Base.hpp b/include/cru/ui/Base.hpp index b2939a0b..fbdfec77 100644 --- a/include/cru/ui/Base.hpp +++ b/include/cru/ui/Base.hpp @@ -43,9 +43,11 @@ class RenderObject; namespace style { class StyleRuleSet; class StyleRuleSetBind; -} +} // namespace style //-------------------- region: basic types -------------------- +enum class Direction { Horizontal, Vertical }; + namespace internal { constexpr int align_start = 0; constexpr int align_end = align_start + 1; diff --git a/include/cru/ui/render/ScrollBarDelegate.hpp b/include/cru/ui/render/ScrollBar.hpp index e5c63f6d..a9be49a3 100644 --- a/include/cru/ui/render/ScrollBarDelegate.hpp +++ b/include/cru/ui/render/ScrollBar.hpp @@ -5,6 +5,7 @@ #include "cru/platform/graphics/Base.hpp" #include "cru/platform/graphics/Painter.hpp" #include "cru/platform/gui/UiApplication.hpp" +#include "cru/ui/Base.hpp" #include "cru/ui/controls/Control.hpp" #include <gsl/pointers> @@ -14,6 +15,14 @@ namespace cru::ui::render { class ScrollRenderObject; +enum class ScrollKind { Absolute, Page, Line }; + +struct Scroll { + Direction direction; + ScrollKind kind; + float offset; +}; + enum class ScrollBarAreaKind { UpArrow, // Line up DownArrow, // Line down @@ -39,7 +48,7 @@ class ScrollBar : public Object { virtual std::optional<ScrollBarAreaKind> HitTest(const Point& point) = 0; - IEvent<float>* ScrollAttemptEvent() { return &scroll_attempt_event_; } + IEvent<Scroll>* ScrollAttemptEvent() { return &scroll_attempt_event_; } void InstallHandlers(controls::Control* control); void UninstallHandlers() { InstallHandlers(nullptr); } @@ -62,7 +71,7 @@ class ScrollBar : public Object { EventRevokerListGuard event_guard_; - Event<float> scroll_attempt_event_; + Event<Scroll> scroll_attempt_event_; }; class HorizontalScrollBar : public ScrollBar { @@ -98,11 +107,6 @@ class VerticalScrollBar : public ScrollBar { void OnDraw(platform::graphics::IPainter* painter, bool expand) override; }; -struct ScrollBarScrollAttemptArgs { - float x_offset; - float y_offset; -}; - // A delegate to draw scrollbar and register related events. class ScrollBarDelegate : public Object { public: @@ -122,9 +126,7 @@ class ScrollBarDelegate : public Object { bool IsVerticalBarEnabled() const { return horizontal_bar_.IsEnabled(); } void SetVerticalBarEnabled(bool value) { horizontal_bar_.SetEnabled(value); } - IEvent<ScrollBarScrollAttemptArgs>* ScrollAttemptEvent() { - return &scroll_attempt_event_; - } + IEvent<Scroll>* ScrollAttemptEvent() { return &scroll_attempt_event_; } void DrawScrollBar(platform::graphics::IPainter* painter); @@ -137,6 +139,6 @@ class ScrollBarDelegate : public Object { HorizontalScrollBar horizontal_bar_; VerticalScrollBar vertical_bar_; - Event<ScrollBarScrollAttemptArgs> scroll_attempt_event_; + Event<Scroll> scroll_attempt_event_; }; } // namespace cru::ui::render diff --git a/include/cru/ui/render/ScrollRenderObject.hpp b/include/cru/ui/render/ScrollRenderObject.hpp index 5a431527..6a6ef198 100644 --- a/include/cru/ui/render/ScrollRenderObject.hpp +++ b/include/cru/ui/render/ScrollRenderObject.hpp @@ -2,7 +2,7 @@ #include "RenderObject.hpp" #include "cru/platform/graphics/util/Painter.hpp" -#include "cru/ui/render/ScrollBarDelegate.hpp" +#include "cru/ui/render/ScrollBar.hpp" #include <memory> #include <optional> diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 6153bc07..7d2792d6 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -33,7 +33,7 @@ add_library(cru_ui STATIC render/FlexLayoutRenderObject.cpp render/LayoutHelper.cpp render/RenderObject.cpp - render/ScrollBarDelegate.cpp + render/ScrollBar.cpp render/ScrollRenderObject.cpp render/StackLayoutRenderObject.cpp render/TextRenderObject.cpp @@ -78,7 +78,7 @@ target_sources(cru_ui PUBLIC ${CRU_UI_INCLUDE_DIR}/render/LayoutRenderObject.hpp ${CRU_UI_INCLUDE_DIR}/render/MeasureRequirement.hpp ${CRU_UI_INCLUDE_DIR}/render/RenderObject.hpp - ${CRU_UI_INCLUDE_DIR}/render/ScrollBarDelegate.hpp + ${CRU_UI_INCLUDE_DIR}/render/ScrollBar.hpp ${CRU_UI_INCLUDE_DIR}/render/ScrollRenderObject.hpp ${CRU_UI_INCLUDE_DIR}/render/StackLayoutRenderObject.hpp ${CRU_UI_INCLUDE_DIR}/render/TextRenderObject.hpp diff --git a/src/ui/render/ScrollBarDelegate.cpp b/src/ui/render/ScrollBar.cpp index 2814c567..487f0b91 100644 --- a/src/ui/render/ScrollBarDelegate.cpp +++ b/src/ui/render/ScrollBar.cpp @@ -1,4 +1,4 @@ -#include "cru/ui/render/ScrollBarDelegate.hpp" +#include "cru/ui/render/ScrollBar.hpp" #include "../Helper.hpp" #include "cru/common/Base.hpp" @@ -125,12 +125,10 @@ ScrollBarDelegate::ScrollBarDelegate( : render_object_(render_object), horizontal_bar_(render_object), vertical_bar_(render_object) { - horizontal_bar_.ScrollAttemptEvent()->AddHandler([this](float offset) { - this->scroll_attempt_event_.Raise({offset, 0}); - }); - vertical_bar_.ScrollAttemptEvent()->AddHandler([this](float offset) { - this->scroll_attempt_event_.Raise({0, offset}); - }); + horizontal_bar_.ScrollAttemptEvent()->AddHandler( + [this](auto scroll) { this->scroll_attempt_event_.Raise(scroll); }); + vertical_bar_.ScrollAttemptEvent()->AddHandler( + [this](auto scroll) { this->scroll_attempt_event_.Raise(scroll); }); } void ScrollBarDelegate::DrawScrollBar(platform::graphics::IPainter* painter) { diff --git a/src/ui/render/ScrollRenderObject.cpp b/src/ui/render/ScrollRenderObject.cpp index 18b0adbf..a9ec729d 100644 --- a/src/ui/render/ScrollRenderObject.cpp +++ b/src/ui/render/ScrollRenderObject.cpp @@ -3,7 +3,7 @@ #include "cru/platform/graphics/Painter.hpp" #include "cru/platform/graphics/util/Painter.hpp" #include "cru/ui/controls/Control.hpp" -#include "cru/ui/render/ScrollBarDelegate.hpp" +#include "cru/ui/render/ScrollBar.hpp" #include <algorithm> #include <memory> |