Aurore
A Switch-like interface for your app, on every screen
Loading...
Searching...
No Matches
box.hpp
Go to the documentation of this file.
1/*
2 Copyright 2020-2021 natinusala
3 Copyright 2021 XITRIX
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16*/
17
18#pragma once
19
20#include <aurore/core/view.hpp>
21
22namespace aurore
23{
24
35
37enum class AlignItems
38{
39 AUTO,
41 CENTER,
43 STRETCH,
47};
48
50enum class Axis
51{
52 ROW,
53 COLUMN,
54};
55
57enum class Wrap
58{
59 NO_WRAP,
60 WRAP,
62};
63
65enum class Direction
66{
67 INHERIT,
70};
71
73class Box : public View
74{
75 public:
77 Box(Axis flexDirection);
79 Box();
82
83 void draw(NVGcontext* vg, float x, float y, float width, float height, Style style, FrameContext* ctx) override;
84 View* getDefaultFocus() override;
85 View* hitTest(Point point) override;
86 View* getNextFocus(FocusDirection direction, View* currentView) override;
87 void willAppear(bool resetState) override;
88 void willDisappear(bool resetState) override;
89 void onWindowSizeChanged() override;
90 void onThemeChanged() override;
91 void onFocusGained() override;
92 void onFocusLost() override;
93 void onParentFocusGained(View* focusedView) override;
94 void onParentFocusLost(View* focusedView) override;
95 bool applyXMLAttribute(std::string name, std::string value) override;
96
97 static View* create();
98
101 virtual View* getParentNavigationDecision(View* from, View* newFocus, FocusDirection direction);
102
107 virtual void addView(View* view);
108
113 virtual void addView(View* view, size_t position);
114
118 virtual void removeView(View* view, bool free = true);
119
123 virtual void clearViews(bool free = true);
124
131 virtual void setPadding(float padding);
132
139 virtual void setPadding(float top, float right, float bottom, float left);
140
145 virtual void setPaddingTop(float top);
146
148
153 virtual void setPaddingRight(float right);
154
156
161 virtual void setPaddingBottom(float bottom);
162
164
169 virtual void setPaddingLeft(float left);
170
172
177 virtual void setGap(float gap);
178
182 float getGap();
183
188 void setRowGap(float gap);
189 float getRowGap();
190
195 void setColumnGap(float gap);
197
204
210 void setAlignItems(AlignItems alignment);
211
218 void setDirection(Direction direction);
219
221 void setAxis(Axis axis);
222 Axis getAxis() const;
223
227 void setWrap(Wrap wrap);
228
232 Wrap getWrap() const;
233
235 std::vector<View*>& getChildren();
236
240 virtual void getCullingBounds(float* top, float* right, float* bottom, float* left);
241
248 void forwardXMLAttribute(std::string attributeName, View* target);
249
257 void forwardXMLAttribute(std::string attributeName, View* target, std::string targetAttributeName);
258
269 virtual void onChildFocusGained(View* directChild, View* focusedView);
270
275 virtual void onChildFocusLost(View* directChild, View* focusedView);
276
277 View* getView(std::string id) override;
278
281
283 void setDefaultFocusedIndex(int index);
284
286
289
291 virtual bool isChildFocused();
292
293 private:
294 Axis axis;
295
296 std::vector<View*> children;
297
298 size_t defaultFocusedIndex = 0;
299 View* lastFocusedView = nullptr;
300
301 std::unordered_map<std::string, std::pair<std::string, View*>> forwardedAttributes;
302
303 protected:
305 std::string getDefaultAccessibilityLabel() override;
306
316 void inflateFromXMLString(std::string_view xml);
317
327 void inflateFromXMLElement(tinyxml2::XMLElement* element);
328
338 void inflateFromXMLRes(const std::string& res);
339
349 void inflateFromXMLFile(const std::string& path);
350
357 void handleXMLElement(tinyxml2::XMLElement* element) override;
358};
359
362class Padding : public View
363{
364 public:
366
367 void draw(NVGcontext* vg, float x, float y, float width, float height, Style style, FrameContext* ctx) override;
368
369 static View* create();
370};
371
372} // namespace aurore
Generic FlexBox layout.
Definition box.hpp:74
float getPaddingBottom()
void onParentFocusLost(View *focusedView) override
float getColumnGap()
virtual void onChildFocusGained(View *directChild, View *focusedView)
Wrap getWrap() const
void setDirection(Direction direction)
void setColumnGap(float gap)
void inflateFromXMLElement(tinyxml2::XMLElement *element)
Axis getAxis() const
virtual void setPadding(float padding)
void handleXMLElement(tinyxml2::XMLElement *element) override
Box()
An empty row.
View * getLastFocusedView() const
See setLastFocusedView().
void willDisappear(bool resetState) override
View * getNextFocus(FocusDirection direction, View *currentView) override
float getPaddingRight()
void onParentFocusGained(View *focusedView) override
void setWrap(Wrap wrap)
virtual void setPaddingRight(float right)
void setDefaultFocusedIndex(int index)
The child that takes the focus first (negative values are ignored).
static View * create()
void setJustifyContent(JustifyContent justify)
float getPaddingLeft()
void forwardXMLAttribute(std::string attributeName, View *target, std::string targetAttributeName)
void onFocusGained() override
virtual void removeView(View *view, bool free=true)
void onWindowSizeChanged() override
float getGap()
void setAlignItems(AlignItems alignment)
virtual void addView(View *view)
std::vector< View * > & getChildren()
The children, in order. The box owns them: it deletes them with itself.
virtual void clearViews(bool free=true)
bool applyXMLAttribute(std::string name, std::string value) override
virtual View * getParentNavigationDecision(View *from, View *newFocus, FocusDirection direction)
virtual void onChildFocusLost(View *directChild, View *focusedView)
virtual void setPaddingLeft(float left)
Box(Axis flexDirection)
An empty box laying its children out along flexDirection.
void setAxis(Axis axis)
The axis the children are laid out along.
virtual void setGap(float gap)
void onFocusLost() override
virtual void setPaddingTop(float top)
void setRowGap(float gap)
float getRowGap()
size_t getDefaultFocusedIndex() const
void inflateFromXMLString(std::string_view xml)
virtual void getCullingBounds(float *top, float *right, float *bottom, float *left)
~Box()
Deletes the children (those a ptrLock() holds go to the deletion pool).
void inflateFromXMLRes(const std::string &res)
void willAppear(bool resetState) override
void inflateFromXMLFile(const std::string &path)
float getPaddingTop()
virtual bool isChildFocused()
Whether the focus is on one of the children, at any depth.
virtual void addView(View *view, size_t position)
virtual void setPadding(float top, float right, float bottom, float left)
View * getView(std::string id) override
virtual void setPaddingBottom(float bottom)
std::string getDefaultAccessibilityLabel() override
A focusable box says the texts shown in it (getAccessibilityText).
void setLastFocusedView(View *view)
The child the focus goes back to when the box gets it again.
View * getDefaultFocus() override
void draw(NVGcontext *vg, float x, float y, float width, float height, Style style, FrameContext *ctx) override
void forwardXMLAttribute(std::string attributeName, View *target)
View * hitTest(Point point) override
void onThemeChanged() override
Definition frame_context.hpp:30
Definition box.hpp:363
static View * create()
void draw(NVGcontext *vg, float x, float y, float width, float height, Style style, FrameContext *ctx) override
Simple wrapper around StyleValues for the array operator.
Definition style.hpp:115
Definition view.hpp:232
Definition actions.hpp:25
Direction
The writing direction a box lays its children out in.
Definition box.hpp:66
JustifyContent
How a box spreads its children along its axis (justifyContent in XML).
Definition box.hpp:27
FocusDirection
Focus direction when navigating.
Definition view.hpp:96
Wrap
Whether a box's children go on to new lines when they do not fit (flexWrap).
Definition box.hpp:58
AlignItems
How a box places its children across its axis (alignItems in XML).
Definition box.hpp:38
Axis
The direction a box lays its children out in (axis in XML).
Definition box.hpp:51
Definition geometry.hpp:26