CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
UIButton.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
14
15namespace CeresEngine {
16
18 enum class UIButtonType {
21 };
22
30 class UIButton : public UIControl {
31 private:
38
48
57
65
75
82
89
92
93 public:
96
97 public:
99
105 explicit UIButton(String title, const SPtr<Texture>& texture = nullptr);
106 ~UIButton() override;
107
108 public:
110 UIButtonType getType() const { return mType; }
111
114
116 const String& getTitle() const { return mTitle; }
117
119 void setTitle(const String& title);
120
122 const String& getAlternateTitle() const { return mAlternateTitle; }
123
126
128 const SPtr<Texture>& getTexture() const { return mTexture; }
129
131 void setTexture(const SPtr<Texture>& texture);
132
135
138
141
144
147
150
151 public: // UIView
153 void didChangeFrame(const UIRect& oldFrame) override;
154
156 void didChangeBounds(const UIRect& bounds) override;
157
159 [[nodiscard]] bool isPointInside(const UIPoint& point, const Optional<const UIEvent&>& event = nullopt) override;
160
163
165 void draw(UIGraphicsContext& context, const UIRect& dirtyRect) override;
166
167 protected:
168 virtual void drawText(UIGraphicsContext& context);
169 virtual void drawFrame(UIGraphicsContext& context);
170
171 public: // UIResponder
173 void keyDown(const UIKeyEvent& event) override;
174
176 void keyUp(const UIKeyEvent& event) override;
177
179 void mouseDown(const UIMouseEvent& event) override;
180
182 void mouseUp(const UIMouseEvent& event) override;
183
184 private:
187
188 public:
193 };
194} // 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
An object that coordinates the layout and display of text characters.
Definition TextLayoutManager.hpp:74
A control that defines an area on the screen that can be used to trigger actions.
Definition UIButton.hpp:30
TextLayoutManager mLayoutManager
The manager that layouts text on the button.
Definition UIButton.hpp:91
static const UIColorAppearanceProperty backgroundColorProperty
Definition UIButton.hpp:190
UIButton(String title, const SPtr< Texture > &texture=nullptr)
Creates a new button with the given title and an optional texture.
UIButtonType getType() const
Sets the button's type, which affects its user interface and behavior when clicked.
Definition UIButton.hpp:110
SPtr< Texture > mAlternateTexture
An alternate texture that appears on the button when the button is in an on state.
Definition UIButton.hpp:74
void setAlternateTitle(const String &alternateTitle)
The title that the button displays when the button is in an on state.
String mTitle
The title displayed on the button when it's in an off state.
Definition UIButton.hpp:47
void setTextureScaling(UITextureScaling textureScaling)
void draw(UIGraphicsContext &context, const UIRect &dirtyRect) override
Displays the view and all its subviews if possible.
void mouseUp(const UIMouseEvent &event) override
Informs the receiver that the user has released the left mouse button.
void mouseDown(const UIMouseEvent &event) override
Informs the receiver that the user has pressed the left mouse button.
virtual void drawText(UIGraphicsContext &context)
static const UIColorAppearanceProperty highlightColorProperty
Definition UIButton.hpp:192
void setTexturePosition(UITexturePosition texturePosition)
const String & getTitle() const
The title displayed on the button when it's in an off state.
Definition UIButton.hpp:116
void setAlternateTexture(const SPtr< Texture > &alternateTexture)
UISize getIntrinsicContentSize() const override
The natural size for the receiving view, considering only properties of the view itself.
Event< void()> didClick
A signal dispatched by the button whenever the user clicks it.
Definition UIButton.hpp:95
void setType(UIButtonType type)
Sets the button's type, which affects its user interface and behavior when clicked.
UITextureScaling getTextureScaling() const
Definition UIButton.hpp:146
static const UIColorAppearanceProperty borderColorProperty
Definition UIButton.hpp:189
void keyDown(const UIKeyEvent &event) override
Informs the receiver that the user has pressed a key.
void didChangeBounds(const UIRect &bounds) override
Called whenever the view bounds changes, either internally or programmatically by calls to setBounds.
bool isPointInside(const UIPoint &point, const Optional< const UIEvent & > &event=nullopt) override
Returns a Boolean value indicating whether the receiver contains the specified point.
UIButtonType mType
Sets the button's type, which affects its user interface and behavior when clicked.
Definition UIButton.hpp:37
virtual void drawFrame(UIGraphicsContext &context)
SPtr< Texture > mTexture
The texture that appears on the button when it's in an off state, or nullptr if there is no such text...
Definition UIButton.hpp:64
void keyUp(const UIKeyEvent &event) override
Informs the receiver that the user has released a key.
void setTexture(const SPtr< Texture > &texture)
UITextureScaling mTextureScaling
The scaling mode applied to make the cell's texture fit the frame of the texture view.
Definition UIButton.hpp:88
void updateTextLayout()
Called internally whenever the text layout needs to be updated.
const SPtr< Texture > & getTexture() const
Definition UIButton.hpp:128
UITexturePosition getTexturePosition() const
Definition UIButton.hpp:140
String mAlternateTitle
The title that the button displays when the button is in an on state.
Definition UIButton.hpp:56
UITexturePosition mTexturePosition
The position of the button's texture relative to its title.
Definition UIButton.hpp:81
static const UIColorAppearanceProperty innerBorderColorProperty
Definition UIButton.hpp:191
const String & getAlternateTitle() const
The title that the button displays when the button is in an on state.
Definition UIButton.hpp:122
void didChangeFrame(const UIRect &oldFrame) override
Called whenever the view frame changes, either internally or programmatically by calls to setFrame.
const SPtr< Texture > & getAlternateTexture() const
Definition UIButton.hpp:134
void setTitle(const String &title)
The title displayed on the button when it's in an off state.
A definition of the fundamental behavior for controls, which are specialized views that notify your a...
Definition UIControl.hpp:30
Definition Application.hpp:19
std::shared_ptr< T > SPtr
SPtr is a smart pointer that retains shared ownership of an object through a pointer.
Definition SmartPtr.hpp:37
Size2 UISize
A type that contains width and height values.
Definition UIUtility.hpp:30
UIButtonType
Button types that can be used with UIButton
Definition UIButton.hpp:18
@ Regular
A regular button type.
Rect2 UIRect
A structure that contains the location and dimensions of a rectangle.
Definition UIUtility.hpp:33
UITextureScaling
Constants that specify a view's texture scaling behavior.
Definition UIUtility.hpp:82
@ ProportionallyDown
If it is too large for the destination, scale the texture down while preserving the aspect ratio.
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
UITexturePosition
Constants for specifying the position of a view texture relative to its title.
Definition UIUtility.hpp:58
@ TextureLeft
The texture is to the left of the title.
A UI appearance property that returns a color.
Definition UIAppearance.hpp:30
Definition UIEvent.hpp:129
Definition UIEvent.hpp:173