CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
UIToolBar.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
11
13
16
17namespace CeresEngine {
18
19 class UIToolBarItem;
20 class UIToolBarDelegate;
21
25 class UIToolBar : public UIView {
26 private:
29
33
34 public:
36 explicit UIToolBar(const UIRect& frame);
37 ~UIToolBar() override;
38
39 public:
42
49
50 template<typename T = UIToolBarItem, typename... Args> T* addItem(Args&&... args) { return insertItem(ce_shared_new<T>(std::forward<Args>(args)...)); }
51
53
54 public:
56 void didChangeBounds(const UIRect& oldBounds) override;
57
60
62 void layoutSubviews() override;
63
65 void draw(UIGraphicsContext& context, const UIRect& dirtyRect) override;
66
68 [[nodiscard]] bool getClearsContextBeforeDrawing() const noexcept override { return false; }
69
70 private: // UIToolBarItem interface
71 friend class UIToolBarItem;
72 friend class UIToolBarItemGroup;
73
77
78 private:
79 class Button : public UIButton {
80 private:
82
83 public:
85 ~Button() override;
86
87 public:
88 };
89 };
90
105
108 friend class UIToolBar;
109
110 private:
116
118 UIToolBar* mToolBar = nullptr;
119
122
125
128
130 bool mBordered = true;
131
133 bool mNavigational = false;
134
136 bool mEnabled = true;
137
140
142 RC<UIView> mView = nullptr;
143
146
147 public:
150
151 public:
157 virtual ~UIToolBarItem();
158
159 public:
162
165
167 [[nodiscard]] const String& getLabel() const noexcept { return mLabel; }
168
170 void setLabel(const String& label);
171
174
177
179 [[nodiscard]] const String& getTitle() const noexcept { return mTitle; }
180
182 void setTitle(const String& title);
183
186
189
192
195
198
200 void setEnabled(bool enabled);
201
204
206 void setTexture(const HTexture& texture);
207
209 [[nodiscard]] UIView* getView() const noexcept { return mView.get(); }
210
212 void setView(UIView* view);
213 };
214
248
249} // namespace CeresEngine
A retain-release type of smart pointer.
Definition SmartPtr.hpp:132
An object that represents a graphics context.
Definition GraphicsContext.hpp:45
Base template for the event class.
Definition Event.hpp:27
A control that defines an area on the screen that can be used to trigger actions.
Definition UIButton.hpp:30
Definition UIToolBar.hpp:79
SPtr< UIToolBarItem > mItem
Definition UIToolBar.hpp:81
Button(const SPtr< UIToolBarItem > &item)
Definition UIToolBar.hpp:91
virtual void toolbarDidRemoveItem(UIToolBar *toolBar, UIToolBarItem *item)
Sent just after an item has been removed from a toolbar.
Definition UIToolBar.hpp:103
virtual void toolbarWillAddItem(UIToolBar *toolBar, UIToolBarItem *item)
Sent just before a new item is added to a toolbar.
Definition UIToolBar.hpp:97
Toolbars manage controls and views that apply to the main window's content area.
Definition UIToolBar.hpp:25
void layoutSubviews() override
Lays out subviews.
UIToolBarItem * insertItem(const SPtr< UIToolBarItem > &item, UInt32 index=~0u)
Inserts the specified item at the specified index.
Vector< SPtr< UIToolBarItem > > mItems
An array containing the toolbar's current items, in order.
Definition UIToolBar.hpp:28
bool getClearsContextBeforeDrawing() const noexcept override
A Boolean value that determines whether the view's bounds should be automatically cleared before draw...
Definition UIToolBar.hpp:68
UIToolBar(const UIRect &frame)
UISize getIntrinsicContentSize() const override
The natural size for the receiving view, considering only properties of the view itself.
void notifyItemDirty(UIToolBarItem *item)
Internal method used to notify when the user changes a UIToolBarItem.
UIToolBarDelegate * mDelegate
The toolbar's delegate.
Definition UIToolBar.hpp:32
void didChangeBounds(const UIRect &oldBounds) override
Called whenever the view bounds changes, either internally or programmatically by calls to setBounds.
UIToolBar()
Definition UIToolBar.hpp:35
friend class UIToolBarItem
Definition UIToolBar.hpp:71
const Vector< SPtr< UIToolBarItem > > & getItems() const noexcept
An array containing the toolbar's current items, in order.
Definition UIToolBar.hpp:41
T * addItem(Args &&... args)
Definition UIToolBar.hpp:50
void draw(UIGraphicsContext &context, const UIRect &dirtyRect) override
Overridden by subclasses to draw the view's texture within the specified rectangle.
void removeItem(const String &itemIdentifier)
A group of subitems in a toolbar item.
Definition UIToolBar.hpp:223
const Vector< SPtr< UIToolBarItem > > & getSubItems() const noexcept
The subitems for the receiver.
Definition UIToolBar.hpp:243
void getSubItems(const Vector< SPtr< UIToolBarItem > > &subItems)
The subitems for the receiver.
Vector< SPtr< UIToolBarItem > > mSubItems
The subitems for the receiver.
Definition UIToolBar.hpp:229
UIToolBarItemGroup(const String &itemIdentifier, const Vector< SPtr< UIToolBarItem > > &subItems)
Creates a new toolbar group item with the given identifier.
An item in a UIToolBar.
Definition UIToolBar.hpp:107
String mToolTip
The tooltip used when the receiver is displayed in the toolbar.
Definition UIToolBar.hpp:124
void setView(UIView *view)
The receiver's view.
String mTitle
The title of the toolbar item.
Definition UIToolBar.hpp:127
UIToolBar * getToolBar() const noexcept
The toolbar that is using the receiver.
Definition UIToolBar.hpp:164
bool mEnabled
A Boolean value that indicates whether the receiver is enabled.
Definition UIToolBar.hpp:136
bool mBordered
A Boolean value that determines whether the toolbar item has a bordered style.
Definition UIToolBar.hpp:130
RC< UIView > mActualView
A private field that holds the actual button view for the toolbar.
Definition UIToolBar.hpp:145
String mLabel
The receiver's label.
Definition UIToolBar.hpp:121
UIView * getView() const noexcept
The receiver's view.
Definition UIToolBar.hpp:209
void setTitle(const String &title)
The title of the toolbar item.
const String & getItemIdentifier() const noexcept
The receiver's identifier.
Definition UIToolBar.hpp:161
bool isBordered() const noexcept
A Boolean value that determines whether the toolbar item has a bordered style.
Definition UIToolBar.hpp:185
const HTexture & getTexture() const noexcept
Definition UIToolBar.hpp:203
void setNavigational(bool navigational)
A Boolean value that indicates whether the item behaves as a navigation item in the toolbar.
const String & getLabel() const noexcept
The receiver's label.
Definition UIToolBar.hpp:167
String mItemIdentifier
The receiver's identifier.
Definition UIToolBar.hpp:115
RC< UIView > mView
The receiver's view.
Definition UIToolBar.hpp:142
void setEnabled(bool enabled)
A Boolean value that indicates whether the receiver is enabled.
bool isNavigational() const noexcept
A Boolean value that indicates whether the item behaves as a navigation item in the toolbar.
Definition UIToolBar.hpp:191
void setTexture(const HTexture &texture)
bool mNavigational
A Boolean value that indicates whether the item behaves as a navigation item in the toolbar.
Definition UIToolBar.hpp:133
UIToolBar * mToolBar
The toolbar that is using the receiver.
Definition UIToolBar.hpp:118
bool isEnabled() const noexcept
A Boolean value that indicates whether the receiver is enabled.
Definition UIToolBar.hpp:197
const String & getTitle() const noexcept
The title of the toolbar item.
Definition UIToolBar.hpp:179
const String & getToolTip() const noexcept
The tooltip used when the receiver is displayed in the toolbar.
Definition UIToolBar.hpp:173
void setBordered(bool bordered)
A Boolean value that determines whether the toolbar item has a bordered style.
Event< void()> didSelect
An event triggered whenever the toolbar item is selected.
Definition UIToolBar.hpp:149
HTexture mTexture
The texture of the receiver.
Definition UIToolBar.hpp:139
void setToolTip(const String &toolTip)
The tooltip used when the receiver is displayed in the toolbar.
UIToolBarItem(const String &itemIdentifier)
Creates a new toolbar item with the given identifier.
void setLabel(const String &label)
The receiver's label.
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
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
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
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