CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
UIControl.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 "UIView.hpp"
11
13
15
16namespace CeresEngine {
17
19
30 class UIControl : public UIView {
31 public:
38 struct State {
39 public:
42
44 constexpr State() = default;
45
48 explicit constexpr State(const UInt32 raw) : raw(raw){};
49
50 public:
51 constexpr State operator+(const State& other) const noexcept { return State(raw | other.raw); }
52 constexpr State& operator+=(const State& other) noexcept {
53 raw |= other.raw;
54 return *this;
55 }
56
57 constexpr State operator-(const State& other) const noexcept { return State(raw & ~other.raw); }
58 constexpr State& operator-=(const State& other) noexcept {
59 raw &= ~other.raw;
60 return *this;
61 }
62
79 [[nodiscard]] constexpr bool contains(const State& member) const noexcept { return (raw & member.raw) == member.raw; }
80
82 [[nodiscard]] constexpr bool operator[](const State& other) const noexcept { return contains(other); }
83
85 [[nodiscard]] constexpr bool operator==(const State& other) const noexcept { return raw == other.raw; }
86
88 [[nodiscard]] constexpr bool operator!=(const State& other) const noexcept { return raw != other.raw; }
89
90 public: // Color transformations
93 [[nodiscard]] UIColor operator()(const UIColor& baseColor) const noexcept;
94
95 public: // Constants
98 static const State Normal; // NOLINT(readability-identifier-naming)
99
108 static const State Highlighted; // NOLINT(readability-identifier-naming)
109
116 static const State Disabled; // NOLINT(readability-identifier-naming)
117
123 static const State Selected; // NOLINT(readability-identifier-naming)
124
126 static const State Focused; // NOLINT(readability-identifier-naming)
127 };
128
133 Center,
134
137 Top,
138
140 Bottom,
141
144 Fill
145 };
146
151 Center,
152
155 Left,
156
158 Right,
159
162 Fill,
163
166 Leading,
167
171 };
172
173 private:
182
196
210
211 public:
214
217
218 public:
220 explicit UIControl(const UIRect& frame);
221 ~UIControl() override;
222
223 public:
225 [[nodiscard]] const State& getState() const noexcept { return mState; }
226
228 void setState(const State& state);
229
242
245
247 void setEnabled(bool enabled);
248
260
263
276
279
282
285
288
291
292 protected:
295 virtual void didChangeState(const State& oldState, const State& newState) {}
296
299 virtual void confirmAction();
300
303 virtual void cancelAction();
304
305 public: // UIResponder
307 [[nodiscard]] bool acceptsFirstResponder() const override;
308
310 [[nodiscard]] bool becomeFirstResponder() override;
311
313 [[nodiscard]] bool resignFirstResponder() override;
314
316 void mouseDown(const UIMouseEvent& event) override;
317
319 void mouseUp(const UIMouseEvent& event) override;
320
322 void rightMouseDown(const UIMouseEvent& event) override;
323
325 void rightMouseUp(const UIMouseEvent& event) override;
326
328 void mouseMoved(const UIMouseEvent& event) override;
329
331 void mouseEntered(const UIMouseEvent& event) override;
332
334 void mouseExited(const UIMouseEvent& event) override;
335
337 void keyDown(const UIKeyEvent& event) override;
338
339 public: // Appearance Properties
342
345
348
351
354
357 };
358
359 std::ostream& operator<<(std::ostream& os, const UIControl::State& state);
360
361} // namespace CeresEngine
A retain-release type of smart pointer.
Definition SmartPtr.hpp:132
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
static const UIFloatAppearanceProperty borderRadiusProperty
An appearance property that controls the control border radius.
Definition UIControl.hpp:344
void mouseExited(const UIMouseEvent &event) override
Informs the receiver that the cursor has exited a tracking rectangle.
ContentHorizontalAlignment
The horizontal alignment of content (text and textures) within a control.
Definition UIControl.hpp:149
@ Leading
Aligns the content horizontally from the leading edge of the control.
@ Center
Aligns the content horizontally in the center of the control.
@ Right
Aligns the content horizontally from the right of the control.
@ Left
Aligns the content horizontally from the left of the control (the default).
@ Trailing
Aligns the content horizontally from the trailing edge of the control.
bool isHighlighted() const noexcept
A Boolean value indicating whether the control draws a highlight.
static const UIFloatAppearanceProperty bottomRightBorderRadiusProperty
An appearance property that controls the control bottom-right border radius.
Definition UIControl.hpp:356
virtual void didChangeState(const State &oldState, const State &newState)
A internal method called whenever the internal control state changes.
Definition UIControl.hpp:295
void rightMouseUp(const UIMouseEvent &event) override
Informs the receiver that the user has released the right mouse button.
void mouseDown(const UIMouseEvent &event) override
Informs the receiver that the user has pressed the left mouse button.
void mouseEntered(const UIMouseEvent &event) override
Informs the receiver that the cursor has entered a tracking rectangle.
void setState(const State &state)
The state of the control, specified as a bit mask value.
UIControl()
Definition UIControl.hpp:219
void setContentVerticalAlignment(ContentVerticalAlignment contentVerticalAlignment)
The vertical alignment of content within the control's bounds.
void rightMouseDown(const UIMouseEvent &event) override
Informs the receiver that the user has pressed the right mouse button.
void keyDown(const UIKeyEvent &event) override
Informs the receiver that the user has pressed a key.
ContentVerticalAlignment getContentVerticalAlignment() const
The vertical alignment of content within the control's bounds.
Definition UIControl.hpp:281
const State & getState() const noexcept
The state of the control, specified as a bit mask value.
Definition UIControl.hpp:225
static const UIFloatAppearanceProperty topLeftBorderRadiusProperty
An appearance property that controls the control top-left border radius.
Definition UIControl.hpp:347
Event< void()> didLostFocus
A signal dispatched to a UIControl once it loses focus.
Definition UIControl.hpp:216
static const UIFloatAppearanceProperty controlSizeProperty
An appearance property that controls the control size.
Definition UIControl.hpp:341
void setSelected(bool selected)
A Boolean value indicating whether the control is in the selected state.
ContentHorizontalAlignment getContentHorizontalAlignment() const
The horizontal alignment of content within the control's bounds.
Definition UIControl.hpp:287
ContentVerticalAlignment
Constants for specifying the vertical alignment of content (text and textures) in a control.
Definition UIControl.hpp:131
@ Bottom
Aligns the content vertically at the bottom in the control.
@ Center
Aligns the content vertically in the center of the control.
@ Top
Aligns the content vertically at the top in the control (the default).
@ Fill
Aligns the content vertically to fill the content rectangle; textures may be stretched.
bool acceptsFirstResponder() const override
A Boolean value that indicates whether the responder accepts first responder status.
Event< void()> didGainFocus
A signal dispatched to a UIControl once it gains focus.
Definition UIControl.hpp:213
ContentHorizontalAlignment mContentHorizontalAlignment
The horizontal alignment of content within the control's bounds.
Definition UIControl.hpp:209
void setHighlighted(bool highlighted)
A Boolean value indicating whether the control draws a highlight.
UIControl(const UIRect &frame)
static const UIFloatAppearanceProperty bottomLeftBorderRadiusProperty
An appearance property that controls the control bottom-left border radius.
Definition UIControl.hpp:353
static const UIFloatAppearanceProperty topRightBorderRadiusProperty
An appearance property that controls the control top-right border radius.
Definition UIControl.hpp:350
void mouseUp(const UIMouseEvent &event) override
Informs the receiver that the user has released the left mouse button.
void mouseMoved(const UIMouseEvent &event) override
Informs the receiver that the mouse has moved.
bool isDisabled() const noexcept
A Boolean value indicating whether the control is in the enabled state.
Definition UIControl.hpp:244
void setEnabled(bool enabled)
A Boolean value indicating whether the control is in the enabled state.
virtual void confirmAction()
An internal method that can be overridden by control implementations that will be triggered once the ...
bool resignFirstResponder() override
Notifies the receiver that it's been asked to relinquish its status as first responder in its window.
bool isSelected() const noexcept
A Boolean value indicating whether the control is in the selected state.
bool isEnabled() const noexcept
A Boolean value indicating whether the control is in the enabled state.
Definition UIControl.hpp:241
State mState
The state of the control, specified as a bit mask value.
Definition UIControl.hpp:181
ContentVerticalAlignment mContentVerticalAlignment
The vertical alignment of content within the control's bounds.
Definition UIControl.hpp:195
virtual void cancelAction()
An internal method that can be overridden by control implementations that will be triggered once the ...
void setContentHorizontalAlignment(ContentHorizontalAlignment contentHorizontalAlignment)
The horizontal alignment of content within the control's bounds.
bool becomeFirstResponder() override
Notifies the receiver that it's about to become first responder in its window.
The infrastructure for drawing and handling events in a UI.
Definition UIView.hpp:153
static const UIRect kDefaultFrame
A rectangle that represents the default frame set by a view without an explicit frame.
Definition UIView.hpp:296
Definition Application.hpp:19
Color UIColor
Definition UIUtility.hpp:187
constexpr Byte operator<<(const Byte arg, const _IntType shift) noexcept
Definition DataTypes.hpp:44
struct CeresEngine::GLState state
Rect2 UIRect
A structure that contains the location and dimensions of a rectangle.
Definition UIUtility.hpp:33
std::uint32_t UInt32
Definition DataTypes.hpp:23
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
Constants describing the state of a control.
Definition UIControl.hpp:38
static const State Highlighted
Highlighted state of a control.
Definition UIControl.hpp:108
UIColor operator()(const UIColor &baseColor) const noexcept
Applies a color transformation to the given baseColor such as that the returned color represents the ...
constexpr State operator+(const State &other) const noexcept
Definition UIControl.hpp:51
static const State Selected
Selected state of a control.
Definition UIControl.hpp:123
constexpr State & operator+=(const State &other) noexcept
Definition UIControl.hpp:52
UInt32 raw
The raw numeric value of the represented state.
Definition UIControl.hpp:41
static const State Normal
The normal, or default state of a control—that is, enabled but neither selected nor highlighted.
Definition UIControl.hpp:98
constexpr State()=default
Creates a new default state object.
constexpr State operator-(const State &other) const noexcept
Definition UIControl.hpp:57
constexpr State & operator-=(const State &other) noexcept
Definition UIControl.hpp:58
constexpr bool operator[](const State &other) const noexcept
Returns a Boolean value that indicates whether a given element is a member of the option set.
Definition UIControl.hpp:82
constexpr bool contains(const State &member) const noexcept
Returns a Boolean value that indicates whether a given element is a member of the option set.
Definition UIControl.hpp:79
constexpr bool operator!=(const State &other) const noexcept
Compares two states if they are not the same.
Definition UIControl.hpp:88
constexpr bool operator==(const State &other) const noexcept
Compares two states if they are the same.
Definition UIControl.hpp:85
static const State Disabled
Disabled state of a control.
Definition UIControl.hpp:116
static const State Focused
Focused state of a control.
Definition UIControl.hpp:126
constexpr State(const UInt32 raw)
Initialize the State object with a raw representation of the state.
Definition UIControl.hpp:48
Definition UIEvent.hpp:129
Definition UIEvent.hpp:173