config: rename scale to progressbar and update configuration

- renamed scale widget to progressbar
 - updated configuration values for progressbar
 - modified renderer to use progressbar instead of scale
This commit is contained in:
Memoraike 2025-01-24 18:21:24 +00:00
parent 2f51092152
commit 5f78a5f795
No known key found for this signature in database
GPG key ID: 770C9ACF631FC053
4 changed files with 47 additions and 47 deletions

View file

@ -321,21 +321,21 @@ void CConfigManager::init() {
m_config.addSpecialConfigValue("label", "zindex", Hyprlang::INT{0});
SHADOWABLE("label");
m_config.addSpecialCategory("scale", Hyprlang::SSpecialCategoryOptions{.key = nullptr, .anonymousKeyBased = true});
m_config.addSpecialConfigValue("scale", "monitor", Hyprlang::STRING{""});
m_config.addSpecialConfigValue("scale", "min", Hyprlang::INT{0});
m_config.addSpecialConfigValue("scale", "max", Hyprlang::INT{100});
m_config.addSpecialConfigValue("scale", "value", Hyprlang::STRING{""});
m_config.addSpecialConfigValue("scale", "border_size", Hyprlang::INT{0});
m_config.addSpecialConfigValue("scale", "border_color", Hyprlang::INT{0xFF000000});
m_config.addSpecialConfigValue("scale", "rounding", Hyprlang::INT{0});
m_config.addSpecialConfigValue("scale", "size", LAYOUTCONFIG("100,20"));
m_config.addSpecialConfigValue("scale", "position", LAYOUTCONFIG("0,0"));
m_config.addSpecialConfigValue("scale", "halign", Hyprlang::STRING{"center"});
m_config.addSpecialConfigValue("scale", "valign", Hyprlang::STRING{"center"});
m_config.addSpecialConfigValue("scale", "zindex", Hyprlang::INT{0});
m_config.addSpecialConfigValue("scale", "color", Hyprlang::INT{0xFF00FF00});
m_config.addSpecialConfigValue("scale", "background_color", Hyprlang::INT{0xFF000000});
m_config.addSpecialCategory("progressbar", Hyprlang::SSpecialCategoryOptions{.key = nullptr, .anonymousKeyBased = true});
m_config.addSpecialConfigValue("progressbar", "monitor", Hyprlang::STRING{""});
m_config.addSpecialConfigValue("progressbar", "min", Hyprlang::INT{0});
m_config.addSpecialConfigValue("progressbar", "max", Hyprlang::INT{100});
m_config.addSpecialConfigValue("progressbar", "value", Hyprlang::STRING{""});
m_config.addSpecialConfigValue("progressbar", "border_size", Hyprlang::INT{0});
m_config.addSpecialConfigValue("progressbar", "border_color", Hyprlang::INT{0xFF000000});
m_config.addSpecialConfigValue("progressbar", "rounding", Hyprlang::INT{0});
m_config.addSpecialConfigValue("progressbar", "size", LAYOUTCONFIG("100,20"));
m_config.addSpecialConfigValue("progressbar", "position", LAYOUTCONFIG("0,0"));
m_config.addSpecialConfigValue("progressbar", "halign", Hyprlang::STRING{"center"});
m_config.addSpecialConfigValue("progressbar", "valign", Hyprlang::STRING{"center"});
m_config.addSpecialConfigValue("progressbar", "zindex", Hyprlang::INT{0});
m_config.addSpecialConfigValue("progressbar", "color", Hyprlang::INT{0xFF00FF00});
m_config.addSpecialConfigValue("progressbar", "background_color", Hyprlang::INT{0xFF000000});
m_config.registerHandler(&::handleSource, "source", {false});
m_config.registerHandler(&::handleBezier, "bezier", {false});
@ -531,26 +531,26 @@ std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
// clang-format on
}
keys = m_config.listKeysForSpecialCategory("scale");
keys = m_config.listKeysForSpecialCategory("progressbar");
for (auto& k : keys) {
// clang-format off
result.push_back(CConfigManager::SWidgetConfig{
"scale",
std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("scale", "monitor", k.c_str())),
"progressbar",
std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("progressbar", "monitor", k.c_str())),
{
{"min", m_config.getSpecialConfigValue("scale", "min", k.c_str())},
{"max", m_config.getSpecialConfigValue("scale", "max", k.c_str())},
{"value", m_config.getSpecialConfigValue("scale", "value", k.c_str())},
{"border_size", m_config.getSpecialConfigValue("scale", "border_size", k.c_str())},
{"border_color", m_config.getSpecialConfigValue("scale", "border_color", k.c_str())},
{"rounding", m_config.getSpecialConfigValue("scale", "rounding", k.c_str())},
{"size", m_config.getSpecialConfigValue("scale", "size", k.c_str())},
{"position", m_config.getSpecialConfigValue("scale", "position", k.c_str())},
{"halign", m_config.getSpecialConfigValue("scale", "halign", k.c_str())},
{"valign", m_config.getSpecialConfigValue("scale", "valign", k.c_str())},
{"zindex", m_config.getSpecialConfigValue("scale", "zindex", k.c_str())},
{"color", m_config.getSpecialConfigValue("scale", "color", k.c_str())},
{"background_color", m_config.getSpecialConfigValue("scale", "background_color", k.c_str())},
{"min", m_config.getSpecialConfigValue("progressbar", "min", k.c_str())},
{"max", m_config.getSpecialConfigValue("progressbar", "max", k.c_str())},
{"value", m_config.getSpecialConfigValue("progressbar", "value", k.c_str())},
{"border_size", m_config.getSpecialConfigValue("progressbar", "border_size", k.c_str())},
{"border_color", m_config.getSpecialConfigValue("progressbar", "border_color", k.c_str())},
{"rounding", m_config.getSpecialConfigValue("progressbar", "rounding", k.c_str())},
{"size", m_config.getSpecialConfigValue("progressbar", "size", k.c_str())},
{"position", m_config.getSpecialConfigValue("progressbar", "position", k.c_str())},
{"halign", m_config.getSpecialConfigValue("progressbar", "halign", k.c_str())},
{"valign", m_config.getSpecialConfigValue("progressbar", "valign", k.c_str())},
{"zindex", m_config.getSpecialConfigValue("progressbar", "zindex", k.c_str())},
{"color", m_config.getSpecialConfigValue("progressbar", "color", k.c_str())},
{"background_color", m_config.getSpecialConfigValue("progressbar", "background_color", k.c_str())},
}
});
// clang-format on

View file

@ -16,7 +16,7 @@
#include "widgets/Label.hpp"
#include "widgets/Image.hpp"
#include "widgets/Shape.hpp"
#include "widgets/Scale.hpp"
#include "widgets/ProgressBar.hpp"
inline const float fullVerts[] = {
1, 0, // top right
@ -449,7 +449,7 @@ std::vector<std::unique_ptr<IWidget>>* CRenderer::getOrCreateWidgetsFor(const CS
widgets[surf].emplace_back(std::make_unique<CImage>(surf->size, surf->output, resourceID, c.values));
} else if (c.type == "scale") {
widgets[surf].emplace_back(std::make_unique<CScale>(surf->size, c.values, surf->output->stringPort));
widgets[surf].emplace_back(std::make_unique<CProgressBar>(surf->size, c.values, surf->output->stringPort));
}
}
}

View file

@ -1,4 +1,4 @@
#include "Scale.hpp"
#include "ProgressBar.hpp"
#include "../Renderer.hpp"
#include "../../core/AnimationManager.hpp"
#include "../../helpers/Log.hpp"
@ -7,7 +7,7 @@
#include "../../core/hyprlock.hpp"
#include <hyprlang.hpp>
CScale::~CScale() {
CProgressBar::~CProgressBar() {
if (valueTimer) {
valueTimer->cancel();
valueTimer.reset();
@ -18,25 +18,25 @@ static void onTimer(std::shared_ptr<CTimer> self, void* data) {
if (data == nullptr)
return;
const auto PSCALE = (CScale*)data;
const auto PSCALE = (CProgressBar*)data;
PSCALE->onTimerUpdate();
PSCALE->plantTimer();
}
void CScale::onTimerUpdate() {
void CProgressBar::onTimerUpdate() {
updateValue();
g_pHyprlock->renderOutput(outputStringPort);
}
void CScale::plantTimer() {
void CProgressBar::plantTimer() {
if (value.updateEveryMs != 0)
valueTimer = g_pHyprlock->addTimer(std::chrono::milliseconds((int)value.updateEveryMs), onTimer, this, value.allowForceUpdate);
else if (value.updateEveryMs == 0 && value.allowForceUpdate)
valueTimer = g_pHyprlock->addTimer(std::chrono::hours(1), onTimer, this, true);
}
CScale::CScale(const Vector2D& viewport_, const std::unordered_map<std::string, std::any>& props, const std::string& output) : viewport(viewport_), outputStringPort(output) {
CProgressBar::CProgressBar(const Vector2D& viewport_, const std::unordered_map<std::string, std::any>& props, const std::string& output) : viewport(viewport_), outputStringPort(output) {
try {
min = std::any_cast<Hyprlang::INT>(props.at("min"));
max = std::any_cast<Hyprlang::INT>(props.at("max"));
@ -55,8 +55,8 @@ CScale::CScale(const Vector2D& viewport_, const std::unordered_map<std::string,
backgroundColor = std::any_cast<Hyprlang::INT>(props.at("background_color"));
} catch (const std::bad_any_cast& e) { RASSERT(false, "Failed to construct CScale: {}", e.what()); } catch (const std::out_of_range& e) {
RASSERT(false, "Missing property for CScale: {}", e.what());
} catch (const std::bad_any_cast& e) { RASSERT(false, "Failed to construct CProgressBar: {}", e.what()); } catch (const std::out_of_range& e) {
RASSERT(false, "Missing property for CProgressBar: {}", e.what());
}
pos = posFromHVAlign(viewport, size, configPos, halign, valign);
@ -69,7 +69,7 @@ CScale::CScale(const Vector2D& viewport_, const std::unordered_map<std::string,
plantTimer();
}
void CScale::updateValue() {
void CProgressBar::updateValue() {
int value = getValue();
if (value < min)
value = min;
@ -79,7 +79,7 @@ void CScale::updateValue() {
*animatedValue = static_cast<float>(value - min) / (max - min);
}
bool CScale::draw(const SRenderData& data) {
bool CProgressBar::draw(const SRenderData& data) {
CBox box = {pos.x, pos.y, size.x, size.y};
g_pRenderer->renderRect(box, backgroundColor, rounding);
@ -92,7 +92,7 @@ bool CScale::draw(const SRenderData& data) {
return false;
}
int CScale::getValue() {
int CProgressBar::getValue() {
if (value.cmd) {
const auto _value = g_pHyprlock->spawnSync(value.formatted);
if (_value.empty())

View file

@ -9,10 +9,10 @@
#include <unordered_map>
#include <any>
class CScale : public IWidget {
class CProgressBar : public IWidget {
public:
CScale(const Vector2D& viewport, const std::unordered_map<std::string, std::any>& props, const std::string& output);
~CScale();
CProgressBar(const Vector2D& viewport, const std::unordered_map<std::string, std::any>& props, const std::string& output);
~CProgressBar();
virtual bool draw(const SRenderData& data);