Skip to content

Commit 9245113

Browse files
committed
ui: scale result buttons with font size
1 parent 3a023f4 commit 9245113

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

src/ui/ResultButton.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
#include "UI.hpp"
55

66
CResultButton::CResultButton() {
7+
const auto FONT_SIZE = Hyprtoolkit::CFontSize{Hyprtoolkit::CFontSize::HT_FONT_TEXT}.ptSize();
8+
m_lastFontSize = FONT_SIZE;
9+
710
m_background = Hyprtoolkit::CRectangleBuilder::begin()
811
->color([]() {
912
auto c = g_ui->m_backend->getPalette()->m_colors.accent.darken(0.3F);
1013
c.a = 0.F;
1114
return c;
1215
})
1316
->rounding(4)
14-
->size({Hyprtoolkit::CDynamicSize::HT_SIZE_PERCENT, Hyprtoolkit::CDynamicSize::HT_SIZE_ABSOLUTE, {1, 30}})
17+
->size({Hyprtoolkit::CDynamicSize::HT_SIZE_PERCENT, Hyprtoolkit::CDynamicSize::HT_SIZE_ABSOLUTE, {1.F, (FONT_SIZE * 2.F) + 4.F}})
1518
->commence();
1619

1720
m_container = Hyprtoolkit::CNullBuilder::begin()->size({Hyprtoolkit::CDynamicSize::HT_SIZE_PERCENT, Hyprtoolkit::CDynamicSize::HT_SIZE_PERCENT, {1, 1}})->commence();
@@ -50,7 +53,21 @@ void CResultButton::setLabel(const std::string& x) {
5053
if (x == m_lastLabel)
5154
return;
5255

56+
if (const auto FONT_SIZE = Hyprtoolkit::CFontSize{Hyprtoolkit::CFontSize::HT_FONT_TEXT}.ptSize(); FONT_SIZE != m_lastFontSize)
57+
updatedFontSize();
58+
5359
m_lastLabel = x;
5460

5561
m_label->rebuild()->text(std::string{x})->commence();
5662
}
63+
64+
void CResultButton::updatedFontSize() {
65+
if (!m_background)
66+
return;
67+
68+
const auto FONT_SIZE = Hyprtoolkit::CFontSize{Hyprtoolkit::CFontSize::HT_FONT_TEXT}.ptSize();
69+
70+
m_background->rebuild()->size({Hyprtoolkit::CDynamicSize::HT_SIZE_PERCENT, Hyprtoolkit::CDynamicSize::HT_SIZE_ABSOLUTE, {1.F, (FONT_SIZE * 2.F) + 4.F}})->commence();
71+
72+
m_lastFontSize = FONT_SIZE;
73+
}

src/ui/ResultButton.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class CResultButton {
3030
void setLabel(const std::string& x);
3131

3232
private:
33-
bool m_active = false;
34-
std::string m_lastLabel = "";
33+
void updatedFontSize();
34+
35+
bool m_active = false;
36+
int m_lastFontSize = 0.F;
37+
std::string m_lastLabel = "";
3538
};

0 commit comments

Comments
 (0)