Aurore
A Switch-like interface for your app, on every screen
Loading...
Searching...
No Matches
view.hpp
Go to the documentation of this file.
1/*
2 Copyright 2019-2021 natinusala
3 Copyright 2019 p-sam
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 <nanovg.h>
21#include <stdio.h>
22#include <algorithm>
23#include <array>
24#include <functional>
25#include <memory>
26#include <set>
27#include <string>
28#include <unordered_map>
29#include <vector>
32#include <aurore/core/event.hpp>
36#include <aurore/core/util.hpp>
38#ifdef USE_LIBROMFS
39#include <romfs/romfs.hpp>
40#endif
41
45#define AURORE_REGISTER_ENUM_XML_ATTRIBUTE(name, enumType, method, ...) \
46 this->registerStringXMLAttribute(name, [this](std::string value) { \
47 std::unordered_map<std::string, enumType> enumMap = __VA_ARGS__; \
48 if (enumMap.count(value) > 0) \
49 method(enumMap[value]); \
50 else \
51 aurore::View::fatalXML("Illegal value \"" + value + "\" for XML attribute \"" + name + "\"; expected " + aurore::View::listXMLValues(enumMap)); })
52
57#define AURORE_REGISTER_CLICK_BY_ID(id, method) \
58 this->getView(id)->registerClickAction([this](aurore::View* view) { return method(view); })
59
60// Avoid conflicts with macro definitions in windows.h
61#undef RGB
62#undef TRANSPARENT
63#undef RELATIVE
64#undef ABSOLUTE
65
66namespace tinyxml2
67{
68class XMLDocument;
69class XMLElement;
70}
71struct YGNode;
72struct YGConfig;
73
74namespace aurore
75{
76
77const NVGcolor TRANSPARENT = nvgRGBA(0, 0, 0, 0);
78
81void nameXMLDocument(const tinyxml2::XMLDocument* document, const std::string& name);
84{
85 explicit ReadingXMLElement(const tinyxml2::XMLElement* element);
89
90 private:
91 const tinyxml2::XMLElement* previous;
92};
93
96{
97 UP,
98 DOWN,
99 LEFT,
100 RIGHT
101};
102
105{
106 NONE,
107 SIDEBAR,
108 BACKDROP,
112};
113
114enum class AlignSelf
115{
116 AUTO,
118 CENTER,
119 FLEX_END,
120 STRETCH,
121 BASELINE,
124};
125
127enum class Visibility
128{
129 VISIBLE,
130 INVISIBLE,
131 GONE,
132};
133
135enum class PositionType
136{
137 RELATIVE,
138 ABSOLUTE,
139 STATIC,
140};
141
143enum class BoxSizing
144{
145 BORDER_BOX,
147};
148
153{
154 FADE,
155 SLIDE_LEFT,
157 NONE,
158 LINEAR,
159};
160
162enum class ShadowType
163{
164 NONE,
165 GENERIC,
166 CUSTOM,
167};
168
170{
171 std::string title;
172 std::string iconPath;
173
174 void setIconFromRes(std::string name)
175 {
176#ifdef USE_LIBROMFS
177 iconPath = "@res/" + name;
178#else
179 iconPath = std::string(AURORE_RESOURCES) + name;
180#endif
181 }
182
183 void setIconFromFile(std::string path)
184 {
185 iconPath = path;
186 }
187
188 void setHintView(View* hintView);
189 View* getHintView() { return hintView; }
190
192
193 private:
194 View* hintView = nullptr;
195};
196
197extern const NVGcolor transparent;
198
199class View;
200class Box;
201class AppletFrame;
202class Subscription;
203class Activity;
204
207
208typedef std::function<void(void)> AutoAttributeHandler;
209typedef std::function<void(int)> IntAttributeHandler;
210typedef std::function<void(float)> FloatAttributeHandler;
211typedef std::function<void(std::string)> StringAttributeHandler;
212typedef std::function<void(NVGcolor)> ColorAttributeHandler;
213typedef std::function<void(bool)> BoolAttributeHandler;
214typedef std::function<void(std::string)> FilePathAttributeHandler;
215
220float ntz(float value);
221
231class View
232{
233 private:
235
236 void drawBackground(NVGcontext* vg, FrameContext* ctx, Style style, Rect frame);
237 void drawShadow(NVGcontext* vg, FrameContext* ctx, Style style, Rect frame);
238 void drawThemeUnderlay(FrameContext* ctx, const Rect& frame);
239 void drawThemeBackdrop(FrameContext* ctx, const Rect& frame);
240 void drawBorder(NVGcontext* vg, FrameContext* ctx, Style style, Rect frame);
241 void drawHighlight(NVGcontext* vg, Theme theme, float alpha, Style style, bool background);
242 void drawClickAnimation(NVGcontext* vg, FrameContext* ctx, Rect frame);
243 void drawWireframe(FrameContext* ctx, Rect frame);
244 void drawLine(FrameContext* ctx, Rect frame);
245
246 Animatable highlightAlpha = 0.0f;
247 float highlightPadding = 0.0f;
248 float highlightCornerRadius = 0.0f;
249
250 Animatable clickAlpha = 0.0f;
251
252 bool highlightShaking = false;
253 Time highlightShakeStart;
254 FocusDirection highlightShakeDirection;
255 float highlightShakeAmplitude;
256
257 bool fadeIn = false;
258 bool inFadeAnimation = false;
259
260 Theme* themeOverride = nullptr;
261
262 bool hidden = false;
263 bool focusable = false;
264
265 enum Sound focusSound = SOUND_FOCUS_CHANGE;
266
267 bool hideHighlightBackground = false;
268 bool hideHighlightBorder = false;
269 bool hideHighlight = false;
270 bool hideClickAnimation = false;
271
272 bool detached = false;
273 Point detachedOrigin;
274
275 Point translation;
276
277 bool wireframeEnabled = false;
278 bool clipsToBounds = false;
279 float scaleX = 1.0f;
280 float scaleY = 1.0f;
281
282 void applyScale(NVGcontext* vg, const Rect& frame);
283
284 std::vector<std::shared_ptr<Action>> actions;
285 std::vector<GestureRecognizer*> gestureRecognizers;
286
291 void* parentUserdata = nullptr;
292
293 bool culled = true;
294
295 float aspectRatio = 0;
296
297 std::unordered_map<std::string, AutoAttributeHandler> autoAttributes;
298 std::unordered_map<std::string, FloatAttributeHandler> percentageAttributes;
299 std::unordered_map<std::string, FloatAttributeHandler> floatAttributes;
300 std::unordered_map<std::string, StringAttributeHandler> stringAttributes;
301 std::unordered_map<std::string, ColorAttributeHandler> colorAttributes;
302 std::unordered_map<std::string, BoolAttributeHandler> boolAttributes;
303 std::unordered_map<std::string, FilePathAttributeHandler> filePathAttributes;
304
305 std::set<std::string> knownAttributes;
306
307 void registerCommonAttributes();
308
314 void ensureCommonAttributes();
315 bool commonAttributesRegistered = false;
316 bool registeringCommonAttributes = false;
317 void printXMLAttributeErrorMessage(tinyxml2::XMLElement* element, std::string name, std::string value);
318
319 unsigned maximumAllowedXMLElements = UINT_MAX;
320
321 NVGcolor lineColor = TRANSPARENT;
322 float lineTop = 0;
323 float lineRight = 0;
324 float lineBottom = 0;
325 float lineLeft = 0;
326
327 Visibility visibility = Visibility::VISIBLE;
328
329 NVGcolor backgroundColor = TRANSPARENT;
330
332 NVGcolor backgroundStartColor = TRANSPARENT;
333 NVGcolor backgroundEndColor = nvgRGBA(0, 0, 0, 200);
335 std::vector<float> backgroundRadius { 0.0f, 0.0f, 0.0f, 0.0f };
336
337 NVGcolor borderColor = TRANSPARENT;
338 float borderThickness = 0.0f;
339 float cornerRadius = 0.0f;
340 std::array<float, 4> cornerRadii = { 0.0f, 0.0f, 0.0f, 0.0f }; // TL, TR, BR, BL
341 ShadowType shadowType = ShadowType::NONE;
342 bool showShadow = true;
343 ThemeArea themeArea = ThemeArea::NONE;
344
345 std::unordered_map<FocusDirection, std::string> customFocusById;
346 std::unordered_map<FocusDirection, View*> customFocusByPtr;
347
348 AppletFrameItem appletFrameItem;
349
350 int ptrLockCounter = 0;
351
352 protected:
354
355 bool focused = false;
356
358 Box* parent = nullptr;
359
362
363 YGNode* ygNode;
364
365 std::string id = "";
366
368 NVGcolor a(NVGcolor color);
369 NVGpaint a(NVGpaint paint);
370
371 NVGcolor RGB(unsigned r, unsigned g, unsigned b)
372 {
373 return this->a(nvgRGB(r, g, b));
374 }
375
376 NVGcolor RGBA(unsigned r, unsigned g, unsigned b, unsigned a)
377 {
378 return this->a(nvgRGBA(r, g, b, a));
379 }
380
381 NVGcolor RGBf(float r, float g, float b)
382 {
383 return this->a(nvgRGBf(r, g, b));
384 }
385
386 NVGcolor RGBAf(float r, float g, float b, float a)
387 {
388 return this->a(nvgRGBAf(r, g, b, a));
389 }
390
391 NVGcolor shadowColor(NVGcolor color, float opacity);
392
397 virtual bool animateHint()
398 {
399 return false;
400 }
401
402 public:
407 static void setHighlightGlide(bool glide);
408
415 void setScale(float scale);
416 void setScaleX(float scale);
417 void setScaleY(float scale);
418 float getScaleX() const { return scaleX; }
419 float getScaleY() const { return scaleY; }
420
422 static constexpr float AUTO = NAN;
423
427 inline static std::string CUSTOM_RESOURCES_PATH;
428
430 virtual ~View();
431
434
439 void setBackgroundLinearGradient(NVGcolor start, NVGcolor end, ViewBackground direction = ViewBackground::VERTICAL_LINEAR);
440
443
447 float getX();
448 float getY();
449
452 float getLocalX();
453 float getLocalY();
454
456 float getWidth();
457 float getHeight(bool includeCollapse = true);
458
466 virtual void invalidate();
467
471 virtual void onLayout() {};
472
480 virtual View* getView(std::string id);
481
482 // -----------------------------------------------------------
483 // Flex layout properties
484 // -----------------------------------------------------------
485
493 void setWidth(float width);
494
502 void setHeight(float height);
503
511 void setSize(Size size);
512
518 void setDimensions(float width, float height);
519
524 void setWidthPercentage(float percentage);
525
530 void setHeightPercentage(float percentage);
531
540 void setMinWidth(float minWidth);
541
550 void setMinHeight(float minHeight);
551
560 void setMinWidthPercentage(float percentage);
561
570 void setMinHeightPercentage(float percentage);
571
580 void setMaxWidth(float maxWidth);
581
590 void setMaxHeight(float maxHeight);
591
600 void setMaxWidthPercentage(float percentage);
601
610 void setMaxHeightPercentage(float percentage);
611
618 void setGrow(float grow);
619
626 void setShrink(float shrink);
627
640 void setMargins(float top, float right, float bottom, float left);
641
652 void setMarginTop(float top);
653
664 void setMarginRight(float right);
665
668
679 void setMarginBottom(float right);
680
691 void setMarginLeft(float left);
692
696 void setVisibility(Visibility visibility);
697
702
717 void setPositionTop(float pos);
718
733 void setPositionRight(float pos);
734
749 void setPositionBottom(float pos);
750
765 void setPositionLeft(float pos);
766
773 void setPositionTopPercentage(float percentage);
774
781 void setPositionRightPercentage(float percentage);
782
789 void setPositionBottomPercentage(float percentage);
790
797 void setPositionLeftPercentage(float percentage);
798
806
810 void setId(std::string id);
811
815 const std::string& getId() const
816 {
817 return this->id;
818 }
819
826
833
834 // -----------------------------------------------------------
835 // Styling and view shape properties
836 // -----------------------------------------------------------
837
844 inline void setLineColor(NVGcolor color)
845 {
846 if (this->transitionStyle("lineColor", StyleValue::of(color)))
847 return;
848 this->lineColor = color;
849 }
850
857 inline void setLineTop(float thickness)
858 {
859 this->lineTop = thickness;
860 }
861
868 inline void setLineRight(float thickness)
869 {
870 this->lineRight = thickness;
871 }
872
879 inline void setLineBottom(float thickness)
880 {
881 this->lineBottom = thickness;
882 }
883
890 inline void setLineLeft(float thickness)
891 {
892 this->lineLeft = thickness;
893 }
894
898 inline void setBackgroundColor(NVGcolor color)
899 {
900 if (this->transitionStyle("backgroundColor", StyleValue::of(color)))
901 return;
902 this->backgroundColor = color;
904 }
905
909 inline void setBorderColor(NVGcolor color)
910 {
911 if (this->transitionStyle("borderColor", StyleValue::of(color)))
912 return;
913 this->borderColor = color;
914 }
915
916 ViewBackground getBackground() const { return this->background; }
917 NVGcolor getBackgroundColor() const { return this->backgroundColor; }
918 NVGcolor getBorderColor() const { return this->borderColor; }
919
923 inline void setBorderThickness(float thickness)
924 {
925 if (this->transitionStyle("borderThickness", StyleValue::of(thickness)))
926 return;
927 this->borderThickness = thickness;
928 }
929
930 inline float getBorderThickness()
931 {
932 return this->borderThickness;
933 }
934
939 inline void setCornerRadius(float radius)
940 {
941 if (this->transitionStyle("cornerRadius", StyleValue::of(radius)))
942 return;
943 this->cornerRadius = radius;
944 this->cornerRadii[0] = radius;
945 this->cornerRadii[1] = radius;
946 this->cornerRadii[2] = radius;
947 this->cornerRadii[3] = radius;
948 }
949
954 inline void setCornerRadius(float topLeft, float topRight, float bottomRight, float bottomLeft)
955 {
956 this->cornerRadii[0] = topLeft;
957 this->cornerRadii[1] = topRight;
958 this->cornerRadii[2] = bottomRight;
959 this->cornerRadii[3] = bottomLeft;
960 this->cornerRadius = (topLeft == topRight && topRight == bottomRight && bottomRight == bottomLeft) ? topLeft : 0.0f;
961 }
962
963 inline float getCornerRadius()
964 {
965 return this->cornerRadius;
966 }
967
979 void setThemeArea(ThemeArea area) { this->themeArea = area; }
980 ThemeArea getThemeArea() const { return this->themeArea; }
981
986 inline void setShadowType(ShadowType type)
987 {
988 this->shadowType = type;
989 }
990
994 inline void setShadowVisibility(bool visible)
995 {
996 this->showShadow = visible;
997 }
998
1004 {
1005 this->hideHighlightBackground = hide;
1006 }
1007
1012 {
1013 this->hideHighlightBorder = hide;
1014 }
1015
1019 inline void setHideHighlight(bool hide)
1020 {
1021 this->hideHighlight = hide;
1022 }
1023
1025 inline void setHideClickAnimation(bool hide)
1026 {
1027 this->hideClickAnimation = hide;
1028 }
1029
1034 inline void setHighlightPadding(float padding)
1035 {
1036 this->highlightPadding = padding;
1037 }
1038
1042 inline void setHighlightCornerRadius(float radius)
1043 {
1044 this->highlightCornerRadius = radius;
1045 }
1046
1047 // -----------------------------------------------------------
1048
1057 virtual View* getNearestView(std::string id);
1058
1068 static View* createFromXMLString(std::string_view xml);
1069
1082 static View* createFromXMLElement(tinyxml2::XMLElement* element);
1083
1093 static View* createFromXMLFile(std::string path);
1094
1104 static View* createFromXMLResource(std::string name);
1105
1115 virtual void handleXMLElement(tinyxml2::XMLElement* element);
1116
1123 virtual void applyXMLAttributes(tinyxml2::XMLElement* element);
1124
1131 virtual bool applyXMLAttribute(std::string name, std::string value);
1132
1140 void registerAutoXMLAttribute(std::string name, AutoAttributeHandler handler);
1141
1151
1159 void registerFloatXMLAttribute(std::string name, FloatAttributeHandler handler);
1160
1171
1180 void registerColorXMLAttribute(std::string name, ColorAttributeHandler handler);
1181
1189 void registerBoolXMLAttribute(std::string name, BoolAttributeHandler handler);
1190
1199
1203 static std::shared_ptr<tinyxml2::XMLDocument> getXMLCache(std::string_view path);
1204
1210 static void forgetXMLCache(const std::string& path);
1211
1215 bool isXMLAttributeValid(std::string attributeName);
1216
1222 static std::string describeXMLError(tinyxml2::XMLDocument* document, const std::string& source = "");
1223
1228 static std::string currentXMLResource;
1229
1234 static std::string describeXMLLocation(const tinyxml2::XMLElement* element);
1235
1240 [[noreturn]] static void fatalXML(const std::string& message);
1241
1245 static std::string closestXMLName(const std::string& name, const std::vector<std::string>& known);
1246
1248 template <typename T>
1249 static std::string listXMLValues(const std::unordered_map<std::string, T>& values)
1250 {
1251 std::vector<std::string> names;
1252 for (const auto& entry : values)
1253 names.push_back(entry.first);
1254 std::sort(names.begin(), names.end());
1255 std::string list;
1256 for (const std::string& name : names)
1257 list += (list.empty() ? "" : ", ") + name;
1258 return list;
1259 }
1260
1266
1268
1272 void setInFadeAnimation(bool translucent);
1273
1280 inline void setFocusable(bool focusable)
1281 {
1282 this->focusable = focusable;
1283 }
1284
1287
1291 void removeFromSuperView(bool free = true);
1292
1296 inline void setFocusSound(enum Sound sound)
1297 {
1298 this->focusSound = sound;
1299 }
1300
1301 virtual enum Sound getFocusSound();
1302
1313 void detach();
1314
1317
1321 void setDetachedPosition(float x, float y);
1322
1327
1332
1337 {
1338 return detachedOrigin;
1339 }
1340
1342 void setParent(Box* parent, void* parentUserdata = nullptr);
1345
1347
1348 typedef std::vector<std::shared_ptr<Action>>::iterator ActionIterator;
1349
1350 template <class ButtonType>
1351 ActionIterator getAction(ButtonType button);
1352
1355
1368 template <class ButtonType, class ActionType>
1369 ActionIdentifier registerAction(const std::string& hintText, ButtonType button, const ActionListener& actionListener, bool hidden = false, bool allowRepeating = false, enum Sound sound = SOUND_NONE);
1370
1372 ActionIdentifier registerAction(const std::string& hintText, ControllerButton button, const ActionListener& actionListener, bool hidden = false, bool allowRepeating = false, enum Sound sound = SOUND_NONE);
1373
1375 ActionIdentifier registerAction(AuroreKeyCombination key, const ActionListener& actionListener, bool allowRepeating = false);
1376
1378
1383
1387 void registerClickAction(const ActionListener& actionListener);
1388
1390 void updateActionHint(enum ControllerButton button, const std::string& hintText);
1392 void setActionAvailable(enum ControllerButton button, bool available);
1394 void setActionsAvailable(bool available) const;
1395
1400 void setActionHidden(enum ControllerButton button, bool hidden);
1401
1404 void playClickAnimation(bool reverse = false, bool animateBack = true, bool force = false);
1405
1407 std::string getClassString() const;
1408
1410 std::string describe() const;
1411
1413 YGNode* getYGNode();
1414
1416 const std::vector<std::shared_ptr<Action>>& getActions();
1417
1421 const std::vector<GestureRecognizer*>& getGestureRecognizers();
1422
1428 void interruptGestures(bool onlyIfUnsureState);
1429
1434
1441
1448
1454 virtual void frame(FrameContext* ctx);
1455
1460
1466 virtual void draw(NVGcontext* vg, float x, float y, float width, float height, Style style, FrameContext* ctx) = 0;
1467
1475 virtual void willAppear(bool resetState = false)
1476 {
1477 // Nothing to do
1478 }
1479
1487 virtual void willDisappear(bool resetState = false)
1488 {
1489 // Nothing to do
1490 }
1491
1496 virtual void onShowAnimationEnd() {};
1497
1501 virtual void show(std::function<void(void)> cb);
1502
1506 virtual void show(std::function<void(void)> cb, bool animate, float animationDuration);
1507
1512
1516 void collapse(bool animated = true);
1517
1520
1522 void setAlpha(float alpha);
1523
1528 void expand(bool animated = true);
1529
1533 virtual void hide(std::function<void(void)> cb);
1534
1538 virtual void hide(std::function<void(void)> cb, bool animate, float animationDuration);
1539
1541 bool isHidden();
1542
1550 virtual bool isTranslucent();
1551
1554
1572
1580 virtual View* hitTest(Point point);
1581
1590 virtual View* getNextFocus(FocusDirection direction, View* currentView);
1591
1596
1604 void setCustomNavigationRoute(FocusDirection direction, std::string targetId);
1605
1608
1611
1615 virtual void onFocusGained();
1616
1620 virtual void onFocusLost();
1621
1625 virtual void onParentFocusGained(View* focusedView);
1626
1631 virtual void onParentFocusLost(View* focusedView);
1632
1637 virtual void onWindowSizeChanged()
1638 {
1639 // Nothing by default
1640 }
1641
1646
1648
1650 virtual float getAlpha(bool child = false);
1651
1652 float getClickAlpha() { return this->clickAlpha; }
1653
1658 void overrideTheme(Theme* newTheme);
1659
1666 void setCulled(bool culled)
1667 {
1668 this->culled = culled;
1669 }
1670
1672 {
1673 return this->culled;
1674 }
1675
1677 void setAspectRatio(float value);
1678
1680
1684 void setBackgroundCornerRadii(float topLeft, float topRight, float bottomRight, float bottomLeft)
1685 {
1686 this->backgroundRadius = { topLeft, topRight, bottomRight, bottomLeft };
1687 }
1688
1695 void setTranslationY(float translateY);
1696
1703 void setTranslationX(float translateX);
1704
1711 void setWireframeEnabled(bool wireframe);
1712
1714
1720 static std::string getStringXMLAttributeValue(std::string value);
1721
1727 static std::string getFilePathXMLAttributeValue(std::string value);
1728
1730 {
1731 return &this->appletFrameItem;
1732 }
1733
1735
1737 bool getClipsToBounds() const
1738 {
1739 return clipsToBounds;
1740 }
1741
1742 void setClipsToBounds(bool value)
1743 {
1744 clipsToBounds = value;
1745 }
1746
1749
1751 void present(View* view);
1753 virtual void dismiss(std::function<void(void)> cb = [] {});
1754
1771 std::weak_ptr<void> aliveToken();
1774 void ptrLock();
1779 void freeView();
1780
1784
1785 // -----------------------------------------------------------
1786 // State styles, transitions, bindings, accessibility
1787 // (docs/styles.md). Nothing is kept for a view that uses none.
1788 // -----------------------------------------------------------
1789
1799 bool setStateStyle(StyleState state, const std::string& property, const std::string& value);
1800
1806 void setStyleState(StyleState state, bool on);
1808
1819 bool setTransition(const std::string& spec);
1820
1829 virtual bool getStyleProperty(const std::string& name, StyleValue* value);
1830 virtual bool setStyleProperty(const std::string& name, const StyleValue& value);
1831
1836 void keepSubscription(Subscription&& subscription);
1837
1848 bool bind(const std::string& spec);
1849
1853 virtual bool setBoundText(const std::string& text) { return false; }
1854
1864 void setAccessibilityLabel(const std::string& label);
1866
1872 void setAccessibilityValue(const std::string& value);
1874
1879 void setAccessibilitySelected(bool selected);
1881
1888 virtual bool getAccessibilityPosition(int* index, int* count);
1889
1895 virtual std::string getAccessibilityDescription();
1896
1904
1912
1918 void resolveBindings(Activity* activity = nullptr);
1919
1925 virtual void onTextScaleChanged() { }
1926
1936 bool setThemeColor(const std::string& property, const std::string& key);
1937
1941 std::string getThemeColor(const std::string& property);
1942
1951 virtual void onThemeChanged();
1952
1953 protected:
1958 virtual std::string getDefaultAccessibilityLabel() { return ""; }
1959 virtual std::string getDefaultAccessibilityValue() { return ""; }
1960 virtual bool getDefaultAccessibilitySelected() { return false; }
1961
1967 bool transitionStyle(const char* name, const StyleValue& to)
1968 {
1969 return this->extras && this->startTransition(name, to);
1970 }
1971
1972 private:
1973 friend class Application;
1974 std::shared_ptr<void> alive;
1975 struct Extras;
1976 struct ExtrasDeleter
1977 {
1978 void operator()(Extras* extras) const;
1979 };
1980 std::unique_ptr<Extras, ExtrasDeleter> extras;
1981 Extras& getExtras();
1984 void noteStyleState(StyleState state, bool on);
1985 void notePress(bool pressed, bool releaseLater);
1986 void applyPendingStyles();
1987 bool hasStateStyle(StyleState state);
1988 bool startTransition(const char* name, const StyleValue& to);
1989 void updateStateStyles();
1990 bool bindOne(const std::string& property, const std::string& path, Activity* activity);
1991 static bool parseStyleValue(const std::string& text, StyleValue::Type type, StyleValue* value);
1992 static unsigned pendingBindings;
1993
1996 struct ThemeColor
1997 {
1998 std::string property;
1999 std::string key;
2000 NVGcolor applied;
2001 };
2002 std::unique_ptr<std::vector<ThemeColor>> themeColors;
2003};
2004
2005} // namespace aurore
Definition activity.hpp:45
Definition animation.hpp:42
Definition applet_frame.hpp:39
Definition application.hpp:68
Generic FlexBox layout.
Definition box.hpp:74
Definition event.hpp:41
Definition frame_context.hpp:30
Definition gesture.hpp:68
Simple wrapper around StyleValues for the array operator.
Definition style.hpp:115
Definition observable.hpp:37
Definition theme.hpp:298
Definition view.hpp:232
static View * createFromXMLResource(std::string name)
void setAccessibilityValue(const std::string &value)
void setScaleY(float scale)
float getLocalX()
void setAccessibilityLabel(const std::string &label)
ThemeArea getThemeArea() const
Definition view.hpp:980
void setFocusable(bool focusable)
Definition view.hpp:1280
void setWireframeEnabled(bool wireframe)
virtual View * getView(std::string id)
float getScaleX() const
Definition view.hpp:418
NVGcolor getBorderColor() const
Definition view.hpp:918
virtual bool animateHint()
Definition view.hpp:397
void overrideTheme(Theme *newTheme)
bool setThemeColor(const std::string &property, const std::string &key)
void setBackgroundColor(NVGcolor color)
Definition view.hpp:898
bool hasCustomNavigationRouteByPtr(FocusDirection direction)
virtual float getAlpha(bool child=false)
The opacity drawn: the view's alpha times its parents'.
void setAlpha(float alpha)
The view's opacity, 0 to 1 (a transition when its style has one).
static std::string closestXMLName(const std::string &name, const std::vector< std::string > &known)
void setCustomNavigationRoute(FocusDirection direction, View *target)
void setCustomNavigationRoute(FocusDirection direction, std::string targetId)
bool bind(const std::string &spec)
bool setStateStyle(StyleState state, const std::string &property, const std::string &value)
void registerStringXMLAttribute(std::string name, StringAttributeHandler handler)
void setHeight(float height)
void setParent(Box *parent, void *parentUserdata=nullptr)
The box this view is in (Box::addView sets it; parentUserdata is the box's own).
void setDetachedPositionY(float y)
AccessibilityRole getAccessibilityRole()
See setAccessibilityRole().
void announceAccessibilityValue()
void setSize(Size size)
void setPositionRight(float pos)
unsigned getMaximumAllowedXMLElements()
const std::vector< GestureRecognizer * > & getGestureRecognizers()
void interruptGestures(bool onlyIfUnsureState)
virtual void onWindowSizeChanged()
Definition view.hpp:1637
static View * createFromXMLString(std::string_view xml)
virtual void frame(FrameContext *ctx)
void setPositionRightPercentage(float percentage)
const std::string & getId() const
Definition view.hpp:815
static std::shared_ptr< tinyxml2::XMLDocument > getXMLCache(std::string_view path)
float getBorderThickness()
Definition view.hpp:930
Animatable alpha
Definition view.hpp:1647
static constexpr float AUTO
A size or position left to the layout (auto in XML).
Definition view.hpp:422
void setBorderColor(NVGcolor color)
Definition view.hpp:909
static View * createFromXMLFile(std::string path)
void setPositionBottomPercentage(float percentage)
bool isAccessibilitySelected()
std::string getThemeColor(const std::string &property)
void frameHighlight(FrameContext *ctx)
void playClickAnimation(bool reverse=false, bool animateBack=true, bool force=false)
Plays the click animation (the flash over the view).
void setClipsToBounds(bool value)
Definition view.hpp:1742
float getHeight(bool includeCollapse=true)
ActionIdentifier registerAction(const std::string &hintText, ButtonType button, const ActionListener &actionListener, bool hidden=false, bool allowRepeating=false, enum Sound sound=SOUND_NONE)
bool hasStyleState(StyleState state)
bool isHidden()
Whether hide() hid the view.
virtual void draw(NVGcontext *vg, float x, float y, float width, float height, Style style, FrameContext *ctx)=0
virtual std::string getAccessibilityDescription()
void expand(bool animated=true)
NVGcolor getBackgroundColor() const
Definition view.hpp:917
static std::string describeXMLLocation(const tinyxml2::XMLElement *element)
void setDimensions(float width, float height)
virtual bool getAccessibilityPosition(int *index, int *count)
static std::string currentXMLResource
Definition view.hpp:1228
Box * parent
Definition view.hpp:358
float getScaleY() const
Definition view.hpp:419
virtual void onParentFocusGained(View *focusedView)
void setPositionLeftPercentage(float percentage)
void setCornerRadius(float topLeft, float topRight, float bottomRight, float bottomLeft)
Definition view.hpp:954
void setAlignSelf(AlignSelf align)
Animatable collapseState
Definition view.hpp:353
void setBoxSizing(BoxSizing sizing)
void setMaximumAllowedXMLElements(unsigned max)
virtual View * getNextFocus(FocusDirection direction, View *currentView)
void setShrink(float shrink)
ActionIterator getAction(ActionIdentifier identifier)
The action registered under identifier, or getActions().end().
void setMinWidthPercentage(float percentage)
virtual void handleXMLElement(tinyxml2::XMLElement *element)
void setMaxHeight(float maxHeight)
void registerClickAction(const ActionListener &actionListener)
void setPositionLeft(float pos)
Activity * getParentActivity()
The activity the view is in, through its parents; nullptr when none.
bool isFocused()
Whether the view has the focus.
bool isDetached()
See detach().
virtual void onThemeChanged()
Box * getParent()
bool getClipsToBounds() const
Whether the children are clipped to the view's frame when drawn.
Definition view.hpp:1737
bool transitionStyle(const char *name, const StyleValue &to)
Definition view.hpp:1967
Rect getFrame()
The view's position and size on the screen, after layout (getX(), getY(), getWidth(),...
static std::string listXMLValues(const std::unordered_map< std::string, T > &values)
An enumeration's values, sorted, for an error message.
Definition view.hpp:1249
virtual View * getNearestView(std::string id)
void ptrUnlock()
void setMinHeight(float minHeight)
void setActionHidden(enum ControllerButton button, bool hidden)
void setHighlightPadding(float padding)
Definition view.hpp:1034
void setBackgroundCornerRadii(float topLeft, float topRight, float bottomRight, float bottomLeft)
Definition view.hpp:1684
void resolveBindings(Activity *activity=nullptr)
ViewBackground getBackground() const
Definition view.hpp:916
virtual void onFocusGained()
NVGpaint a(NVGpaint paint)
void setHideHighlightBackground(bool hide)
Definition view.hpp:1003
NVGcolor a(NVGcolor color)
Helper functions to apply this view's alpha to a color.
void setPositionType(PositionType type)
bool setTransition(const std::string &spec)
void setHideClickAnimation(bool hide)
No click animation when the view is clicked.
Definition view.hpp:1025
void keepSubscription(Subscription &&subscription)
void setInFadeAnimation(bool translucent)
virtual View * getDefaultFocus()
ActionIdentifier registerAction(AuroreKeyCombination key, const ActionListener &actionListener, bool allowRepeating=false)
An action on a keyboard key (a combination with modifiers): no hint, no sound.
std::weak_ptr< void > aliveToken()
std::string id
Definition view.hpp:365
void setThemeArea(ThemeArea area)
Definition view.hpp:979
bool isCulled()
Definition view.hpp:1671
void setActionAvailable(enum ControllerButton button, bool available)
Turns the action on button on or off (an action off runs nothing and shows no hint).
virtual bool applyXMLAttribute(std::string name, std::string value)
float getX()
The position on the screen, in layout units: the parents' positions and translations added.
void ptrLock()
NVGcolor shadowColor(NVGcolor color, float opacity)
virtual bool setStyleProperty(const std::string &name, const StyleValue &value)
void setPositionTopPercentage(float percentage)
Activity * parentActivity
Definition view.hpp:357
bool isPtrLocked()
Whether a ptrLock() holds the view.
void setMarginLeft(float left)
void setActionsAvailable(bool available) const
The same for every action of the view.
virtual bool getDefaultAccessibilitySelected()
Definition view.hpp:1960
virtual void hide(std::function< void(void)> cb, bool animate, float animationDuration)
void setStyleState(StyleState state, bool on)
void removeFromSuperView(bool free=true)
bool isFocusable()
Whether the view takes the focus: focusable, and visible.
static std::string getFilePathXMLAttributeValue(std::string value)
void setMinHeightPercentage(float percentage)
Sound gestureRecognizerRequest(TouchState touch, MouseState mouse, View *firstResponder)
void setHideHighlight(bool hide)
Definition view.hpp:1019
void setBackgroundLinearGradient(NVGcolor start, NVGcolor end, ViewBackground direction=ViewBackground::VERTICAL_LINEAR)
virtual float getShowAnimationDuration(TransitionAnimation animation)
void shakeHighlight(FocusDirection direction)
Shakes the focus highlight towards direction: there is nothing to go to there.
std::string describe() const
The class name and the id, for logs: Label (id="title").
void setMarginBottom(float right)
virtual void show(std::function< void(void)> cb)
float getClickAlpha()
Definition view.hpp:1652
void * getParentUserData()
ActionIdentifier registerAction(const std::string &hintText, ControllerButton button, const ActionListener &actionListener, bool hidden=false, bool allowRepeating=false, enum Sound sound=SOUND_NONE)
The same, on a controller button.
virtual void dismiss(std::function< void(void)> cb=[] {})
Pops the AppletFrame's content back to the one before, then runs cb.
virtual std::string getDefaultAccessibilityValue()
Definition view.hpp:1959
virtual void onTextScaleChanged()
Definition view.hpp:1925
void setBackground(ViewBackground background)
How the view's background is drawn: none, the sidebar's, the backdrop, a plain colour or a gradient.
void setGrow(float grow)
void setWidth(float width)
bool isXMLAttributeValid(std::string attributeName)
void setHideHighlightBorder(bool hide)
Definition view.hpp:1011
void setBorderThickness(float thickness)
Definition view.hpp:923
void setDetachedPositionX(float x)
void setAccessibilitySelected(bool selected)
void setMaxHeightPercentage(float percentage)
void setLineTop(float thickness)
Definition view.hpp:857
static void setHighlightGlide(bool glide)
std::string getCustomNavigationRouteId(FocusDirection direction)
NVGcolor RGBf(float r, float g, float b)
Definition view.hpp:381
virtual void onParentFocusLost(View *focusedView)
void setHighlightCornerRadius(float radius)
Definition view.hpp:1042
void setCulled(bool culled)
Definition view.hpp:1666
static std::string CUSTOM_RESOURCES_PATH
Definition view.hpp:427
virtual std::string getDefaultAccessibilityLabel()
Definition view.hpp:1958
virtual enum Sound getFocusSound()
ActionIterator getAction(ButtonType button)
void setLineBottom(float thickness)
Definition view.hpp:879
virtual void onShowAnimationEnd()
Definition view.hpp:1496
virtual void applyXMLAttributes(tinyxml2::XMLElement *element)
void registerBoolXMLAttribute(std::string name, BoolAttributeHandler handler)
virtual bool setBoundText(const std::string &text)
Definition view.hpp:1853
void setMaxWidthPercentage(float percentage)
std::vector< std::shared_ptr< Action > >::iterator ActionIterator
Definition view.hpp:1348
virtual void onLayout()
Definition view.hpp:471
GenericEvent focusEvent
Definition view.hpp:360
void updateActionHint(enum ControllerButton button, const std::string &hintText)
Changes the hint of the action on button.
float getY()
void setFocusSound(enum Sound sound)
Definition view.hpp:1296
void present(View *view)
Pushes view as the content of the view's AppletFrame (a page inside the frame).
bool hasCustomNavigationRouteById(FocusDirection direction)
std::string getAccessibilityLabel()
void setTranslationY(float translateY)
void setMarginRight(float right)
void setScale(float scale)
void setMaxWidth(float maxWidth)
void registerFilePathXMLAttribute(std::string name, FilePathAttributeHandler handler)
void registerAutoXMLAttribute(std::string name, AutoAttributeHandler handler)
void setParentActivity(Activity *activity)
void registerColorXMLAttribute(std::string name, ColorAttributeHandler handler)
void setShadowVisibility(bool visible)
Definition view.hpp:994
const std::vector< std::shared_ptr< Action > > & getActions()
The actions registered on the view.
void setLineColor(NVGcolor color)
Definition view.hpp:844
virtual void show(std::function< void(void)> cb, bool animate, float animationDuration)
void freeView()
Deletes the view at the end of the frame (Application::addToFreeQueue).
std::string getClassString() const
The view's class name ("Label", "Box"…).
void setPositionTop(float pos)
GenericEvent focusLostEvent
Definition view.hpp:361
void setScaleX(float scale)
void collapse(bool animated=true)
float getWidth()
The size as laid out by Yoga; the height without the collapse when includeCollapse is false.
virtual void hide(std::function< void(void)> cb)
NVGcolor RGBA(unsigned r, unsigned g, unsigned b, unsigned a)
Definition view.hpp:376
void resetClickAnimation()
virtual ~View()
std::string getAccessibilityValue()
AppletFrameItem * getAppletFrameItem()
Definition view.hpp:1729
void setAspectRatio(float value)
The width over the height, kept by the layout (values <= 0 are ignored).
static std::string describeXMLError(tinyxml2::XMLDocument *document, const std::string &source="")
void setVisibility(Visibility visibility)
std::string getAccessibilityText()
virtual void invalidate()
void setMinWidth(float minWidth)
void setShadowType(ShadowType type)
Definition view.hpp:986
View * getCustomNavigationRoutePtr(FocusDirection direction)
virtual void willDisappear(bool resetState=false)
Definition view.hpp:1487
float getCornerRadius()
Definition view.hpp:963
void updateAppletFrameItem()
static void forgetXMLCache(const std::string &path)
void setMarginTop(float top)
static std::string getStringXMLAttributeValue(std::string value)
virtual bool getStyleProperty(const std::string &name, StyleValue *value)
bool focused
Definition view.hpp:355
float getMarginLeft()
bool isWireframeEnabled()
bool removeGestureRecognizer(GestureRecognizer *recognizer)
virtual AccessibilityRole getDefaultAccessibilityRole()
Definition view.hpp:1957
void setMargins(float top, float right, float bottom, float left)
Rect getLocalFrame()
The position and size in the parent, as laid out by Yoga.
virtual bool isTranslucent()
virtual void onFocusLost()
virtual View * hitTest(Point point)
bool isCollapsed()
Whether collapse() hid the view.
bool hasParent()
float getMarginRight()
void func(AuroreKeyCombination key)
void setCornerRadius(float radius)
Definition view.hpp:939
NVGcolor RGB(unsigned r, unsigned g, unsigned b)
Definition view.hpp:371
void addGestureRecognizer(GestureRecognizer *recognizer)
void setWidthPercentage(float percentage)
GenericEvent * getFocusEvent()
Fired with the view when it gains the focus.
Visibility getVisibility()
void setId(std::string id)
virtual void willAppear(bool resetState=false)
Definition view.hpp:1475
void setPositionBottom(float pos)
void setAccessibilityRole(AccessibilityRole role)
void registerPercentageXMLAttribute(std::string name, FloatAttributeHandler handler)
float getAspectRatio()
void setLineLeft(float thickness)
Definition view.hpp:890
static void fatalXML(const std::string &message)
virtual AppletFrame * getAppletFrame()
The AppletFrame the view is in, or nullptr.
void setLineRight(float thickness)
Definition view.hpp:868
NVGcolor RGBAf(float r, float g, float b, float a)
Definition view.hpp:386
YGNode * ygNode
Definition view.hpp:363
float getLocalY()
YGNode * getYGNode()
The view's Yoga node.
Point getDetachedPosition() const
Definition view.hpp:1336
void setHeightPercentage(float percentage)
void setDetachedPosition(float x, float y)
static View * createFromXMLElement(tinyxml2::XMLElement *element)
void setTranslationX(float translateX)
GenericEvent * getFocusLostEvent()
Fired with the view when it loses the focus.
void registerFloatXMLAttribute(std::string name, FloatAttributeHandler handler)
void unregisterAction(ActionIdentifier identifier)
Definition actions.hpp:25
std::function< void(float)> FloatAttributeHandler
Definition view.hpp:210
std::function< void(NVGcolor)> ColorAttributeHandler
Definition view.hpp:212
TransitionAnimation
Definition view.hpp:153
@ SLIDE_RIGHT
inverted SLIDE_LEFT
@ FADE
the old activity fades away and the new one fades in
@ SLIDE_LEFT
the old activity slides out to the left and the new one slides in from the right
PositionType
Position attribute behavior.
Definition view.hpp:136
@ ABSOLUTE
position attributes set the absolute coordinates of the view
@ RELATIVE
position attributes offset the view from the base layout
@ STATIC
position attributes are ignored, and absolute children are placed against an ancestor that is not sta...
AccessibilityRole
Definition view_style.hpp:78
const NVGcolor transparent
StyleState
Definition view_style.hpp:31
Visibility
View visibility.
Definition view.hpp:128
@ VISIBLE
the view is visible
@ INVISIBLE
the view is invisible but still takes some space
@ GONE
the view is invisible and doesn't take any space
int ActionIdentifier
Definition actions.hpp:31
ControllerButton
Definition input.hpp:179
ShadowType
A View shape's shadow type.
Definition view.hpp:163
@ CUSTOM
customized shadow (use the provided methods to tweak it)
@ NONE
do not draw any shadow around the shape
@ GENERIC
generic all-purpose shadow
FocusDirection
Focus direction when navigating.
Definition view.hpp:96
Event< View * > GenericEvent
Definition view.hpp:205
float ntz(float value)
std::function< void(void)> AutoAttributeHandler
Definition view.hpp:208
Event VoidEvent
Definition view.hpp:206
const NVGcolor TRANSPARENT
Definition view.hpp:77
std::function< void(bool)> BoolAttributeHandler
Definition view.hpp:213
std::function< void(std::string)> StringAttributeHandler
Definition view.hpp:211
ThemeArea
What a decoration picture is drawn in (View::setThemeArea)
Definition theme.hpp:129
@ SIDEBAR
backdrop.sidebar: the sidebar (Cadran's rail)
ViewBackground
View background.
Definition view.hpp:105
Sound
Definition audio.hpp:23
@ SOUND_NONE
Definition audio.hpp:24
@ SOUND_FOCUS_CHANGE
Definition audio.hpp:26
retro_time_t Time
Definition time.hpp:31
std::function< bool(View *)> ActionListener
Definition actions.hpp:29
void nameXMLDocument(const tinyxml2::XMLDocument *document, const std::string &name)
AlignSelf
Definition view.hpp:115
std::function< void(std::string)> FilePathAttributeHandler
Definition view.hpp:214
std::function< void(int)> IntAttributeHandler
Definition view.hpp:209
BoxSizing
What the width and height of a view measure.
Definition view.hpp:144
@ CONTENT_BOX
the content only, padding and border are added to it
@ BORDER_BOX
the whole view, padding and border included
Definition text.hpp:13
Definition view.hpp:67
Definition view.hpp:170
View * getHintView()
Definition view.hpp:189
void setIconFromFile(std::string path)
Definition view.hpp:183
std::string title
Definition view.hpp:171
std::string iconPath
Definition view.hpp:172
void setIconFromRes(std::string name)
Definition view.hpp:174
void setHintView(View *hintView)
Definition actions.hpp:36
Definition input.hpp:321
Definition geometry.hpp:26
While it lives, the XML element being read (named in View::fatalXML's errors).
Definition view.hpp:84
ReadingXMLElement(const tinyxml2::XMLElement *element)
ReadingXMLElement & operator=(const ReadingXMLElement &)=delete
ReadingXMLElement(const ReadingXMLElement &)=delete
Definition geometry.hpp:70
Definition geometry.hpp:50
Definition view_style.hpp:41
Type
Definition view_style.hpp:43
static StyleValue of(float number)
Definition view_style.hpp:53
Definition input.hpp:277