CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
UIScroller.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "UIControl.hpp"
11
12namespace CeresEngine {
13
14 class UIScrollView;
15
32 class UIScroller : public UIControl {
34
35 private:
37 double mValue = 0.0;
38
42 double mRelativeSize = 0.0;
43
45 bool mVertical = true;
46
47 private:
49 struct DragState {
52
55 double startValue;
56 };
57
60
61 public:
66
67 public:
68 explicit UIScroller();
69 explicit UIScroller(bool isVertical);
70
71 public:
73 [[nodiscard]] double getValue() const noexcept { return mValue; }
74
77
82 void setValueAndSize(double value, double relativeSize);
83
84 public:
86 void draw(UIGraphicsContext& context, const UIRect& dirtyRect) override;
87
88 public: // UIResponder
90 void mouseDown(const UIMouseEvent& event) override;
91
93 void mouseUp(const UIMouseEvent& event) override;
94
96 void mouseDragged(const CeresEngine::UIMouseEvent &event) override;
97
98 protected:
101 virtual UIRect getKnobSlotRect() const;
102
107 virtual UIRect getKnobRect() const;
108
110 virtual void drawKnob(UIGraphicsContext& context, const UIRect& knobRect);
111
113 virtual void drawKnobSlot(UIGraphicsContext& context, const UIRect& knobSlotRect);
114
115 public:
119
122
125
128
131 };
132
133} // namespace CeresEngine
An object that represents a graphics context.
Definition GraphicsContext.hpp:45
Definition Optional.hpp:17
Base template for the event class.
Definition Event.hpp:27
A definition of the fundamental behavior for controls, which are specialized views that notify your a...
Definition UIControl.hpp:30
UIControl()
Definition UIControl.hpp:219
An object that controls scrolling of a document view within a scroll view or other type of container ...
Definition UIScroller.hpp:32
static const UIFloatAppearanceProperty scrollerSizeProperty
Determines the size of the scroller.
Definition UIScroller.hpp:118
Optional< DragState > mDragState
Specifies the state of a drag operation.
Definition UIScroller.hpp:59
static const UIColorAppearanceProperty scrollerSlotColorProperty
Determines the color in which the scroller slot area is rendered with.
Definition UIScroller.hpp:121
bool mVertical
Specifies whether the scroller is vertical or horizontal.
Definition UIScroller.hpp:45
UIScroller(bool isVertical)
virtual void drawKnob(UIGraphicsContext &context, const UIRect &knobRect)
Draws thw knob of the scroller.
void draw(UIGraphicsContext &context, const UIRect &dirtyRect) override
Displays the view and all its subviews if possible.
virtual UIRect getKnobSlotRect() const
Computes the rectangle that represents the scroller knob slot.
double mRelativeSize
The proportional size of the scroller.
Definition UIScroller.hpp:42
static const UIColorAppearanceProperty scrollerKnobColorProperty
Determines the color in which the scroller knob area is rendered with.
Definition UIScroller.hpp:127
double mValue
The scroller position. Varies from 0 to 1.
Definition UIScroller.hpp:37
void mouseUp(const UIMouseEvent &event) override
Informs the receiver that the user has released the left mouse button.
void mouseDragged(const CeresEngine::UIMouseEvent &event) override
Informs the receiver that the user has moved the mouse with the left button pressed.
double getValue() const noexcept
The scroller position. Varies from 0 to 1.
Definition UIScroller.hpp:73
void mouseDown(const UIMouseEvent &event) override
Informs the receiver that the user has pressed the left mouse button.
static const UIFloatAppearanceProperty scrollerKnobRadiusProperty
Determines the radius the knob area is drawn with.
Definition UIScroller.hpp:130
virtual UIRect getKnobRect() const
Computes the rectangle that represents the scroller knob.
static const UIFloatAppearanceProperty scrollerSlotRadiusProperty
Determines the radius the slot area is drawn with.
Definition UIScroller.hpp:124
virtual void drawKnobSlot(UIGraphicsContext &context, const UIRect &knobSlotRect)
Draws thw knob slot of the scroller.
double getRelativeSize() const noexcept
The proportional size of the scroller.
Definition UIScroller.hpp:76
void setValueAndSize(double value, double relativeSize)
Sets the current value of the scroller alongside it's relative size.
Event< void()> didScroll
An event fired whenever the scroller value changes from user interaction.
Definition UIScroller.hpp:65
Definition Application.hpp:19
Rect2 UIRect
A structure that contains the location and dimensions of a rectangle.
Definition UIUtility.hpp:33
Point2 UIPoint
A type that contains a point in a two-dimensional coordinate system.
Definition UIUtility.hpp:27
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
A UI appearance property that returns a color.
Definition UIAppearance.hpp:30
Definition UIEvent.hpp:173
Specifies the state of a drag operation.
Definition UIScroller.hpp:49
UIPoint startPoint
Specifies the starting point of the drag operation.
Definition UIScroller.hpp:51
double startValue
Specifies the scroller value at the start of the dragging operation.
Definition UIScroller.hpp:55