|
6 | 6 | #include "net/http_client.h" |
7 | 7 | #include "render/core/renderer.h" |
8 | 8 | #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" |
13 | 10 | #include "ui/palette.h" |
14 | 11 | #include "ui/style.h" |
15 | 12 |
|
@@ -41,66 +38,70 @@ DesktopMediaPlayerWidget::DesktopMediaPlayerWidget(MprisService* mpris, HttpClie |
41 | 38 | void DesktopMediaPlayerWidget::create() { |
42 | 39 | auto rootNode = std::make_unique<Node>(); |
43 | 40 |
|
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 | + }); |
48 | 46 | rootNode->addChild(std::move(artwork)); |
49 | 47 |
|
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 | + }); |
55 | 54 | rootNode->addChild(std::move(title)); |
56 | 55 |
|
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 | + }); |
61 | 61 | rootNode->addChild(std::move(artist)); |
62 | 62 |
|
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 | + })); |
104 | 105 |
|
105 | 106 | rootNode->addChild(std::move(controls)); |
106 | 107 | setRoot(std::move(rootNode)); |
|
0 commit comments