Skip to content

Commit a3f062e

Browse files
committed
ui: convert all 5 desktop widgets to builder helper
1 parent 6891efe commit a3f062e

5 files changed

Lines changed: 103 additions & 99 deletions

File tree

src/shell/desktop/widgets/desktop_clock_widget.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "render/core/renderer.h"
44
#include "render/scene/node.h"
55
#include "time/time_format.h"
6-
#include "ui/controls/label.h"
6+
#include "ui/builders.h"
77
#include "ui/palette.h"
88
#include "ui/style.h"
99

@@ -34,13 +34,13 @@ DesktopClockWidget::DesktopClockWidget(std::string format, ColorSpec color, bool
3434
void DesktopClockWidget::create() {
3535
auto rootNode = std::make_unique<Node>();
3636

37-
auto label = std::make_unique<Label>();
38-
label->setFontWeight(FontWeight::Bold);
39-
label->setTextAlign(TextAlign::Center);
40-
label->setColor(m_color);
41-
label->setFontSize(clockFontSize(contentScale()));
42-
m_label = label.get();
43-
37+
auto label = ui::label({
38+
.out = &m_label,
39+
.fontSize = clockFontSize(contentScale()),
40+
.color = m_color,
41+
.fontWeight = FontWeight::Bold,
42+
.textAlign = TextAlign::Center,
43+
});
4444
rootNode->addChild(std::move(label));
4545
setRoot(std::move(rootNode));
4646
applyShadow();

src/shell/desktop/widgets/desktop_media_player_widget.cpp

Lines changed: 59 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
#include "net/http_client.h"
77
#include "render/core/renderer.h"
88
#include "render/scene/node.h"
9-
#include "ui/controls/button.h"
10-
#include "ui/controls/flex.h"
11-
#include "ui/controls/image.h"
12-
#include "ui/controls/label.h"
9+
#include "ui/builders.h"
1310
#include "ui/palette.h"
1411
#include "ui/style.h"
1512

@@ -41,66 +38,70 @@ DesktopMediaPlayerWidget::DesktopMediaPlayerWidget(MprisService* mpris, HttpClie
4138
void DesktopMediaPlayerWidget::create() {
4239
auto rootNode = std::make_unique<Node>();
4340

44-
auto artwork = std::make_unique<Image>();
45-
artwork->setFit(ImageFit::Cover);
46-
artwork->setRadius(Style::scaledRadiusMd(contentScale()));
47-
m_artwork = artwork.get();
41+
auto artwork = ui::image({
42+
.out = &m_artwork,
43+
.fit = ImageFit::Cover,
44+
.radius = Style::scaledRadiusMd(contentScale()),
45+
});
4846
rootNode->addChild(std::move(artwork));
4947

50-
auto title = std::make_unique<Label>();
51-
title->setFontWeight(FontWeight::Bold);
52-
title->setMaxLines(1);
53-
title->setColor(m_color);
54-
m_title = title.get();
48+
auto title = ui::label({
49+
.out = &m_title,
50+
.color = m_color,
51+
.maxLines = 1,
52+
.fontWeight = FontWeight::Bold,
53+
});
5554
rootNode->addChild(std::move(title));
5655

57-
auto artist = std::make_unique<Label>();
58-
artist->setMaxLines(1);
59-
artist->setColor(m_color);
60-
m_artist = artist.get();
56+
auto artist = ui::label({
57+
.out = &m_artist,
58+
.color = m_color,
59+
.maxLines = 1,
60+
});
6161
rootNode->addChild(std::move(artist));
6262

63-
auto controls = std::make_unique<Flex>();
64-
controls->setDirection(FlexDirection::Horizontal);
65-
controls->setAlign(FlexAlign::Center);
66-
controls->setJustify(FlexJustify::Center);
67-
m_controls = controls.get();
68-
69-
auto prev = std::make_unique<Button>();
70-
prev->setGlyph("media-prev");
71-
prev->setVariant(ButtonVariant::Ghost);
72-
prev->setOnClick([this]() {
73-
if (m_mpris != nullptr) {
74-
m_mpris->previousActive();
75-
requestRedraw();
76-
}
77-
});
78-
m_prev = prev.get();
79-
controls->addChild(std::move(prev));
80-
81-
auto playPause = std::make_unique<Button>();
82-
playPause->setGlyph("media-play");
83-
playPause->setVariant(ButtonVariant::Primary);
84-
playPause->setOnClick([this]() {
85-
if (m_mpris != nullptr) {
86-
m_mpris->playPauseActive();
87-
requestRedraw();
88-
}
89-
});
90-
m_playPause = playPause.get();
91-
controls->addChild(std::move(playPause));
92-
93-
auto next = std::make_unique<Button>();
94-
next->setGlyph("media-next");
95-
next->setVariant(ButtonVariant::Ghost);
96-
next->setOnClick([this]() {
97-
if (m_mpris != nullptr) {
98-
m_mpris->nextActive();
99-
requestRedraw();
100-
}
101-
});
102-
m_next = next.get();
103-
controls->addChild(std::move(next));
63+
auto controls = ui::row(
64+
{
65+
.out = &m_controls,
66+
.align = FlexAlign::Center,
67+
.justify = FlexJustify::Center,
68+
},
69+
ui::button({
70+
.out = &m_prev,
71+
.glyph = "media-prev",
72+
.variant = ButtonVariant::Ghost,
73+
.onClick =
74+
[this]() {
75+
if (m_mpris != nullptr) {
76+
m_mpris->previousActive();
77+
requestRedraw();
78+
}
79+
},
80+
}),
81+
ui::button({
82+
.out = &m_playPause,
83+
.glyph = "media-play",
84+
.variant = ButtonVariant::Primary,
85+
.onClick =
86+
[this]() {
87+
if (m_mpris != nullptr) {
88+
m_mpris->playPauseActive();
89+
requestRedraw();
90+
}
91+
},
92+
}),
93+
ui::button({
94+
.out = &m_next,
95+
.glyph = "media-next",
96+
.variant = ButtonVariant::Ghost,
97+
.onClick =
98+
[this]() {
99+
if (m_mpris != nullptr) {
100+
m_mpris->nextActive();
101+
requestRedraw();
102+
}
103+
},
104+
}));
104105

105106
rootNode->addChild(std::move(controls));
106107
setRoot(std::move(rootNode));

src/shell/desktop/widgets/desktop_sticker_widget.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "render/core/image_decoder.h"
55
#include "render/core/renderer.h"
66
#include "render/scene/node.h"
7-
#include "ui/controls/image.h"
7+
#include "ui/builders.h"
88
#include "util/file_utils.h"
99

1010
#include <algorithm>
@@ -46,10 +46,10 @@ void DesktopStickerWidget::create() {
4646
auto rootNode = std::make_unique<Node>();
4747
rootNode->setOpacity(m_opacity);
4848

49-
auto image = std::make_unique<Image>();
50-
image->setFit(ImageFit::Contain);
51-
m_image = image.get();
52-
49+
auto image = ui::image({
50+
.out = &m_image,
51+
.fit = ImageFit::Contain,
52+
});
5353
rootNode->addChild(std::move(image));
5454
setRoot(std::move(rootNode));
5555
}

src/shell/desktop/widgets/desktop_sysmon_widget.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
#include "render/scene/node.h"
66
#include "system/format_units.h"
77
#include "system/system_monitor_service.h"
8-
#include "ui/controls/glyph.h"
9-
#include "ui/controls/label.h"
8+
#include "ui/builders.h"
109
#include "ui/style.h"
1110

1211
#include <algorithm>
@@ -66,9 +65,10 @@ DesktopSysmonWidget::~DesktopSysmonWidget() {
6665
void DesktopSysmonWidget::create() {
6766
auto rootNode = std::make_unique<Node>();
6867

69-
auto glyph = std::make_unique<Glyph>();
70-
glyph->setGlyph(glyphName(m_stat));
71-
m_glyph = glyph.get();
68+
auto glyph = ui::glyph({
69+
.out = &m_glyph,
70+
.glyph = glyphName(m_stat),
71+
});
7272
rootNode->addChild(std::move(glyph));
7373

7474
auto graph = std::make_unique<GraphNode>();
@@ -77,12 +77,13 @@ void DesktopSysmonWidget::create() {
7777
m_graphNode = static_cast<GraphNode*>(rootNode->addChild(std::move(graph)));
7878

7979
if (m_showLabel) {
80-
auto label = std::make_unique<Label>();
81-
label->setFontWeight(FontWeight::Bold);
80+
auto label = ui::label({
81+
.out = &m_label,
82+
.fontWeight = FontWeight::Bold,
83+
});
8284
if (m_shadow) {
8385
label->setShadow(Color{0.0f, 0.0f, 0.0f, 0.5f}, 0.0f, 1.0f);
8486
}
85-
m_label = label.get();
8687
rootNode->addChild(std::move(label));
8788
}
8889

src/shell/desktop/widgets/desktop_weather_widget.cpp

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
#include "render/core/renderer.h"
55
#include "render/scene/node.h"
66
#include "system/weather_service.h"
7-
#include "ui/controls/glyph.h"
8-
#include "ui/controls/label.h"
7+
#include "ui/builders.h"
98
#include "ui/palette.h"
109
#include "ui/style.h"
1110

@@ -42,28 +41,31 @@ void DesktopWeatherWidget::create() {
4241
auto rootNode = std::make_unique<Node>();
4342
rootNode->setClipChildren(true);
4443

45-
auto glyph = std::make_unique<Glyph>();
46-
glyph->setGlyph("weather-cloud");
47-
glyph->setGlyphSize(glyphFontSize(contentScale()));
48-
glyph->setColor(m_color);
49-
m_glyph = glyph.get();
44+
auto glyph = ui::glyph({
45+
.out = &m_glyph,
46+
.glyph = "weather-cloud",
47+
.glyphSize = glyphFontSize(contentScale()),
48+
.color = m_color,
49+
});
5050
rootNode->addChild(std::move(glyph));
5151

52-
auto temperature = std::make_unique<Label>();
53-
temperature->setFontWeight(FontWeight::Bold);
54-
temperature->setTextAlign(TextAlign::Start);
55-
temperature->setFontSize(temperatureFontSize(contentScale()));
56-
temperature->setMaxLines(1);
57-
temperature->setColor(m_color);
58-
m_temperature = temperature.get();
52+
auto temperature = ui::label({
53+
.out = &m_temperature,
54+
.fontSize = temperatureFontSize(contentScale()),
55+
.color = m_color,
56+
.maxLines = 1,
57+
.fontWeight = FontWeight::Bold,
58+
.textAlign = TextAlign::Start,
59+
});
5960
rootNode->addChild(std::move(temperature));
6061

61-
auto condition = std::make_unique<Label>();
62-
condition->setTextAlign(TextAlign::Start);
63-
condition->setFontSize(conditionFontSize(contentScale()));
64-
condition->setMaxLines(1);
65-
condition->setColor(m_color);
66-
m_condition = condition.get();
62+
auto condition = ui::label({
63+
.out = &m_condition,
64+
.fontSize = conditionFontSize(contentScale()),
65+
.color = m_color,
66+
.maxLines = 1,
67+
.textAlign = TextAlign::Start,
68+
});
6769
rootNode->addChild(std::move(condition));
6870

6971
setRoot(std::move(rootNode));

0 commit comments

Comments
 (0)