73 std::enable_if_t<std::is_scalar_v<T>, T>
dpi_scale(T aValue)
const
111 template <
typename T>
114 return std::forward<T>(
dpi_scale_factor() >= 1.5 ? aHighDpiValue : aLowDpiValue);
131 void restore_saved_context();
145 template <
typename Units>
158 set_units(aNewUnits);
162 set_units(aNewUnits);
172 return current_units_for_this_thread();
176 if (iSavedUnits != std::nullopt)
182 restore_saved_units();
186 void set_units(
units aNewUnits)
188 current_units_for_this_thread() = aNewUnits;
190 void restore_saved_units()
192 if (iSavedUnits != std::nullopt)
194 set_units(*iSavedUnits);
195 iSavedUnits = std::nullopt;
198 static units& current_units_for_this_thread()
200 shared_thread_local_class(units, basic_scoped_units<Units>, current_units_for_this_thread, tCurrentUnits, units::Default);
201 return tCurrentUnits;
205 std::optional<scoped_units_context> iScopedContext;
206 std::optional<units> iSavedUnits;
209 template <
typename T>
214 struct unknown_unit : std::runtime_error {
unknown_unit(std::string
const& aUnitName) : std::runtime_error{
"neoGFX: Error: Unknown unit '" + aUnitName +
"'" } {} };
219 iValue{ aValue }, iUnits{ aUnits }
225 return iValue == aRhs.iValue && iUnits == aRhs.iUnits;
229 return !(*
this == aRhs);
233 return std::forward_as_tuple(iValue, iUnits) < std::forward_as_tuple(aRhs.iValue, aRhs.iUnits);
242 if (
units() == units::NoUnitsAsMaximumLength)
243 return std::numeric_limits<value_type>::infinity();
257 return (aToEmit ?
"std::numeric_limits<dimension>::infinity()" :
"max");
258 std::ostringstream oss;
259 oss << unconverted_value();
296 static const std::unordered_map<std::string, neogfx::units> sUnitTypes
312 std::istringstream iss{ aValue };
313 iss >> result.iValue;
314 std::string unitName;
316 auto u = sUnitTypes.find(unitName);
317 if (u == sUnitTypes.end())
319 result.iUnits = u->second;
369 template <
typename T, u
int32_t D>
373 for (uint32_t i = 0; i <
D; ++i)
374 result[i] = to_device_units(aValue[i]);
377 template <
typename T, u
int32_t D>
381 for (uint32_t i = 0; i <
D; ++i)
382 result[i] = to_device_units(aExtents, aValue[i]);
385 template <
typename T, u
int32_t D>
389 for (uint32_t i = 0; i <
D; ++i)
390 result[i] = from_device_units(aValue[i]);
393 template <
typename T, u
int32_t D>
397 for (uint32_t i = 0; i <
D; ++i)
398 result[i] = from_device_units(aExtents, aValue[i]);
444 if (aSourceUnits == aDestinationUnits)
459 if constexpr (std::is_scalar_v<T>)
460 return std::round(result);
462 return result.
round();
470 return convert_units(aUnitsContext, aUnitsContext, aSourceUnits, aDestinationUnits, aValue);
473 template <
typename T>
479 template <
typename T>
485 template <
typename T>
491 template <
typename T>
497 template <
typename T>
503 template <
typename T>
509 template <
typename T>
515 template <
typename T>
521 template <
typename T>
527 template <
typename ResultT,
typename T>
533 template <
typename ResultT,
typename T>
539 template <
typename ResultT,
typename T>
545 template <
typename ResultT,
typename T>
551 template <
typename ResultT,
typename T>
557 template <
typename ResultT,
typename T>
563 template <
typename ResultT,
typename T>
569 template <
typename ResultT,
typename T>
575 template <
typename ResultT,
typename T>
581 template <
typename T>
587 template <
typename T>
593 template <
typename T>
599 template <
typename T>
605 template <
typename T>
611 template <
typename T>
617 template <
typename T>
623 template <
typename T>
629 template <
typename T>
635 template <
typename ResultT,
typename T>
641 template <
typename ResultT,
typename T>
647 template <
typename ResultT,
typename T>
653 template <
typename ResultT,
typename T>
659 template <
typename ResultT,
typename T>
665 template <
typename ResultT,
typename T>
671 template <
typename ResultT,
typename T>
677 template <
typename ResultT,
typename T>
683 template <
typename ResultT,
typename T>
689 template <
typename T>
695 template <
typename T>
701 template <
typename T>
707 template <
typename T>
713 template <
typename T>
719 template <
typename T>
725 template <
typename T>
731 template <
typename T>
737 template <
typename T>
743 template <
typename T>
749 template <
typename T>
755 template <
typename T>
761 template <
typename T>
767 template <
typename T>
773 template <
typename T>
779 template <
typename T>
785 template <
typename T>
791 template <
typename T>
797 template <
typename T>
803 template <
typename T>
809 template <
typename T>
815 template <
typename T>
821 namespace unit_literals
924 using namespace unit_literals;
std::string to_string(bool aToEmit=true) const
value_type unconverted_value() const
bool operator==(const self_type &aRhs) const
bool operator!=(const self_type &aRhs) const
basic_length(value_type aValue=value_type{}, neogfx::units aUnits=neogfx::units::Pixels)
static self_type from_string(std::string const &aValue)
bool operator<(const self_type &aRhs) const
neogfx::units units() const
const point_type & position() const
const size_type & extents() const
basic_scoped_units(units aNewUnits=current_units())
basic_scoped_units(i_units_context const &aNewContext, units aNewUnits=current_units())
static units current_units()
units saved_units() const
static constexpr dimension_type max_dimension()
virtual dimension horizontal_dpi() const =0
virtual dimension vertical_dpi() const =0
virtual const i_device_metrics & device_metrics() const =0
point dpi_scale(const point &aPoint) const
vector2 dpi_scale(const vector2 &aVector) const
virtual ~i_units_context()
dimension x2_dpi_scale_factor() const
size dpi_scale(const size &aSize) const
dimension xn_dpi_scale_factor() const
dimension dpi_scale(dimension aValue) const
std::enable_if_t< std::is_scalar_v< T >, T > dpi_scale(T aValue) const
delta dpi_scale(const delta &aDelta) const
T && dpi_select(T &&aLowDpiValue, T &&aHighDpiValue) const
dimension dpi_scale_factor() const
padding dpi_scale(const padding &aPadding) const
virtual bool device_metrics_available() const =0
static void context_destroyed(i_units_context const &aContext)
~scoped_units_context() noexcept(false)
static i_units_context const & current_context()
scoped_units_context(i_units_context const &aNewContext)
size from_device_units(const size &aExtents, const size &aValue) const
point to_device_units(const size &aExtents, const point &aValue) const
units_converter(i_units_context const &aContext)
basic_vector< T, D > from_device_units(const size &aExtents, const basic_vector< T, D > &aValue)
dimension to_device_units(dimension aValue) const
void set_units(neogfx::units aUnits)
vector2 from_device_units(const size &aExtents, const vector2 &aValue) const
neogfx::units units() const
point from_device_units(const size &aExtents, const point &aValue) const
basic_vector< T, D > to_device_units(const size &aExtents, const basic_vector< T, D > &aValue)
dimension from_device_units(const size &aExtents, dimension aValue) const
dimension to_device_units(const size &aExtents, dimension aValue) const
dimension from_device_units(dimension aValue) const
padding from_device_units(const padding &aValue) const
size to_device_units(const size &aValue) const
basic_vector< T, D > from_device_units(const basic_vector< T, D > &aValue)
delta to_device_units(const size &aExtents, const delta &aValue) const
delta from_device_units(const delta &aValue) const
rect from_device_units(const size &aExtents, const rect &aValue) const
rect to_device_units(const size &aExtents, const rect &aValue) const
rect from_device_units(const rect &aValue) const
padding to_device_units(const padding &aValue) const
point from_device_units(const point &aValue) const
basic_vector< T, D > to_device_units(const basic_vector< T, D > &aValue)
vector2 to_device_units(const vector2 &aValue) const
vector2 from_device_units(const vector2 &aValue) const
delta to_device_units(const delta &aValue) const
units_converter(i_units_context const &aContext, neogfx::units aUnits)
point to_device_units(const point &aValue) const
delta from_device_units(const size &aExtents, const delta &aValue) const
size to_device_units(const size &aExtents, const size &aValue) const
vector2 to_device_units(const size &aExtents, const vector2 &aValue) const
size from_device_units(const size &aValue) const
rect to_device_units(const rect &aValue) const
#define shared_thread_local_class(VariableType, ClassType, VariableScope, VariableName,...)
basic_length< T > pt(T aValue)
T to_units(i_units_context const &aSourceUnitsContext, units aNewUnits, const T &aValue)
basic_length< T > pct(T aValue)
default_geometry_value_type dimension
basic_length< T > cm(T aValue)
basic_length< T > in(T aValue)
T floor_rasterized(T aValue)
basic_length< default_geometry_value_type > length
basic_length< T > px(T aValue)
dimension x2_dpi_scale_factor(dimension aPpi)
basic_length< T > em(T aValue)
dpi_scale_type & dpi_scale_type_for_thread()
basic_length< T > dip(T aValue)
scalar default_geometry_value_type
dimension xn_dpi_scale_factor(dimension aPpi)
T ceil_rasterized(T aValue)
T from_units(i_units_context const &aSourceUnitsContext, units aUnits, const T &aValue)
T convert_units(i_units_context const &aUnitsContext, units aSourceUnits, units aDestinationUnits, const T &aValue)
basic_length< T > pc(T aValue)
basic_scoped_units< units > scoped_units
basic_length< T > mm(T aValue)
unknown_unit(std::string const &aUnitName)