wxMaxima
|
A Type-Safe Fixed-Point Font Size. More...
#include <FontAttribs.h>
Data Structures | |
struct | Equals |
Public Types | |
using | value_type = int16_t |
Public Member Functions | |
constexpr | AFontSize (float size) |
constexpr | AFontSize (AFontSize minimum, double size) |
constexpr | AFontSize (AFontSize minimum, AFontSize size) |
constexpr | AFontSize (const AFontSize &o)=default |
constexpr void | Set (float size) |
constexpr void | Clear () |
constexpr AFontSize & | operator= (const AFontSize &o)=default |
constexpr bool | operator== (AFontSize o) const |
constexpr bool | operator!= (AFontSize o) const |
constexpr bool | operator< (AFontSize o) const |
constexpr bool | operator> (AFontSize o) const |
constexpr float | Get () const |
constexpr long | GetAsLong () const |
constexpr auto | GetForWX () const |
Get the numerical value suitable for passing to wxFont/wxFontInfo. | |
constexpr bool | IsNull () const |
constexpr bool | IsValid () const |
constexpr bool | IsMinimal () const |
Static Public Attributes | |
static constexpr float | Minimum_Size = 4.0f |
static constexpr float | Maximum_Size = std::numeric_limits<value_type>::max() * Size_Unit |
Friends | |
bool | EqualToWithin (AFontSize, AFontSize, float) |
Whether the difference between to font sizes is below a provided limit value. | |
A Type-Safe Fixed-Point Font Size.
The use of this type enforces type-safety: a font size isn't just any other float. Additionally, the built-in comparison of floating point types does not behave as one would expect, whereas this type is comparable without any gotchas.
The size default-constructs to a null value (AFontSize().IsNull() is true).
The range of font size is Minimum_Size (4.0) to Maximum_Size (1638.35), inclusive.
It is an invariant: the numerical value (available via Get(), GetAsLong(), and operators that convert to double) is always within that range. The Set() operation clamps the value to these two limits, and cannot be used to set the null value.
To null the size, assign the default value or Clear() it.
By the time the getters are invoked, we know that a valid font size is needed, even if only to gracefully degrade to a small displayed text size instead of nastier bugs. I.e. Get() and GetAsLong() on a null font size are valid and return Minimum_Size, but such use is not correct: if null size is expected, e.g. as a default from the configuration system, null check should be done before accessing the numerical value.
To check if a font size is null, use IsNull(), or its inverse IsValid().