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)) {}
109 constexpr
AFontSize(
AFontSize minimum,
double size) : m_uSize(std::max(minimum.m_uSize, ToUSize(
float(size)))) {}
113 constexpr
void Set(
float size) { m_uSize = ToUSize(size); }
114 constexpr
void Clear() { m_uSize = {}; }
119 constexpr
bool operator==(
AFontSize o)
const {
return m_uSize == o.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
float Get()
const {
return IsValid() ? m_uSize * Size_Unit : Minimum_Size; }
124 constexpr
long GetAsLong()
const {
return long(Get() + 0.5f); }
126 constexpr
bool IsNull()
const {
return !IsValid(); }
127 constexpr
bool IsValid()
const {
return m_uSize > 0; }
128 constexpr
bool IsMinimal()
const {
return m_uSize == ToUSize(Minimum_Size); }
137 value_type m_uSize = {};
138 constexpr
static value_type ToUSize(
float size);
147 size_t operator()(
AFontSize name)
const {
return std::hash<int16_t>()(name.m_uSize); }
151 constexpr
double operator*(
double factor,
AFontSize size) {
return factor * size.Get(); }
152 constexpr
double operator*(
AFontSize size,
double factor) {
return size.Get() * factor; }
153 constexpr
double operator/(
double dividend,
AFontSize size) {
return dividend / size.Get(); }
154 constexpr
double operator/(
AFontSize size,
double divisor) {
return size.Get() / divisor; }
155 constexpr
double operator+(
double offset,
AFontSize size) {
return offset + size.Get(); }
156 constexpr
double operator+(
AFontSize size,
double offset) {
return size.Get() + offset; }
157 constexpr
double operator-(
double offset,
AFontSize size) {
return offset - size.Get(); }
158 constexpr
double operator-(
AFontSize size,
double offset) {
return size.Get() - offset; }
159 constexpr
AFontSize operator-=(
AFontSize &size,
double factor) {
return size.Set(
float(size - factor)), size; }
161 constexpr AFontSize::value_type AFontSize::ToUSize(
float size)
163 return AFontSize::value_type(stx::clamp(size, Minimum_Size, Maximum_Size) / Size_Unit + 0.5f);
169 #if wxCHECK_VERSION(3,1,2)