Skip to content

ui::OptionalFloat

Header: winui/core/OptionalFloat.hpp.

A float that may be unset: the type of every optional size, length and value in an option field or setter. Any number fills it (.min_item_width = 120, set_width(240)), std::nullopt or {} leaves it unset, and it converts to and from std::optional<float>. Reading it works as on an optional: test it, then dereference it or call value_or().

Example:

const ui::TileLayout tiles{ .min_item_width = 120, .min_item_height = 90 };

auto panel = std::make_unique<ui::TilePanelControl>();
panel->set_item_width(std::nullopt); // back to the first item's width

OptionalFloat

constexpr OptionalFloat() noexcept = default

Unset.

OptionalFloat

constexpr OptionalFloat(std::nullopt_t) noexcept

Unset.

OptionalFloat

template <detail::OptionalFloatNumber T>
constexpr OptionalFloat(T value) noexcept

Set to value, converted to float.

OptionalFloat

constexpr OptionalFloat(const std::optional<float>& value) noexcept

The same value as value, set or unset.

operator std::optional< float >

constexpr operator std::optional< float >() const noexcept

The value as a std::optional.

has_value

bool has_value() const noexcept

Whether a value is set.

operator bool

constexpr operator bool() const noexcept

Whether a value is set.

operator*

float operator*() const noexcept

The value; it must be set.

value_or

float value_or(float fallback) const noexcept

The value, or fallback when unset.

reset

void reset() noexcept

Unsets the value.