Skip to content

Commit beb2f63

Browse files
committed
ui: convert all bar widgets to builder
1 parent d7afc46 commit beb2f63

32 files changed

Lines changed: 552 additions & 479 deletions

src/shell/bar/widgets/active_window_widget.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
#include "render/scene/node.h"
66
#include "system/desktop_entry.h"
77
#include "system/internal_app_metadata.h"
8-
#include "ui/controls/image.h"
9-
#include "ui/controls/label.h"
8+
#include "ui/builders.h"
109
#include "ui/palette.h"
1110
#include "ui/style.h"
1211
#include "util/string_utils.h"
@@ -34,20 +33,23 @@ void ActiveWindowWidget::create() {
3433
});
3534
m_area = rootNode.get();
3635

37-
auto icon = std::make_unique<Image>();
38-
icon->setRadius(Style::radiusSm);
39-
icon->setFit(ImageFit::Contain);
40-
icon->setSize(m_iconSize * m_contentScale, m_iconSize * m_contentScale);
41-
m_icon = static_cast<Image*>(rootNode->addChild(std::move(icon)));
42-
43-
auto title = std::make_unique<Label>();
44-
title->setFontWeight(labelFontWeight());
45-
title->setFontSize(Style::fontSizeBody * m_contentScale);
46-
title->setColor(widgetForegroundOr(colorSpecFromRole(ColorRole::OnSurface)));
47-
title->setMaxWidth(m_maxWidth * m_contentScale);
48-
title->setMaxLines(1);
49-
title->setAutoScroll(false);
50-
m_title = static_cast<Label*>(rootNode->addChild(std::move(title)));
36+
rootNode->addChild(ui::image({
37+
.out = &m_icon,
38+
.fit = ImageFit::Contain,
39+
.radius = Style::radiusSm,
40+
.width = m_iconSize * m_contentScale,
41+
.height = m_iconSize * m_contentScale,
42+
}));
43+
44+
rootNode->addChild(ui::label({
45+
.out = &m_title,
46+
.fontSize = Style::fontSizeBody * m_contentScale,
47+
.color = widgetForegroundOr(colorSpecFromRole(ColorRole::OnSurface)),
48+
.maxWidth = m_maxWidth * m_contentScale,
49+
.maxLines = 1,
50+
.fontWeight = labelFontWeight(),
51+
.autoScroll = false,
52+
}));
5153

5254
setRoot(std::move(rootNode));
5355
}

src/shell/bar/widgets/battery_widget.cpp

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
#include "dbus/upower/upower_service.h"
44
#include "render/core/renderer.h"
55
#include "render/scene/input_area.h"
6-
#include "ui/controls/box.h"
7-
#include "ui/controls/glyph.h"
8-
#include "ui/controls/label.h"
6+
#include "ui/builders.h"
97
#include "ui/palette.h"
108
#include "ui/style.h"
119

@@ -85,51 +83,51 @@ void BatteryWidget::create() {
8583
void BatteryWidget::createGraphicMode() {
8684
auto* container = static_cast<InputArea*>(root());
8785

88-
auto bodyBg = std::make_unique<Box>();
89-
bodyBg->setFill(withOpacity(widgetForegroundOr(colorSpecFromRole(ColorRole::OnSurface)), 0.25f));
90-
m_bodyBg = bodyBg.get();
91-
container->addChild(std::move(bodyBg));
86+
container->addChild(ui::box({
87+
.out = &m_bodyBg,
88+
.fill = withOpacity(widgetForegroundOr(colorSpecFromRole(ColorRole::OnSurface)), 0.25f),
89+
}));
9290

93-
auto fillRect = std::make_unique<Box>();
94-
m_fillRect = fillRect.get();
95-
container->addChild(std::move(fillRect));
91+
container->addChild(ui::box({
92+
.out = &m_fillRect,
93+
}));
9694

97-
auto terminalNub = std::make_unique<Box>();
98-
terminalNub->setFill(withOpacity(widgetForegroundOr(colorSpecFromRole(ColorRole::OnSurface)), 0.25f));
99-
m_terminalNub = terminalNub.get();
100-
container->addChild(std::move(terminalNub));
95+
container->addChild(ui::box({
96+
.out = &m_terminalNub,
97+
.fill = withOpacity(widgetForegroundOr(colorSpecFromRole(ColorRole::OnSurface)), 0.25f),
98+
}));
10199

102100
if (m_showLabel) {
103-
auto overlayLabel = std::make_unique<Label>();
104-
overlayLabel->setFontWeight(labelFontWeight());
105-
overlayLabel->setColor(widgetForegroundOr(colorSpecFromRole(ColorRole::OnSurface)));
106-
m_overlayLabel = overlayLabel.get();
107-
container->addChild(std::move(overlayLabel));
101+
container->addChild(ui::label({
102+
.out = &m_overlayLabel,
103+
.color = widgetForegroundOr(colorSpecFromRole(ColorRole::OnSurface)),
104+
.fontWeight = labelFontWeight(),
105+
}));
108106
}
109107

110-
auto overlayGlyph = std::make_unique<Glyph>();
111-
overlayGlyph->setColor(widgetForegroundOr(colorSpecFromRole(ColorRole::OnSurface)));
112-
overlayGlyph->setVisible(false);
113-
m_overlayGlyph = overlayGlyph.get();
114-
container->addChild(std::move(overlayGlyph));
108+
container->addChild(ui::glyph({
109+
.out = &m_overlayGlyph,
110+
.color = widgetForegroundOr(colorSpecFromRole(ColorRole::OnSurface)),
111+
.visible = false,
112+
}));
115113
}
116114

117115
void BatteryWidget::createIconMode() {
118116
auto* container = static_cast<InputArea*>(root());
119117

120-
auto glyph = std::make_unique<Glyph>();
121-
glyph->setGlyph("battery-4");
122-
glyph->setGlyphSize(Style::barGlyphSize * m_contentScale);
123-
glyph->setColor(widgetForegroundOr(colorSpecFromRole(ColorRole::OnSurface)));
124-
m_glyph = glyph.get();
125-
container->addChild(std::move(glyph));
126-
127-
auto label = std::make_unique<Label>();
128-
label->setFontWeight(labelFontWeight());
129-
label->setFontSize(Style::fontSizeBody * m_contentScale);
130-
label->setVisible(m_showLabel);
131-
m_label = label.get();
132-
container->addChild(std::move(label));
118+
container->addChild(ui::glyph({
119+
.out = &m_glyph,
120+
.glyph = "battery-4",
121+
.glyphSize = Style::barGlyphSize * m_contentScale,
122+
.color = widgetForegroundOr(colorSpecFromRole(ColorRole::OnSurface)),
123+
}));
124+
125+
container->addChild(ui::label({
126+
.out = &m_label,
127+
.fontSize = Style::fontSizeBody * m_contentScale,
128+
.fontWeight = labelFontWeight(),
129+
.visible = m_showLabel,
130+
}));
133131
}
134132

135133
void BatteryWidget::doLayout(Renderer& renderer, float containerWidth, float containerHeight) {

src/shell/bar/widgets/bluetooth_widget.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
#include "render/core/renderer.h"
44
#include "render/scene/input_area.h"
55
#include "render/scene/node.h"
6-
#include "ui/controls/glyph.h"
7-
#include "ui/controls/label.h"
6+
#include "ui/builders.h"
87
#include "ui/palette.h"
98
#include "ui/style.h"
109

@@ -54,19 +53,19 @@ void BluetoothWidget::create() {
5453
area->setOnClick(
5554
[this](const InputArea::PointerData& /*data*/) { requestPanelToggle("control-center", "bluetooth"); });
5655

57-
auto glyph = std::make_unique<Glyph>();
58-
glyph->setGlyph("bluetooth");
59-
glyph->setGlyphSize(Style::barGlyphSize * m_contentScale);
60-
glyph->setColor(widgetForegroundOr(colorSpecFromRole(ColorRole::OnSurface)));
61-
m_glyph = glyph.get();
62-
area->addChild(std::move(glyph));
56+
area->addChild(ui::glyph({
57+
.out = &m_glyph,
58+
.glyph = "bluetooth",
59+
.glyphSize = Style::barGlyphSize * m_contentScale,
60+
.color = widgetForegroundOr(colorSpecFromRole(ColorRole::OnSurface)),
61+
}));
6362

6463
if (m_showLabel) {
65-
auto label = std::make_unique<Label>();
66-
label->setFontSize(Style::fontSizeBody * m_contentScale);
67-
label->setFontWeight(labelFontWeight());
68-
m_label = label.get();
69-
area->addChild(std::move(label));
64+
area->addChild(ui::label({
65+
.out = &m_label,
66+
.fontSize = Style::fontSizeBody * m_contentScale,
67+
.fontWeight = labelFontWeight(),
68+
}));
7069
}
7170

7271
setRoot(std::move(area));

src/shell/bar/widgets/brightness_widget.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
#include "render/scene/input_area.h"
55
#include "render/scene/node.h"
66
#include "system/brightness_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

@@ -45,19 +44,19 @@ void BrightnessWidget::create() {
4544
m_brightness->setBrightness(display->id, newValue);
4645
});
4746

48-
auto glyph = std::make_unique<Glyph>();
49-
glyph->setGlyph("brightness-high");
50-
glyph->setGlyphSize(Style::barGlyphSize * m_contentScale);
51-
glyph->setColor(widgetForegroundOr(colorSpecFromRole(ColorRole::OnSurface)));
52-
m_glyph = glyph.get();
53-
area->addChild(std::move(glyph));
54-
55-
auto label = std::make_unique<Label>();
56-
label->setFontWeight(labelFontWeight());
57-
label->setFontSize(Style::fontSizeBody * m_contentScale);
58-
label->setVisible(m_showLabel);
59-
m_label = label.get();
60-
area->addChild(std::move(label));
47+
area->addChild(ui::glyph({
48+
.out = &m_glyph,
49+
.glyph = "brightness-high",
50+
.glyphSize = Style::barGlyphSize * m_contentScale,
51+
.color = widgetForegroundOr(colorSpecFromRole(ColorRole::OnSurface)),
52+
}));
53+
54+
area->addChild(ui::label({
55+
.out = &m_label,
56+
.fontSize = Style::fontSizeBody * m_contentScale,
57+
.fontWeight = labelFontWeight(),
58+
.visible = m_showLabel,
59+
}));
6160

6261
setRoot(std::move(area));
6362
}

src/shell/bar/widgets/clipboard_widget.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "render/core/renderer.h"
44
#include "render/scene/input_area.h"
5-
#include "ui/controls/glyph.h"
5+
#include "ui/builders.h"
66
#include "ui/palette.h"
77
#include "ui/style.h"
88

@@ -14,12 +14,12 @@ void ClipboardWidget::create() {
1414
auto area = std::make_unique<InputArea>();
1515
area->setOnClick([this](const InputArea::PointerData& /*data*/) { requestPanelToggle("clipboard"); });
1616

17-
auto glyph = std::make_unique<Glyph>();
18-
glyph->setGlyph(m_barGlyphId.empty() ? "clipboard" : m_barGlyphId);
19-
glyph->setGlyphSize(Style::barGlyphSize * m_contentScale);
20-
glyph->setColor(widgetForegroundOr(colorSpecFromRole(ColorRole::OnSurface)));
21-
m_glyph = glyph.get();
22-
area->addChild(std::move(glyph));
17+
area->addChild(ui::glyph({
18+
.out = &m_glyph,
19+
.glyph = m_barGlyphId.empty() ? "clipboard" : m_barGlyphId,
20+
.glyphSize = Style::barGlyphSize * m_contentScale,
21+
.color = widgetForegroundOr(colorSpecFromRole(ColorRole::OnSurface)),
22+
}));
2323

2424
setRoot(std::move(area));
2525
}

src/shell/bar/widgets/clock_widget.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "render/scene/input_area.h"
55
#include "render/scene/node.h"
66
#include "time/time_format.h"
7-
#include "ui/controls/label.h"
7+
#include "ui/builders.h"
88
#include "ui/palette.h"
99
#include "ui/style.h"
1010

@@ -69,20 +69,20 @@ void ClockWidget::create() {
6969
area->setOnClick(
7070
[this](const InputArea::PointerData& /*data*/) { requestPanelToggle("control-center", "calendar"); });
7171

72-
auto label = std::make_unique<Label>();
73-
label->setFontWeight(labelFontWeight());
74-
label->setTextAlign(TextAlign::Center);
75-
label->setFontSize(Style::fontSizeBody * m_contentScale);
76-
m_label = label.get();
77-
area->addChild(std::move(label));
78-
79-
auto secondaryLabel = std::make_unique<Label>();
80-
secondaryLabel->setFontWeight(labelFontWeight());
81-
secondaryLabel->setTextAlign(TextAlign::Center);
82-
secondaryLabel->setFontSize(Style::fontSizeBody * m_contentScale * kStackedSecondaryScale);
83-
secondaryLabel->setVisible(false);
84-
m_secondaryLabel = secondaryLabel.get();
85-
area->addChild(std::move(secondaryLabel));
72+
area->addChild(ui::label({
73+
.out = &m_label,
74+
.fontSize = Style::fontSizeBody * m_contentScale,
75+
.fontWeight = labelFontWeight(),
76+
.textAlign = TextAlign::Center,
77+
}));
78+
79+
area->addChild(ui::label({
80+
.out = &m_secondaryLabel,
81+
.fontSize = Style::fontSizeBody * m_contentScale * kStackedSecondaryScale,
82+
.fontWeight = labelFontWeight(),
83+
.textAlign = TextAlign::Center,
84+
.visible = false,
85+
}));
8686

8787
setRoot(std::move(area));
8888
}

src/shell/bar/widgets/control_center_widget.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
#include "render/scene/input_area.h"
44
#include "render/scene/node.h"
5-
#include "ui/controls/glyph.h"
6-
#include "ui/controls/image.h"
5+
#include "ui/builders.h"
76
#include "ui/palette.h"
87
#include "ui/style.h"
98

@@ -18,17 +17,17 @@ void ControlCenterWidget::create() {
1817
area->setOnClick([this](const InputArea::PointerData& /*data*/) { requestPanelToggle("control-center", "home"); });
1918

2019
if (!m_logoPath.empty()) {
21-
auto image = std::make_unique<Image>();
22-
image->setFit(ImageFit::Contain);
23-
m_image = image.get();
24-
area->addChild(std::move(image));
20+
area->addChild(ui::image({
21+
.out = &m_image,
22+
.fit = ImageFit::Contain,
23+
}));
2524
} else {
26-
auto glyph = std::make_unique<Glyph>();
27-
glyph->setGlyph(m_barGlyphId.empty() ? "search" : m_barGlyphId);
28-
glyph->setGlyphSize(Style::barGlyphSize * m_contentScale);
29-
glyph->setColor(widgetForegroundOr(colorSpecFromRole(ColorRole::OnSurface)));
30-
m_glyph = glyph.get();
31-
area->addChild(std::move(glyph));
25+
area->addChild(ui::glyph({
26+
.out = &m_glyph,
27+
.glyph = m_barGlyphId.empty() ? "search" : m_barGlyphId,
28+
.glyphSize = Style::barGlyphSize * m_contentScale,
29+
.color = widgetForegroundOr(colorSpecFromRole(ColorRole::OnSurface)),
30+
}));
3231
}
3332

3433
setRoot(std::move(area));

src/shell/bar/widgets/custom_button_widget.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
#include "cursor-shape-v1-client-protocol.h"
66
#include "render/core/renderer.h"
77
#include "render/scene/input_area.h"
8-
#include "ui/controls/glyph.h"
9-
#include "ui/controls/label.h"
8+
#include "ui/builders.h"
109
#include "ui/palette.h"
1110
#include "ui/style.h"
1211

@@ -89,23 +88,23 @@ void CustomButtonWidget::create() {
8988
area->setTooltip(m_tooltip);
9089
}
9190

92-
auto glyph = std::make_unique<Glyph>();
93-
glyph->setGlyph(m_glyphName);
94-
glyph->setGlyphSize(Style::barGlyphSize * m_contentScale);
95-
glyph->setColor(widgetForegroundOr(colorSpecFromRole(ColorRole::OnSurface)));
96-
glyph->setVisible(!m_glyphName.empty());
97-
m_glyph = glyph.get();
98-
area->addChild(std::move(glyph));
99-
100-
auto label = std::make_unique<Label>();
101-
label->setText(m_labelText);
102-
label->setFontSize(Style::fontSizeBody * m_contentScale);
103-
label->setFontWeight(labelFontWeight());
104-
label->setMaxLines(1);
105-
label->setColor(widgetForegroundOr(colorSpecFromRole(ColorRole::OnSurface)));
106-
label->setVisible(!m_labelText.empty());
107-
m_label = label.get();
108-
area->addChild(std::move(label));
91+
area->addChild(ui::glyph({
92+
.out = &m_glyph,
93+
.glyph = m_glyphName,
94+
.glyphSize = Style::barGlyphSize * m_contentScale,
95+
.color = widgetForegroundOr(colorSpecFromRole(ColorRole::OnSurface)),
96+
.visible = !m_glyphName.empty(),
97+
}));
98+
99+
area->addChild(ui::label({
100+
.out = &m_label,
101+
.text = m_labelText,
102+
.fontSize = Style::fontSizeBody * m_contentScale,
103+
.color = widgetForegroundOr(colorSpecFromRole(ColorRole::OnSurface)),
104+
.maxLines = 1,
105+
.fontWeight = labelFontWeight(),
106+
.visible = !m_labelText.empty(),
107+
}));
109108

110109
m_area = area.get();
111110
setRoot(std::move(area));

0 commit comments

Comments
 (0)