From 5f78a5f7956fbf6596170aa97b9fd6973630e362 Mon Sep 17 00:00:00 2001 From: Memoraike Date: Fri, 24 Jan 2025 18:21:24 +0000 Subject: [PATCH] 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 --- src/config/ConfigManager.cpp | 62 +++++++++---------- src/renderer/Renderer.cpp | 4 +- .../widgets/{Scale.cpp => ProgressBar.cpp} | 22 +++---- .../widgets/{Scale.hpp => ProgressBar.hpp} | 6 +- 4 files changed, 47 insertions(+), 47 deletions(-) rename src/renderer/widgets/{Scale.cpp => ProgressBar.cpp} (83%) rename src/renderer/widgets/{Scale.hpp => ProgressBar.hpp} (84%) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index cd8cfb6..252e2ab 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -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::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(m_config.getSpecialConfigValue("scale", "monitor", k.c_str())), + "progressbar", + std::any_cast(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 diff --git a/src/renderer/Renderer.cpp b/src/renderer/Renderer.cpp index aba5b37..8cf35d1 100644 --- a/src/renderer/Renderer.cpp +++ b/src/renderer/Renderer.cpp @@ -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>* CRenderer::getOrCreateWidgetsFor(const CS widgets[surf].emplace_back(std::make_unique(surf->size, surf->output, resourceID, c.values)); } else if (c.type == "scale") { - widgets[surf].emplace_back(std::make_unique(surf->size, c.values, surf->output->stringPort)); + widgets[surf].emplace_back(std::make_unique(surf->size, c.values, surf->output->stringPort)); } } } diff --git a/src/renderer/widgets/Scale.cpp b/src/renderer/widgets/ProgressBar.cpp similarity index 83% rename from src/renderer/widgets/Scale.cpp rename to src/renderer/widgets/ProgressBar.cpp index a1ea5f9..a628a23 100644 --- a/src/renderer/widgets/Scale.cpp +++ b/src/renderer/widgets/ProgressBar.cpp @@ -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 -CScale::~CScale() { +CProgressBar::~CProgressBar() { if (valueTimer) { valueTimer->cancel(); valueTimer.reset(); @@ -18,25 +18,25 @@ static void onTimer(std::shared_ptr 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& props, const std::string& output) : viewport(viewport_), outputStringPort(output) { +CProgressBar::CProgressBar(const Vector2D& viewport_, const std::unordered_map& props, const std::string& output) : viewport(viewport_), outputStringPort(output) { try { min = std::any_cast(props.at("min")); max = std::any_cast(props.at("max")); @@ -55,8 +55,8 @@ CScale::CScale(const Vector2D& viewport_, const std::unordered_map(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(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()) diff --git a/src/renderer/widgets/Scale.hpp b/src/renderer/widgets/ProgressBar.hpp similarity index 84% rename from src/renderer/widgets/Scale.hpp rename to src/renderer/widgets/ProgressBar.hpp index 779d195..43988a8 100644 --- a/src/renderer/widgets/Scale.hpp +++ b/src/renderer/widgets/ProgressBar.hpp @@ -9,10 +9,10 @@ #include #include -class CScale : public IWidget { +class CProgressBar : public IWidget { public: - CScale(const Vector2D& viewport, const std::unordered_map& props, const std::string& output); - ~CScale(); + CProgressBar(const Vector2D& viewport, const std::unordered_map& props, const std::string& output); + ~CProgressBar(); virtual bool draw(const SRenderData& data);