#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: // // 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 class Progressbar : public Div { public: using Div::attr; using Div::style; using Div::markDirty; using Div::getTheme; Progressbar(Attributes attr = Attributes{}, std::initializer_list children = {}) : Div(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::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