Skip to content

Commit 99a5ac2

Browse files
committed
hideo-shell: Made notifications dismisable.
1 parent 3a4da6f commit 99a5ac2

File tree

6 files changed

+181
-81
lines changed

6 files changed

+181
-81
lines changed

src/apps/hideo-shell/app.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ inline auto panel(Math::Vec2i size = {500, 400}) {
2121

2222
Ui::Child lock(State const &state);
2323

24-
Ui::Child appsPanel();
24+
Ui::Child appsPanel(State const &state);
2525

26-
Ui::Child appsFlyout();
26+
Ui::Child appsFlyout(State const &state);
2727

2828
Ui::Child sysPanel(State const &state);
2929

src/apps/hideo-shell/main.cpp

+106-18
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Ui::Child taskbar(State const &) {
8686

8787
Ui::Child tabletPanels(State const &state) {
8888
return Ui::stack(
89-
state.activePanel == Panel::APPS ? appsFlyout() : Ui::empty(),
89+
state.activePanel == Panel::APPS ? appsFlyout(state) : Ui::empty(),
9090
state.activePanel == Panel::SYS ? sysFlyout(state) : Ui::empty());
9191
}
9292

@@ -102,7 +102,7 @@ Ui::Child tablet(State const &state) {
102102

103103
Ui::Child desktopPanels(State const &state) {
104104
return Ui::stack(
105-
state.activePanel == Panel::APPS ? appsPanel() | Ui::align(Layout::Align::START | Layout::Align::TOP) | Ui::slideIn(Ui::SlideFrom::TOP) : Ui::empty(),
105+
state.activePanel == Panel::APPS ? appsPanel(state) | Ui::align(Layout::Align::START | Layout::Align::TOP) | Ui::slideIn(Ui::SlideFrom::TOP) : Ui::empty(),
106106
state.activePanel == Panel::NOTIS ? notiPanel(state) | Ui::align(Layout::Align::HCENTER | Layout::Align::TOP) | Ui::slideIn(Ui::SlideFrom::TOP) : Ui::empty(),
107107
state.activePanel == Panel::SYS ? sysPanel(state) | Ui::align(Layout::Align::END | Layout::Align::TOP) | Ui::slideIn(Ui::SlideFrom::TOP) : Ui::empty()) |
108108
Ui::spacing({8, 38});
@@ -118,22 +118,110 @@ Ui::Child desktop(State const &state) {
118118
}
119119

120120
Ui::Child app(bool isMobile) {
121-
return Ui::reducer<Model>({.isMobile = isMobile}, [](auto state) {
122-
auto wallpapers = Media::loadImageOrFallback("bundle://skift-wallpapers/images/abstract.qoi"_url).unwrap();
123-
auto background = Ui::align(Layout::Align::COVER, Ui::image(wallpapers));
124-
125-
return Ui::stack(
126-
background,
127-
state.locked ? lock(state)
128-
: (state.isMobile ? tablet(state)
129-
: desktop(state)),
130-
state.isMobile ? tabletPanels(state)
131-
: desktopPanels(state)) |
132-
Ui::dialogLayer() |
133-
Ui::pinSize(
134-
state.isMobile ? Math::Vec2i{411, 731}
135-
: Math::Vec2i{1280, 720});
136-
});
121+
return Ui::reducer<Model>(
122+
{
123+
.isMobile = isMobile,
124+
.noti = {
125+
{
126+
1,
127+
{{Mdi::INFORMATION_OUTLINE, Gfx::BLUE_RAMP}, "About"},
128+
"Hello",
129+
"Hello, world!",
130+
},
131+
{
132+
2,
133+
{{Mdi::INFORMATION_OUTLINE, Gfx::BLUE_RAMP}, "About"},
134+
"Hello",
135+
"Hello, world!",
136+
},
137+
{
138+
3,
139+
{{Mdi::INFORMATION_OUTLINE, Gfx::BLUE_RAMP}, "About"},
140+
"Hello",
141+
"Hello, world!",
142+
},
143+
{
144+
4,
145+
{{Mdi::INFORMATION_OUTLINE, Gfx::BLUE_RAMP}, "About"},
146+
"Hello",
147+
"Hello, world!",
148+
},
149+
},
150+
.entries = {
151+
{
152+
{Mdi::INFORMATION_OUTLINE, Gfx::BLUE_RAMP},
153+
"About",
154+
},
155+
{
156+
{Mdi::CALCULATOR, Gfx::ORANGE_RAMP},
157+
"Calculator",
158+
},
159+
{
160+
{Mdi::PALETTE_SWATCH, Gfx::RED_RAMP},
161+
"Color Picker",
162+
},
163+
{
164+
{Mdi::COUNTER, Gfx::GREEN_RAMP},
165+
"Counter",
166+
},
167+
{
168+
{Mdi::DUCK, Gfx::YELLOW_RAMP},
169+
"Demos",
170+
},
171+
{
172+
{Mdi::FILE, Gfx::ORANGE_RAMP},
173+
"Files",
174+
},
175+
{
176+
{Mdi::FORMAT_FONT, Gfx::BLUE_RAMP},
177+
"Fonts",
178+
},
179+
{
180+
{Mdi::EMOTICON, Gfx::RED_RAMP},
181+
"Hello World",
182+
},
183+
{
184+
{Mdi::IMAGE, Gfx::GREEN_RAMP},
185+
"Icons",
186+
},
187+
{
188+
{Mdi::IMAGE, Gfx::YELLOW_RAMP},
189+
"Image Viewer",
190+
},
191+
{
192+
{Mdi::CUBE, Gfx::BLUE_RAMP},
193+
"Ray Tracer",
194+
},
195+
{
196+
{Mdi::COG, Gfx::ZINC_RAMP},
197+
"Settings",
198+
},
199+
{
200+
{Mdi::TABLE, Gfx::GREEN_RAMP},
201+
"Spreadsheet",
202+
},
203+
{
204+
{Mdi::WIDGETS, Gfx::BLUE_RAMP},
205+
"Widget Gallery",
206+
},
207+
},
208+
},
209+
[](auto state) {
210+
auto wallpapers = Media::loadImageOrFallback("bundle://skift-wallpapers/images/abstract.qoi"_url).unwrap();
211+
auto background = Ui::align(Layout::Align::COVER, Ui::image(wallpapers));
212+
213+
return Ui::stack(
214+
background,
215+
state.locked ? lock(state)
216+
: (state.isMobile ? tablet(state)
217+
: desktop(state)),
218+
state.isMobile ? tabletPanels(state)
219+
: desktopPanels(state)) |
220+
Ui::dialogLayer() |
221+
Ui::pinSize(
222+
state.isMobile ? Math::Vec2i{411, 731}
223+
: Math::Vec2i{1280, 720});
224+
});
137225
}
138226

139227
} // namespace Shell

src/apps/hideo-shell/model.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ void reduce(State &s, Action a) {
1616
[&](Unlock) {
1717
s.locked = false;
1818
},
19+
[&](DimisNoti dismis) {
20+
s.noti.removeAt(dismis.index);
21+
},
1922
[&](Activate panel) {
2023
if (s.activePanel != panel.panel) {
2124
s.activePanel = panel.panel;

src/apps/hideo-shell/model.h

+24-6
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,22 @@
44

55
namespace Shell {
66

7-
struct App {
7+
struct MenuIcon {
88
Mdi::Icon icon;
9-
Gfx::ColorRamp color;
9+
Gfx::ColorRamp colors;
10+
};
11+
12+
struct MenuEntry {
13+
MenuIcon icon;
1014
String name;
1115
};
1216

1317
struct Noti {
18+
usize id;
19+
MenuEntry entry;
1420
String title;
15-
String msg;
21+
String body;
22+
Vec<String> actions{};
1623
};
1724

1825
enum struct Panel {
@@ -22,11 +29,18 @@ enum struct Panel {
2229
SYS,
2330
};
2431

32+
struct Surface {
33+
};
34+
2535
struct State {
2636
bool locked = true;
2737
bool isMobile = true;
2838
Panel activePanel = Panel::NIL;
2939
bool isSysPanelColapsed = true;
40+
41+
Vec<Noti> noti;
42+
Vec<MenuEntry> entries;
43+
Vec<Surface> surfaces;
3044
};
3145

3246
struct ToggleTablet {};
@@ -35,13 +49,17 @@ struct Lock {};
3549

3650
struct Unlock {};
3751

38-
struct Activate {
39-
Panel panel;
52+
struct DimisNoti {
53+
usize index;
4054
};
4155

4256
struct ToggleSysPanel {};
4357

44-
using Action = Var<ToggleTablet, Lock, Unlock, Activate, ToggleSysPanel>;
58+
struct Activate {
59+
Panel panel;
60+
};
61+
62+
using Action = Var<ToggleTablet, Lock, Unlock, DimisNoti, Activate, ToggleSysPanel>;
4563

4664
void reduce(State &, Action);
4765

src/apps/hideo-shell/tray-apps.cpp

+17-31
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,28 @@ Ui::Child searchInput() {
2525
Ui::button(Keyboard::show);
2626
}
2727

28-
Ui::Child appIcon(Mdi::Icon icon, Gfx::ColorRamp colors, isize size = 22) {
29-
return Ui::icon(icon, size) |
28+
Ui::Child appIcon(MenuIcon const &icon, isize size = 22) {
29+
return Ui::icon(icon.icon, size) |
3030
Ui::spacing(size / 2.75) |
3131
Ui::center() |
3232
Ui::box({
3333
.borderRadius = size * 0.25,
3434
.borderWidth = 1,
35-
.borderPaint = colors[5],
36-
.backgroundPaint = colors[6],
37-
.foregroundPaint = colors[1],
35+
.borderPaint = icon.colors[5],
36+
.backgroundPaint = icon.colors[6],
37+
.foregroundPaint = icon.colors[1],
3838
});
3939
}
4040

41-
Ui::Child appRow(Mdi::Icon icon, Gfx::ColorRamp colors, String title) {
41+
Ui::Child appRow(MenuEntry const &entry) {
4242
return Ui::button(
4343
Ui::NOP,
4444
Ui::ButtonStyle::subtle(),
4545
Ui::hflow(
4646
12,
4747
Layout::Align::START | Layout::Align::VCENTER,
48-
appIcon(icon, colors),
49-
Ui::labelLarge(title)) |
48+
appIcon(entry.icon),
49+
Ui::labelLarge(entry.name)) |
5050
Ui::spacing(6));
5151
}
5252

@@ -63,35 +63,21 @@ Ui::Child apps(Ui::Children apps) {
6363
Ui::grow());
6464
}
6565

66-
Ui::Child appsList() {
67-
Ui::Children appItems = {
68-
appRow(Mdi::INFORMATION_OUTLINE, Gfx::BLUE_RAMP, "About"),
69-
appRow(Mdi::CALCULATOR, Gfx::ORANGE_RAMP, "Calculator"),
70-
appRow(Mdi::PALETTE_SWATCH, Gfx::RED_RAMP, "Color Picker"),
71-
appRow(Mdi::COUNTER, Gfx::GREEN_RAMP, "Counter"),
72-
appRow(Mdi::DUCK, Gfx::YELLOW_RAMP, "Demos"),
73-
appRow(Mdi::FILE, Gfx::ORANGE_RAMP, "Files"),
74-
appRow(Mdi::FORMAT_FONT, Gfx::BLUE_RAMP, "Fonts"),
75-
appRow(Mdi::EMOTICON, Gfx::RED_RAMP, "Hello World"),
76-
appRow(Mdi::IMAGE, Gfx::GREEN_RAMP, "Icons"),
77-
appRow(Mdi::IMAGE, Gfx::YELLOW_RAMP, "Image Viewer"),
78-
appRow(Mdi::CUBE, Gfx::BLUE_RAMP, "Ray Tracer"),
79-
appRow(Mdi::COG, Gfx::ZINC_RAMP, "Settings"),
80-
appRow(Mdi::TABLE, Gfx::GREEN_RAMP, "Spreadsheet"),
81-
appRow(Mdi::WIDGETS, Gfx::BLUE_RAMP, "Widget Gallery"),
82-
};
83-
84-
return apps(appItems);
66+
Ui::Child appsList(State const &state) {
67+
return apps(
68+
iter(state.entries)
69+
.map(appRow)
70+
.collect<Ui::Children>());
8571
}
8672

87-
Ui::Child appsPanel() {
88-
return appsList() | panel();
73+
Ui::Child appsPanel(State const &state) {
74+
return appsList(state) | panel();
8975
}
9076

91-
Ui::Child appsFlyout() {
77+
Ui::Child appsFlyout(State const &state) {
9278
return Ui::vflow(
9379
Ui::dragHandle(),
94-
appsList() | Ui::grow()) |
80+
appsList(state) | Ui::grow()) |
9581
Ui::box({
9682
.margin = {8, 8 + 64, 8, 8},
9783
.padding = {12, 0},

0 commit comments

Comments
 (0)