Files
Seele/src/Engine/UI/Element/Progressbar.h
T

56 lines
1.7 KiB
C++
Raw Normal View History

2026-11-10 18:18:42 +00:00
#pragma once
#include "UI/Element/Div.h"
#include "UI/Style/Class.h"
namespace Seele {
namespace UI {
// A progress bar: a horizontal bar that fills proportionally to a 0.0-1.0 value.
// HTML analog: <progress>
//
// Usage:
// auto* bar = new Progressbar<>();
// // per-frame: bar->setValue(fraction) // 0.0 - 1.0
//
// Pure display widget. The bar's background is a lerp between a dimmed
// "empty" color and an accent "full" color, giving a visual fill effect.
template<StyleClass... classes>
class Progressbar : public Div<classes...> {
public:
using Div<classes...>::attr;
using Div<classes...>::style;
using Div<classes...>::markDirty;
using Div<classes...>::getTheme;
Progressbar(Attributes attr = Attributes{}, std::initializer_list<OElement> children = {})
: Div<classes...>(std::move(attr), children) {
style.height = 8;
}
virtual ~Progressbar() override {}
void setValue(float value) {
_value = value < 0.0f ? 0.0f : (value > 1.0f ? 1.0f : value);
markDirty();
}
float getValue() const { return _value; }
void applyStyle(Style parentStyle, const Theme& theme) override {
Div<classes...>::applyStyle(parentStyle, theme);
}
void applyOverrides() override {
const Theme& th = getTheme();
// Lerp between empty (dimmed) and full (green) based on value.
Vector empty(0.14f, 0.14f, 0.16f);
Vector full = th.color(ColorToken::Green);
float v = _value;
style.backgroundColor = Vector(
empty.x + (full.x - empty.x) * v,
empty.y + (full.y - empty.y) * v,
empty.z + (full.z - empty.z) * v);
}
private:
float _value = 0.0f;
};
} // namespace UI
} // namespace Seele