You.i Engine
YiLayoutConfig.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2020. All rights reserved.
2 #ifndef _YI_LAYOUT_CONFIG_H_
3 #define _YI_LAYOUT_CONFIG_H_
4 
5 #include "utility/YiRtti.h"
6 #include "utility/YiString.h"
7 
8 #include <glm/vec3.hpp>
9 
11 
26 {
27 public:
34  enum class Gravity
35  {
36  None,
37  Center,
38  Left,
39  Right,
40  Top,
41  Bottom,
42  Front,
43  Back,
44  TopLeft,
45  TopRight,
46  BottomLeft,
48  };
49 
55  class CubeOffset
56  {
57  public:
59  CubeOffset(float offset)
60  : start(offset)
61  , end(offset)
62  {
63  }
64  CubeOffset(const glm::vec3 &offset)
65  : start(offset)
66  , end(offset)
67  {
68  }
69  static const CubeOffset zeroInstance;
70  static CubeOffset CreateFromPropertiesOf(const IYIPropertiesSource *pSource, const CYIString &keyPrefix, const CubeOffset &defaultValue = zeroInstance);
71 
72  glm::vec3 start;
73  glm::vec3 end;
74 
75  inline glm::vec3 GetTotal() const { return start + end; }
76  inline float GetTotalX() const
77  {
78  return start.x + end.x;
79  }
80  inline float GetTotalY() const
81  {
82  return start.y + end.y;
83  }
84  inline float GetTotalZ() const
85  {
86  return start.z + end.z;
87  }
88 
89  inline float GetLeft() const
90  {
91  return start.x;
92  }
93  inline float GetRight() const
94  {
95  return end.x;
96  }
97  inline float GetTop() const
98  {
99  return start.y;
100  }
101  inline float GetBottom() const
102  {
103  return end.y;
104  }
105  inline float GetFront() const
106  {
107  return start.z;
108  }
109  inline float GetBack() const
110  {
111  return end.z;
112  }
113  };
114 
116 
125  {
126  public:
128  : minimum(-1.0f)
129  , preferred(-1.0f)
130  , maximum(-1.0f)
131  , fillParent(false)
132  , fitContent(false)
133  {
134  }
135 
136  float minimum;
137  float preferred;
138  float maximum;
141  };
142 
149  {
150  public:
152  : maintainAspectRatio(false)
153  {
154  }
156 
160 
162  };
163 
164  CYILayoutConfig();
165  virtual ~CYILayoutConfig();
166 
170  virtual std::unique_ptr<CYILayoutConfig> Clone() const;
171 
181  virtual void ConfigureFrom(const IYIPropertiesSource *pSource);
182 
189  void SetSizeConstraints(const SizeConstraints &sizeConstraints);
190 
191  inline const SizeConstraints &GetSizeConstraints() const;
192 
198  void SetMargin(const Margin &margin);
199 
200  inline const Margin &GetMargin() const;
201 
207  void SetLayoutable(bool layoutable);
208 
209  inline bool IsLayoutable() const;
210 
224  void SetItemGravity(const glm::vec3 &itemGravity);
225 
232  void SetItemGravity(Gravity itemGravity);
233 
234  inline const glm::vec3 &GetItemGravity() const;
235 
243  void SetIsBackground(bool background);
244 
245  inline bool IsBackground() const;
246 
260  static void RemoveSuffixFromNumber(CYIString &inOutNumber, CYIString &outSuffix);
261 
265  static glm::vec3 ReadGravityFrom(CYIStringView key, const IYIPropertiesSource *pSource, const glm::vec3 &defaultGravity);
266 
270  static glm::vec3 GetGravityVectorFor(Gravity gravity);
271 
272 private:
276  static void ReadSizeConstraintFrom(const IYIPropertiesSource *pSource, CYIStringView key, SizeConstraint *pConstraint);
277 
278  bool m_layoutable;
279  bool m_background;
280  SizeConstraints m_sizeConstraints;
281  Margin m_margin;
282  glm::vec3 m_itemGravity;
283 
285 };
286 
290 {
291  return m_sizeConstraints;
292 }
293 
295 {
296  return m_margin;
297 }
298 
299 inline bool CYILayoutConfig::IsLayoutable() const
300 {
301  return m_layoutable;
302 }
303 
304 inline const glm::vec3 &CYILayoutConfig::GetItemGravity() const
305 {
306  return m_itemGravity;
307 }
308 
310 {
311  return m_background;
312 }
313 
314 #endif // _YI_LAYOUT_CONFIG_H_
glm::vec3 start
Definition: YiLayoutConfig.h:72
float GetTotalY() const
Definition: YiLayoutConfig.h:80
SizeConstraint height
Definition: YiLayoutConfig.h:158
void SetMargin(const Margin &margin)
bool fitContent
Definition: YiLayoutConfig.h:140
SizeConstraints()
Definition: YiLayoutConfig.h:151
float GetBottom() const
Definition: YiLayoutConfig.h:101
A class used to hold a 3D &#39;cube offset&#39;.
Definition: YiLayoutConfig.h:55
bool maintainAspectRatio
Definition: YiLayoutConfig.h:161
float GetBack() const
Definition: YiLayoutConfig.h:109
void SetIsBackground(bool background)
Container class for Unicode strings. Conceptually, a CYIString object is a sequence of Unicode charac...
Definition: YiString.h:36
static glm::vec3 GetGravityVectorFor(Gravity gravity)
static glm::vec3 ReadGravityFrom(CYIStringView key, const IYIPropertiesSource *pSource, const glm::vec3 &defaultGravity)
float GetLeft() const
Definition: YiLayoutConfig.h:89
SizeConstraint width
Definition: YiLayoutConfig.h:157
bool IsLayoutable() const
Definition: YiLayoutConfig.h:299
Aligns the back edge of the child with the back edge of the container.
static const SizeConstraints defaultInstance
Definition: YiLayoutConfig.h:155
const SizeConstraints & GetSizeConstraints() const
Definition: YiLayoutConfig.h:289
Gravity
Definition: YiLayoutConfig.h:34
CubeOffset Margin
Definition: YiLayoutConfig.h:115
float GetTotalZ() const
Definition: YiLayoutConfig.h:84
float maximum
Definition: YiLayoutConfig.h:138
A class used to hold a size constraint for a specific dimension.
Definition: YiLayoutConfig.h:124
Aligns the top edge of the child with the top edge of the container.
bool IsBackground() const
Definition: YiLayoutConfig.h:309
Aligns the top-right corner of the child with the top-right corner of the container.
Aligns the right edge of the child with the right edge of the container.
glm::vec3 end
Definition: YiLayoutConfig.h:73
CubeOffset()
Definition: YiLayoutConfig.h:58
Centers the child in the container.
CubeOffset(float offset)
Definition: YiLayoutConfig.h:59
SizeConstraint()
Definition: YiLayoutConfig.h:127
A class used to hold node-specific layout configuration (such as, for example, Margin).
Definition: YiLayoutConfig.h:25
virtual void ConfigureFrom(const IYIPropertiesSource *pSource)
float minimum
Definition: YiLayoutConfig.h:136
Aligns the left edge of the child with the left edge of the container.
Aligns the bottom-right corner of the child with the bottom-right corner of the container.
bool fillParent
Definition: YiLayoutConfig.h:139
static void RemoveSuffixFromNumber(CYIString &inOutNumber, CYIString &outSuffix)
An interface to a class that provides key-value properties.
Definition: YiPropertiesSource.h:21
const glm::vec3 & GetItemGravity() const
Definition: YiLayoutConfig.h:304
Indicates that the existing position of the child will be retained.
void SetItemGravity(const glm::vec3 &itemGravity)
Aligns the bottom-left corner of the child with the bottom-left corner of the container.
float GetFront() const
Definition: YiLayoutConfig.h:105
A class used to hold the size constraint for each of the 3 dimensions. A flag that indicates if the w...
Definition: YiLayoutConfig.h:148
#define YI_TYPE_BASES(CLASS, BASES...)
Definition: YiRtti.h:257
Aligns the bottom edge of the child with the bottom edge of the container.
static const CubeOffset zeroInstance
Definition: YiLayoutConfig.h:69
SizeConstraint depth
Definition: YiLayoutConfig.h:159
float GetTotalX() const
Definition: YiLayoutConfig.h:76
This file contains the classes and macros used to implement RTTI in You.i Engine. ...
const Margin & GetMargin() const
Definition: YiLayoutConfig.h:294
void SetSizeConstraints(const SizeConstraints &sizeConstraints)
glm::vec3 GetTotal() const
Definition: YiLayoutConfig.h:75
Aligns the top-left corner of the child with the top-left corner of the container.
float preferred
Definition: YiLayoutConfig.h:137
virtual std::unique_ptr< CYILayoutConfig > Clone() const
Aligns the front edge of the child with the front edge of the container.
float GetRight() const
Definition: YiLayoutConfig.h:93
CubeOffset(const glm::vec3 &offset)
Definition: YiLayoutConfig.h:64
void SetLayoutable(bool layoutable)
float GetTop() const
Definition: YiLayoutConfig.h:97
virtual ~CYILayoutConfig()
A lightweight wrapper around a sequence of Unicode characters.
Definition: YiStringView.h:57