aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/cru/platform/graphics/Factory.hpp8
-rw-r--r--include/cru/ui/controls/TextHostControlService.hpp2
-rw-r--r--include/cru/ui/events/UiEvent.hpp1
-rw-r--r--include/cru/ui/render/ScrollBar.hpp93
-rw-r--r--include/cru/ui/render/ScrollRenderObject.hpp15
5 files changed, 99 insertions, 20 deletions
diff --git a/include/cru/platform/graphics/Factory.hpp b/include/cru/platform/graphics/Factory.hpp
index d1b37783..f9018e13 100644
--- a/include/cru/platform/graphics/Factory.hpp
+++ b/include/cru/platform/graphics/Factory.hpp
@@ -21,5 +21,11 @@ struct IGraphFactory : virtual INativeResource {
virtual std::unique_ptr<ITextLayout> CreateTextLayout(
std::shared_ptr<IFont> font, std::u16string text) = 0;
+
+ std::unique_ptr<ISolidColorBrush> CreateSolidColorBrush(const Color& color) {
+ std::unique_ptr<ISolidColorBrush> brush = CreateSolidColorBrush();
+ brush->SetColor(color);
+ return brush;
+ }
};
-} // namespace cru::platform::graph
+} // namespace cru::platform::graphics
diff --git a/include/cru/ui/controls/TextHostControlService.hpp b/include/cru/ui/controls/TextHostControlService.hpp
index 9e6a08bc..340228fe 100644
--- a/include/cru/ui/controls/TextHostControlService.hpp
+++ b/include/cru/ui/controls/TextHostControlService.hpp
@@ -100,7 +100,7 @@ class TextHostControlService : public Object {
void SetupOneHandler(event::RoutedEvent<TArgs>* (Control::*event)(),
void (TextHostControlService::*handler)(
typename event::RoutedEvent<TArgs>::EventArgs)) {
- this->event_guard_ += (this->control_->*event)()->Direct()->AddHandler(
+ this->event_guard_ += (this->control_->*event)()->Bubble()->AddHandler(
std::bind(handler, this, std::placeholders::_1));
}
diff --git a/include/cru/ui/events/UiEvent.hpp b/include/cru/ui/events/UiEvent.hpp
index 660b33f5..22ad0150 100644
--- a/include/cru/ui/events/UiEvent.hpp
+++ b/include/cru/ui/events/UiEvent.hpp
@@ -84,6 +84,7 @@ class MouseEventArgs : public UiEventArgs {
// This point is relative to window client lefttop.
Point GetPoint() const { return point_.value_or(Point{}); }
+ Point GetPoint(render::RenderObject* render_target) const;
Point GetPointToContent(render::RenderObject* render_target) const;
private:
diff --git a/include/cru/ui/render/ScrollBar.hpp b/include/cru/ui/render/ScrollBar.hpp
index a9be49a3..e3dabb57 100644
--- a/include/cru/ui/render/ScrollBar.hpp
+++ b/include/cru/ui/render/ScrollBar.hpp
@@ -15,25 +15,27 @@
namespace cru::ui::render {
class ScrollRenderObject;
-enum class ScrollKind { Absolute, Page, Line };
+enum class ScrollKind { Absolute, Relative, Page, Line };
struct Scroll {
Direction direction;
ScrollKind kind;
- float offset;
+ // For absolute, the new scroll position. Otherwise, offset.
+ float value;
};
enum class ScrollBarAreaKind {
UpArrow, // Line up
DownArrow, // Line down
- UpThumb, // Page up
- DownThumb, // Page down
+ UpSlot, // Page up
+ DownSlot, // Page down
Thumb
};
class ScrollBar : public Object {
public:
- explicit ScrollBar(gsl::not_null<ScrollRenderObject*> render_object);
+ ScrollBar(gsl::not_null<ScrollRenderObject*> render_object,
+ Direction direction);
CRU_DELETE_COPY(ScrollBar)
CRU_DELETE_MOVE(ScrollBar)
@@ -41,12 +43,15 @@ class ScrollBar : public Object {
~ScrollBar() override = default;
public:
+ Direction GetDirection() const { return direction_; }
+
bool IsEnabled() const { return is_enabled_; }
void SetEnabled(bool value);
- void Draw(platform::graphics::IPainter* painter);
+ bool IsExpanded() const { return is_expanded_; }
+ void SetExpanded(bool value);
- virtual std::optional<ScrollBarAreaKind> HitTest(const Point& point) = 0;
+ void Draw(platform::graphics::IPainter* painter);
IEvent<Scroll>* ScrollAttemptEvent() { return &scroll_attempt_event_; }
@@ -54,20 +59,54 @@ class ScrollBar : public Object {
void UninstallHandlers() { InstallHandlers(nullptr); }
gsl::not_null<std::shared_ptr<platform::graphics::IBrush>>
- GetCollapseThumbBrush() const;
+ GetCollapsedThumbBrush() const;
+ gsl::not_null<std::shared_ptr<platform::graphics::IBrush>>
+ GetExpandedThumbBrush() const;
+ gsl::not_null<std::shared_ptr<platform::graphics::IBrush>>
+ GetExpandedSlotBrush() const;
+ gsl::not_null<std::shared_ptr<platform::graphics::IBrush>>
+ GetExpandedArrowBrush() const;
+ gsl::not_null<std::shared_ptr<platform::graphics::IBrush>>
+ GetExpandedArrowBackgroundBrush() const;
protected:
- virtual void OnDraw(platform::graphics::IPainter* painter, bool expand) = 0;
+ 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;
+
+ std::optional<ScrollBarAreaKind> ExpandedHitTest(const Point& point);
+
+ virtual bool IsShowBar() = 0;
+
+ virtual std::optional<Rect> GetExpandedAreaRect(
+ ScrollBarAreaKind area_kind) = 0;
+ virtual std::optional<Rect> GetCollapsedTriggerExpandAreaRect() = 0;
+ virtual std::optional<Rect> GetCollapsedThumbRect() = 0;
+
+ virtual float CalculateNewScrollPosition(const Rect& thumb_original_rect,
+ const Point& mouse_offset) = 0;
protected:
gsl::not_null<ScrollRenderObject*> render_object_;
private:
+ Direction direction_;
+
bool is_enabled_ = true;
bool is_expanded_ = false;
- std::shared_ptr<platform::graphics::IBrush> collapse_thumb_brush_;
+ std::shared_ptr<platform::graphics::IBrush> collapsed_thumb_brush_;
+ std::shared_ptr<platform::graphics::IBrush> expanded_thumb_brush_;
+ std::shared_ptr<platform::graphics::IBrush> expanded_slot_brush_;
+ std::shared_ptr<platform::graphics::IBrush> expanded_arrow_brush_;
+ std::shared_ptr<platform::graphics::IBrush> expanded_arrow_background_brush_;
+
+ Rect move_thumb_thumb_original_rect_;
+ std::optional<Point> move_thumb_start_;
EventRevokerListGuard event_guard_;
@@ -84,11 +123,20 @@ class HorizontalScrollBar : public ScrollBar {
~HorizontalScrollBar() override = default;
- public:
- std::optional<ScrollBarAreaKind> HitTest(const Point& point) override;
-
protected:
- void OnDraw(platform::graphics::IPainter* painter, bool expand) override;
+ void DrawUpArrow(platform::graphics::IPainter* painter,
+ const Rect& area) override;
+ void DrawDownArrow(platform::graphics::IPainter* painter,
+ const Rect& area) override;
+
+ bool IsShowBar() override;
+
+ std::optional<Rect> GetExpandedAreaRect(ScrollBarAreaKind area_kind) override;
+ std::optional<Rect> GetCollapsedTriggerExpandAreaRect() override;
+ std::optional<Rect> GetCollapsedThumbRect() override;
+
+ float CalculateNewScrollPosition(const Rect& thumb_original_rect,
+ const Point& mouse_offset) override;
};
class VerticalScrollBar : public ScrollBar {
@@ -100,11 +148,20 @@ class VerticalScrollBar : public ScrollBar {
~VerticalScrollBar() override = default;
- public:
- std::optional<ScrollBarAreaKind> HitTest(const Point& point) override;
-
protected:
- void OnDraw(platform::graphics::IPainter* painter, bool expand) override;
+ void DrawUpArrow(platform::graphics::IPainter* painter,
+ const Rect& area) override;
+ void DrawDownArrow(platform::graphics::IPainter* painter,
+ const Rect& area) override;
+
+ bool IsShowBar() override;
+
+ std::optional<Rect> GetExpandedAreaRect(ScrollBarAreaKind area_kind) override;
+ std::optional<Rect> GetCollapsedTriggerExpandAreaRect() override;
+ std::optional<Rect> GetCollapsedThumbRect() override;
+
+ float CalculateNewScrollPosition(const Rect& thumb_original_rect,
+ const Point& mouse_offset) override;
};
// A delegate to draw scrollbar and register related events.
diff --git a/include/cru/ui/render/ScrollRenderObject.hpp b/include/cru/ui/render/ScrollRenderObject.hpp
index 6a6ef198..aed25f8e 100644
--- a/include/cru/ui/render/ScrollRenderObject.hpp
+++ b/include/cru/ui/render/ScrollRenderObject.hpp
@@ -2,6 +2,7 @@
#include "RenderObject.hpp"
#include "cru/platform/graphics/util/Painter.hpp"
+#include "cru/ui/Base.hpp"
#include "cru/ui/render/ScrollBar.hpp"
#include <memory>
@@ -29,8 +30,22 @@ class ScrollRenderObject : public RenderObject {
// Return the coerced scroll offset.
Point GetScrollOffset();
+ float GetScrollOffset(Direction direction) {
+ return direction == Direction::Horizontal ? GetScrollOffset().x
+ : GetScrollOffset().y;
+ }
void SetScrollOffset(const Point& offset);
void SetScrollOffset(std::optional<float> x, std::optional<float> y);
+ void SetScrollOffset(Direction direction, std::optional<float> value) {
+ if (direction == Direction::Horizontal) {
+ SetScrollOffset(value, std::nullopt);
+ } else {
+ SetScrollOffset(std::nullopt, value);
+ }
+ }
+
+ void Scroll(const Scroll& scroll);
+
Point GetRawScrollOffset() const { return scroll_offset_; }
// Return the viewable area rect.