improved bars

This commit is contained in:
2026-07-12 11:17:50 +03:00
parent 2c6d7c2dfa
commit feb26e01c6
4 changed files with 74 additions and 28 deletions
+28 -1
View File
@@ -9,6 +9,7 @@
#include <initializer_list>
#include <optional>
#include <string_view>
#include <type_traits>
#include <variant>
namespace omath::hud::widget
@@ -23,6 +24,32 @@ namespace omath::hud::widget
}
};
struct BarGradient
{
Color empty_color;
Color full_color;
};
struct BarPaint : std::variant<Color, Gradient, BarGradient>
{
using std::variant<Color, Gradient, BarGradient>::variant;
constexpr BarPaint(const float red, const float green, const float blue, const float alpha)
: std::variant<Color, Gradient, BarGradient>(Color{red, green, blue, alpha})
{
}
BarPaint(const Paint& paint)
{
std::visit(
[this](const auto& value)
{
this->template emplace<std::decay_t<decltype(value)>>(value);
},
paint);
}
};
// ── Overloaded helper for std::visit ──────────────────────────────────────
template<typename... Ts>
struct Overloaded : Ts...
@@ -124,7 +151,7 @@ namespace omath::hud::widget
/// A filled bar. `size` is width for left/right sides, height for top/bottom.
struct Bar
{
Paint color;
BarPaint color;
Color outline;
Color bg;
float size;