aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-02-27 22:16:28 +0800
committercrupest <crupest@outlook.com>2021-02-27 22:16:28 +0800
commit4a0c86d94a06e72be0988062d49a19c05142434a (patch)
treeb99a9614a75a460ebac21e7bd79a7dea44cb8c39 /include
parent9c2f860ea80310f87b62a2947b4ddea5e7d85587 (diff)
downloadcru-4a0c86d94a06e72be0988062d49a19c05142434a.tar.gz
cru-4a0c86d94a06e72be0988062d49a19c05142434a.tar.bz2
cru-4a0c86d94a06e72be0988062d49a19c05142434a.zip
...
Diffstat (limited to 'include')
-rw-r--r--include/cru/ui/Base.hpp4
-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.hpp2
3 files changed, 17 insertions, 13 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>