53#ifndef WXMAXIMA_FONTATTRIBS_H
54#define WXMAXIMA_FONTATTRIBS_H
56#include "EnumWrapper.h"
57#include "stx/clamp.hpp"
59#include <wx/version.h>
99 constexpr static float Size_Unit = 0.05f;
102 using value_type = int16_t;
104 constexpr static float Minimum_Size = 4.0f;
105 constexpr static float Maximum_Size = std::numeric_limits<value_type>::max() * Size_Unit;
108 constexpr explicit AFontSize(
float size) : m_uSize(ToUSize(size)) {}
110 m_uSize(std::max(minimum.m_uSize, ToUSize(
static_cast<float>(size)))) {}
114 constexpr void Set(
float size) { m_uSize = ToUSize(size); }
115 constexpr void Clear() { m_uSize = {}; }
120 constexpr bool operator==(
AFontSize o)
const {
return m_uSize == o.m_uSize; }
121 constexpr bool operator!=(
AFontSize o)
const {
return m_uSize != o.m_uSize; }
122 constexpr bool operator<(
AFontSize o)
const {
return m_uSize < o.m_uSize; }
123 constexpr bool operator>(
AFontSize o)
const {
return m_uSize > o.m_uSize; }
124 constexpr float Get()
const {
return IsValid() ? m_uSize * Size_Unit : Minimum_Size; }
125 constexpr long GetAsLong()
const {
return long(Get() + 0.5f); }
127 constexpr bool IsNull()
const {
return !IsValid(); }
128 constexpr bool IsValid()
const {
return m_uSize > 0; }
129 constexpr bool IsMinimal()
const {
return m_uSize == ToUSize(Minimum_Size); }
137 value_type m_uSize = {};
138 constexpr static value_type ToUSize(
float size);
141constexpr double operator*(
double factor,
AFontSize size) {
return factor * size.Get(); }
142constexpr double operator*(
AFontSize size,
double factor) {
return size.Get() * factor; }
143constexpr double operator/(
double dividend,
AFontSize size) {
return dividend / size.Get(); }
144constexpr double operator/(
AFontSize size,
double divisor) {
return size.Get() / divisor; }
145constexpr double operator+(
double offset,
AFontSize size) {
return offset + size.Get(); }
146constexpr double operator+(
AFontSize size,
double offset) {
return size.Get() + offset; }
147constexpr double operator-(
double offset,
AFontSize size) {
return offset - size.Get(); }
148constexpr double operator-(
AFontSize size,
double offset) {
return size.Get() - offset; }
150{
return size.Set(
static_cast<float>(size - factor)), size; }
152constexpr AFontSize::value_type AFontSize::ToUSize(
float size)
154 return AFontSize::value_type(stx::clamp(size, Minimum_Size, Maximum_Size) / Size_Unit + 0.5f);
160#if wxCHECK_VERSION(3, 1, 2)
A Type-Safe Fixed-Point Font Size.
Definition: FontAttribs.h:98
constexpr auto GetForWX() const
Get the numerical value suitable for passing to wxFont/wxFontInfo.
Definition: FontAttribs.h:158
friend bool EqualToWithin(AFontSize, AFontSize, float)
Whether the difference between to font sizes is below a provided limit value.
Definition: FontAttribs.cpp:64
Definition: FontAttribs.h:131