From f78758c4eedb022ae49fbecf2f2505f9672d0b9d Mon Sep 17 00:00:00 2001 From: scorpion-26 Date: Fri, 21 Jul 2023 01:08:07 +0200 Subject: [PATCH] SNI: Allow bar rotation Texture was also rewritten, so it doesn't need the SNIPaddingTop hack as much anymore --- src/Bar.cpp | 155 ++++++++++++++++--------------------------------- src/SNI.cpp | 13 +++-- src/Widget.cpp | 22 ++++--- src/Widget.h | 64 ++++++++++++++++++++ 4 files changed, 134 insertions(+), 120 deletions(-) diff --git a/src/Bar.cpp b/src/Bar.cpp index 5ffdc1e..e493353 100644 --- a/src/Bar.cpp +++ b/src/Bar.cpp @@ -269,74 +269,17 @@ namespace Bar #endif } - inline void SetTransform(Widget& widget, const Transform& primary, const Transform& secondary = {}) - { - if (Config::Get().location == 'T' || Config::Get().location == 'B') - { - widget.SetHorizontalTransform(primary); - widget.SetVerticalTransform(secondary); - } - else if (Config::Get().location == 'R' || Config::Get().location == 'L') - { - widget.SetVerticalTransform(primary); - widget.SetHorizontalTransform(secondary); - } - } - - inline TransitionType GetTransitionType() - { - switch (Config::Get().location) - { - case 'T': - case 'B': return TransitionType::SlideLeft; - case 'L': - case 'R': return TransitionType::SlideUp; - default: LOG("Invalid location char \"" << Config::Get().location << "\"!") return TransitionType::SlideLeft; - } - } - - inline Orientation GetOrientation() - { - switch (Config::Get().location) - { - case 'T': - case 'B': return Orientation::Horizontal; - case 'L': - case 'R': return Orientation::Vertical; - default: LOG("Invalid location char \"" << Config::Get().location << "\"!") return Orientation::Horizontal; - } - } - - inline double GetAngle() - { - if (Config::Get().location == 'T' || Config::Get().location == 'B') - { - return 0; - } - else if (Config::Get().location == 'L') - { - return 270; // 90 is buggy (Clipped text) - } - else if (Config::Get().location == 'R') - { - return 270; - } - - LOG("Invalid location char \"" << Config::Get().location << "\"!"); - return 0; - } - void WidgetSensor(Widget& parent, TimerCallback&& callback, const std::string& sensorClass, const std::string& textClass, Text*& textPtr) { auto eventBox = Widget::Create(); { auto box = Widget::Create(); box->SetSpacing({0, false}); - SetTransform(*box, {-1, true, Alignment::Right}); - box->SetOrientation(GetOrientation()); + Utils::SetTransform(*box, {-1, true, Alignment::Right}); + box->SetOrientation(Utils::GetOrientation()); { auto revealer = Widget::Create(); - revealer->SetTransition({GetTransitionType(), 500}); + revealer->SetTransition({Utils::GetTransitionType(), 500}); // Add event to eventbox for the revealer to open eventBox->SetHoverFn( [textRevealer = revealer.get()](EventBox&, bool hovered) @@ -346,8 +289,8 @@ namespace Bar { auto text = Widget::Create(); text->SetClass(textClass); - text->SetAngle(GetAngle()); - SetTransform(*text, {-1, true, Alignment::Fill, 0, 6}); + text->SetAngle(Utils::GetAngle()); + Utils::SetTransform(*text, {-1, true, Alignment::Fill, 0, 6}); textPtr = text.get(); revealer->AddChild(std::move(text)); } @@ -364,7 +307,7 @@ namespace Bar } sensor->SetStyle({angle}); sensor->AddTimer(std::move(callback), DynCtx::updateTime); - SetTransform(*sensor, {24, true, Alignment::Fill}); + Utils::SetTransform(*sensor, {24, true, Alignment::Fill}); box->AddChild(std::move(revealer)); box->AddChild(std::move(sensor)); @@ -386,8 +329,8 @@ namespace Bar auto widgetAudioSlider = [](Widget& parent, AudioType type) { auto slider = Widget::Create(); - slider->SetOrientation(GetOrientation()); - SetTransform(*slider, {100, true, Alignment::Fill}); + slider->SetOrientation(Utils::GetOrientation()); + Utils::SetTransform(*slider, {100, true, Alignment::Fill}); slider->SetInverted(true); switch (type) { @@ -412,11 +355,11 @@ namespace Bar { auto box = Widget::Create(); box->SetSpacing({8, false}); - SetTransform(*box, {-1, true, Alignment::Right}); - box->SetOrientation(GetOrientation()); + Utils::SetTransform(*box, {-1, true, Alignment::Right}); + box->SetOrientation(Utils::GetOrientation()); { auto icon = Widget::Create(); - icon->SetAngle(GetAngle()); + icon->SetAngle(Utils::GetAngle()); switch (type) { case AudioType::Input: @@ -427,7 +370,7 @@ namespace Bar case AudioType::Output: icon->SetClass("audio-icon"); icon->SetText("󰕾 "); - SetTransform(*icon, {-1, true, Alignment::Fill, 0, 6}); + Utils::SetTransform(*icon, {-1, true, Alignment::Fill, 0, 6}); DynCtx::audioIcon = icon.get(); break; } @@ -436,7 +379,7 @@ namespace Bar { EventBox& eventBox = (EventBox&)parent; auto revealer = Widget::Create(); - revealer->SetTransition({GetTransitionType(), 500}); + revealer->SetTransition({Utils::GetTransitionType(), 500}); // Add event to eventbox for the revealer to open eventBox.SetHoverFn( [slideRevealer = revealer.get()](EventBox&, bool hovered) @@ -492,7 +435,7 @@ namespace Bar text->SetText(""); text->SetVisible(false); text->SetClass("package-empty"); - text->SetAngle(GetAngle()); + text->SetAngle(Utils::GetAngle()); text->AddTimer(DynCtx::UpdatePackages, 1000 * Config::Get().checkUpdateInterval, TimerDispatchBehaviour::ImmediateDispatch); parent.AddChild(std::move(text)); } @@ -502,17 +445,17 @@ namespace Bar { auto box = Widget::Create(); box->SetSpacing({0, false}); - box->SetOrientation(GetOrientation()); + box->SetOrientation(Utils::GetOrientation()); { auto devText = Widget::Create(); - devText->SetAngle(GetAngle()); + devText->SetAngle(Utils::GetAngle()); DynCtx::btDevText = devText.get(); devText->SetClass("bt-num"); auto iconText = Widget::Create