foxygit / Torlinkc Log in
commits tags

/include/torlinkc/ui/progress_bar.hpp · 1.35 KB

raw
#pragma once

#include <optional>

#include <ftxui/dom/elements.hpp>
#include <ftxui/screen/color.hpp>

namespace torlinkc::ui {

// Fixed rather than flexed: FTXUI doesn't hand a Node its final box size
// until after it's built, so a per-cell-colored bar (like the logo) needs a
// width decided up front. 24 sits in the original's dynamic 8-28 range.
inline constexpr int kProgressBarWidth = 24;

// A `width`-cell bar at `pct` (0-100), ported from ProgressBar.tsx: a
// deep->mid->bright ramp built from `base` (the row's status color), with
// the empty portion drawn in palette::rule. When `sweepCenter` is given
// (only while status == Downloading), blends in a moving cosine-bell
// highlight -- same trick as the splash logo's sweep -- and switches to the
// fixed purple ramp ProgressBar.tsx's animated case uses, ignoring `base`,
// matching the original 1:1 (every animated row is a downloading row, which
// is already accent-colored anyway).
ftxui::Element renderProgressBar(int pct, int width, ftxui::Color base, std::optional<float> sweepCenter);

// The sheen's position (in bar-cells, possibly outside [0, width) while it
// travels in from/out to off-screen) at a given point on the shared UI
// clock. Mirrors logo.cpp's sweep math but in the progress bar's own units.
float progressSheenCenter(float clockSeconds, int width);

}  // namespace torlinkc::ui