124 typedef size_policy abstract_type;
126 struct no_aspect_ratio : std::logic_error { no_aspect_ratio() :
std::logic_error(
"neogfx::size_policy::no_aspect_ratio") {} };
129 size_constraint aSizeConstraint,
130 visibility_constraint aVisibility = visibility_constraint::Consider,
131 optional_size
const& aAspectRatio = {}) :
132 iHorizontalConstraint{ aSizeConstraint },
133 iVerticalConstraint{ aSizeConstraint },
134 iVisibility{ aVisibility },
135 iAspectRatio{ aAspectRatio }
139 size_constraint aHorizontalConstraint,
140 size_constraint aVerticalConstraint,
141 visibility_constraint aVisibility = visibility_constraint::Consider,
142 optional_size
const& aAspectRatio = {}) :
143 iHorizontalConstraint{ aHorizontalConstraint },
144 iVerticalConstraint{ aVerticalConstraint },
145 iVisibility{ aVisibility },
146 iAspectRatio{ aAspectRatio }
150 bool operator==(
const size_policy& aRhs)
const
152 return iHorizontalConstraint == aRhs.iHorizontalConstraint &&
153 iVerticalConstraint == aRhs.iVerticalConstraint &&
154 iVisibility == aRhs.iVisibility &&
155 iAspectRatio == aRhs.iAspectRatio;
157 bool operator!=(
const size_policy& aRhs)
const
159 return !(*
this == aRhs);
162 size_constraint horizontal_constraint(
bool aIgnoreUniformity =
true)
const
164 if (iHorizontalConstraint != size_constraint::ExpandingUniform)
165 return iHorizontalConstraint;
166 return aIgnoreUniformity ? size_constraint::Expanding : size_constraint::ExpandingUniform;
168 size_constraint vertical_constraint(
bool aIgnoreUniformity =
true)
const
170 if (iVerticalConstraint != size_constraint::ExpandingUniform)
171 return iVerticalConstraint;
172 return aIgnoreUniformity ? size_constraint::Expanding : size_constraint::ExpandingUniform;
174 size_policy& set_constraint(size_constraint aConstraint)
176 iHorizontalConstraint = aConstraint;
177 iVerticalConstraint = aConstraint;
180 size_policy& set_horizontal_constraint(size_constraint aHorizontalConstraint)
182 iHorizontalConstraint = aHorizontalConstraint;
185 size_policy& set_vertical_constraint(size_constraint aVerticalConstraint)
187 iVerticalConstraint = aVerticalConstraint;
194 bool ignore_visibility()
const
196 return iVisibility == visibility_constraint::Ignore;
198 size_policy& set_ignore_visibility(
bool aIgnoreVisibility)
200 iVisibility = (aIgnoreVisibility ? visibility_constraint::Ignore : visibility_constraint::Consider);
203 bool maintain_aspect_ratio()
const
205 return iAspectRatio != std::nullopt;
209 if (maintain_aspect_ratio())
210 return *iAspectRatio;
211 throw no_aspect_ratio();
213 size_policy& set_aspect_ratio(optional_size
const& aAspectRatio)
215 iAspectRatio = aAspectRatio;
219 static size_policy
from_string(std::string
const& aHorizontalConstraint, std::string
const& aVerticalConstraint)
225 void to_string(std::string& aHorizontalConstraint, std::string& aVerticalConstraint)
const
237 template <
typename Elem,
typename Traits>
238 inline std::basic_ostream<Elem, Traits>&
operator<<(std::basic_ostream<Elem, Traits>& aStream,
const size_policy& aPolicy)
240 aStream <<
"{" << aPolicy.horizontal_constraint() <<
" " << aPolicy.vertical_constraint() <<
" " << aPolicy.visibility() <<
" " << (aPolicy.maintain_aspect_ratio() ? aPolicy.aspect_ratio() :
optional_size{}) <<
"}";
244 using optional_size_policy = optional<size_policy>;
246 template <
typename Elem,
typename Traits>
247 inline std::basic_ostream<Elem, Traits>&
operator<<(std::basic_ostream<Elem, Traits>& aStream,
const optional_size_policy& aPolicy)
249 if (aPolicy != std::nullopt)
250 return aStream << *aPolicy;
251 return aStream <<
"{ nullopt }";
254 class i_geometry :
public i_units_context
257 friend class layout_item;
259 virtual point origin()
const = 0;
260 virtual void reset_origin()
const = 0;
261 virtual point position()
const = 0;
262 virtual void set_position(
const point& aPosition) = 0;
263 virtual size extents()
const = 0;
264 virtual void set_extents(
const size& aExtents) = 0;
265 virtual bool has_size_policy() const noexcept = 0;
266 virtual
neogfx::size_policy size_policy() const = 0;
267 virtual
void set_size_policy(const optional_size_policy& aSizePolicy,
bool aUpdateLayout = true) = 0;
268 virtual
bool has_weight() const noexcept = 0;
269 virtual size weight() const = 0;
270 virtual
void set_weight(optional_size const& aWeight,
bool aUpdateLayout = true) = 0;
271 virtual
bool has_ideal_size() const noexcept = 0;
272 virtual
bool is_ideal_size_constrained() const noexcept = 0;
273 virtual size ideal_size(optional_size const& aAvailableSpace = {})
const = 0;
274 virtual void set_ideal_size(optional_size
const& aIdealSize,
bool aUpdateLayout =
true) = 0;
275 virtual bool has_minimum_size() const noexcept = 0;
276 virtual
bool is_minimum_size_constrained() const noexcept = 0;
277 virtual size minimum_size(optional_size const& aAvailableSpace = {})
const = 0;
278 virtual void set_minimum_size(optional_size
const& aMinimumSize,
bool aUpdateLayout =
true) = 0;
279 virtual bool has_maximum_size() const noexcept = 0;
280 virtual
bool is_maximum_size_constrained() const noexcept = 0;
281 virtual size maximum_size(optional_size const& aAvailableSpace = {})
const = 0;
282 virtual void set_maximum_size(optional_size
const& aMaximumSize,
bool aUpdateLayout =
true) = 0;
283 virtual bool has_fixed_size() const noexcept = 0;
284 virtual size fixed_size(optional_size const& aAvailableSpace = {})
const = 0;
285 virtual void set_fixed_size(optional_size
const& aFixedSize,
bool aUpdateLayout =
true) = 0;
286 virtual bool has_transformation() const noexcept = 0;
287 virtual mat33 const& transformation(
bool aCombineAncestorTransformations = false) const = 0;
288 virtual
void set_transformation(optional_mat33 const& aTransformation,
bool aUpdateLayout = true) = 0;
290 virtual
bool has_margin() const noexcept = 0;
291 virtual
neogfx::margin margin() const = 0;
292 virtual
void set_margin(optional_margin const& aMargin,
bool aUpdateLayout = true) = 0;
293 virtual
bool has_border() const noexcept = 0;
294 virtual
neogfx::border border() const = 0;
295 virtual
void set_border(optional_border const& aBorder,
bool aUpdateLayout = true) = 0;
296 virtual
bool has_padding() const noexcept = 0;
297 virtual
neogfx::padding padding() const = 0;
298 virtual
void set_padding(optional_padding const& aPadding,
bool aUpdateLayout = true) = 0;
300 virtual point unconstrained_origin() const = 0;
301 virtual point unconstrained_position() const = 0;
304 size apply_fixed_size(size const& aResult)
const
306 auto newResult = aResult;
307 if (size_policy().horizontal_constraint() == size_constraint::Fixed && has_fixed_size())
308 newResult.cx = fixed_size().cx;
309 if (size_policy().vertical_constraint() == size_constraint::Fixed && has_fixed_size())
310 newResult.cy = fixed_size().cy;
313 neogfx::size_policy effective_size_policy()
const
315 auto effectivePolicy = size_policy();
316 if (effectivePolicy.horizontal_constraint() == size_constraint::MinimumExpanding)
317 effectivePolicy.set_horizontal_constraint(has_weight() ? size_constraint::Expanding :
size_constraint::
Minimum);
318 else if (effectivePolicy.horizontal_constraint() == size_constraint::DefaultMinimumExpanding)
319 effectivePolicy.set_horizontal_constraint(has_weight() ? size_constraint::Expanding :
size_constraint::
Minimum);
320 if (effectivePolicy.vertical_constraint() == size_constraint::MinimumExpanding)
321 effectivePolicy.set_vertical_constraint(has_weight() ? size_constraint::Expanding :
size_constraint::
Minimum);
322 else if (effectivePolicy.vertical_constraint() == size_constraint::DefaultMinimumExpanding)
323 effectivePolicy.set_vertical_constraint(has_weight() ? size_constraint::Expanding :
size_constraint::
Minimum);
324 return effectivePolicy;
326 void set_size_policy(size_constraint aConstraint,
bool aUpdateLayout =
true)
328 set_size_policy(neogfx::size_policy{ aConstraint }, aUpdateLayout);
330 void set_size_policy(size_constraint aConstraint, visibility_constraint aVisibility,
bool aUpdateLayout =
true)
332 set_size_policy(neogfx::size_policy{ aConstraint, aVisibility }, aUpdateLayout);
334 void set_size_policy(size_constraint aConstraint, visibility_constraint aVisibility,
const size& aAspectRatio,
bool aUpdateLayout =
true)
336 set_size_policy(neogfx::size_policy{ aConstraint, aVisibility, aAspectRatio }, aUpdateLayout);
338 void set_size_policy(size_constraint aHorizontalConstraint, size_constraint aVerticalConstraint,
bool aUpdateLayout =
true)
340 set_size_policy(neogfx::size_policy{ aHorizontalConstraint, aVerticalConstraint }, aUpdateLayout);
342 void set_size_policy(size_constraint aHorizontalConstraint, size_constraint aVerticalConstraint, visibility_constraint aVisibility,
bool aUpdateLayout =
true)
344 set_size_policy(neogfx::size_policy{ aHorizontalConstraint, aVerticalConstraint, aVisibility }, aUpdateLayout);
346 void set_size_policy(size_constraint aHorizontalConstraint, size_constraint aVerticalConstraint, visibility_constraint aVisibility,
const size& aAspectRatio,
bool aUpdateLayout =
true)
348 set_size_policy(neogfx::size_policy{ aHorizontalConstraint, aVerticalConstraint, aVisibility, aAspectRatio }, aUpdateLayout);
350 void set_minimum_width(dimension aWidth,
bool aUpdateLayout =
true)
352 auto newSize = minimum_size();
354 set_minimum_size(newSize, aUpdateLayout);
356 void set_minimum_height(dimension aHeight,
bool aUpdateLayout =
true)
358 auto newSize = minimum_size();
359 newSize.cy = aHeight;
360 set_minimum_size(newSize, aUpdateLayout);
362 void set_maximum_width(dimension aWidth,
bool aUpdateLayout =
true)
364 auto newSize = maximum_size();
366 set_maximum_size(newSize, aUpdateLayout);
368 void set_maximum_height(dimension aHeight,
bool aUpdateLayout =
true)
370 auto newSize = maximum_size();
371 newSize.cy = aHeight;
372 set_maximum_size(newSize, aUpdateLayout);
375 box_areas internal_spacing(
bool aExtendIntoPadding =
true)
const
384 typedef i_size_hint abstract_type;
386 virtual ~i_size_hint() =
default;
388 virtual i_string
const& primary_hint()
const = 0;
389 virtual i_string
const& secondary_hint()
const = 0;
392 class size_hint :
public i_size_hint
395 size_hint(i_size_hint
const& aOther) :
396 iPrimaryHint{ aOther.primary_hint() },
397 iSecondaryHint{ aOther.secondary_hint() }
400 size_hint(
string const& aPrimaryHint = {},
string const& aSecondaryHint = {}) :
401 iPrimaryHint{ aPrimaryHint },
402 iSecondaryHint{ aSecondaryHint }
406 operator bool()
const
408 return !primary_hint().empty() || !secondary_hint().empty();
410 bool operator==(
const size_hint& aOther)
const
412 return primary_hint() == aOther.primary_hint() && secondary_hint() == aOther.secondary_hint();
414 bool operator!=(
const size_hint& aOther)
const
416 return !(*
this == aOther);
419 string const& primary_hint() const final
423 string const& secondary_hint() const final
425 return iSecondaryHint;
429 string iSecondaryHint;
#define end_declare_enum(enumName)
#define declare_enum_string(enumName, enumEnumerator)
#define begin_declare_enum(enumName)
std::basic_ostream< Elem, Traits > & operator<<(std::basic_ostream< Elem, Traits > &aStream, const basic_point< T > &aPoint)
basic_box_areas< double > box_areas
basic_margin< dimension > margin
bool operator!=(color_or_gradient const &lhs, color const &rhs) noexcept
basic_padding< dimension > padding
std::string to_string(note const &aNote)
@ DefaultMinimumExpanding
bool operator==(const basic_rect< CoordinateType, CoordinateSystem > &left, const basic_rect< CoordinateType, CoordinateSystem > &right)
optional< size > optional_size
basic_point< coordinate > point
basic_border< dimension > border
basic_size< coordinate > size
ref_ptr< ConcreteType > make_ref(Args &&... args)
StringT enum_to_string(Enum aEnumerator, bool aMustEnumerate=false)
T from_string(i_string const &aValueAsString)