Skip to content

Commit

Permalink
hideo-shell: Introduce mock launcher and instance, update state manag…
Browse files Browse the repository at this point in the history
…ement.
  • Loading branch information
sleepy-monax committed Jan 3, 2025
1 parent 90818e8 commit 9d424b7
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 81 deletions.
31 changes: 10 additions & 21 deletions src/apps/hideo-shell/app.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <hideo-keyboard/views.h>
#include <karm-app/host.h>
#include <karm-kira/scaffold.h>
#include <karm-ui/dialog.h>
#include <karm-ui/drag.h>
#include <karm-ui/input.h>
Expand Down Expand Up @@ -149,12 +148,10 @@ Ui::Child tabletPanels(State const &state) {
}

Ui::Child appHost(State const &state) {
if (state.instances.len() == 0)
if (isEmpty(state.instances))
return Ui::grow(NONE);

auto surface = state.instances[0];
return Ui::empty() |
Ui::box({.backgroundFill = surface->color});
return first(state.instances)->build();
}

Ui::Child tablet(State const &state) {
Expand All @@ -172,33 +169,25 @@ Ui::Child tablet(State const &state) {

Ui::Child appStack(State const &state) {
Ui::Children apps;
usize index = state.instances.len() - 1;
for (auto &s : iterRev(state.instances)) {
usize zindex = state.instances.len() - 1;
for (auto &i : iterRev(state.instances)) {
apps.pushBack(
Kr::scaffold({
.icon = s->manifest->icon,
.title = s->manifest->name,
.body = slot$(Ui::empty()),
}) |
i->build() |
Ui::box({
.borderRadii = 6,
.borderWidth = 1,
.borderFill = Ui::GRAY800,
.backgroundFill = Ui::GRAY900,
.shadowStyle = Gfx::BoxShadow::elevated(index ? 4 : 16),
.shadowStyle = Gfx::BoxShadow::elevated(zindex ? 4 : 16),
}) |
Ui::placed(s->bound) |
Ui::placed(i->bound) |
Ui::intent([=](Ui::Node &n, App::Event &e) {
if (auto m = e.is<Ui::DragEvent>()) {
e.accept();
Model::bubble<MoveInstance>(n, {index, m->delta});
Model::bubble<MoveInstance>(n, {zindex, m->delta});
} else if (auto c = e.is<App::RequestExitEvent>()) {
e.accept();
Model::bubble<CloseInstance>(n, {index});
Model::bubble<CloseInstance>(n, {zindex});
}
})
);
index--;
zindex--;
}

return Ui::stack(apps);
Expand Down
2 changes: 1 addition & 1 deletion src/apps/hideo-shell/cursor.path
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"M13.1 14.9 1.4 3.1 1.4 20 5 16.2 8.3 23.8 11 22.6 7.7 15Z"
"M11.7 11.8 0 0 0 16.9 3.6 13.1 6.9 20.7 9.6 19.5 6.3 11.9Z"
23 changes: 0 additions & 23 deletions src/apps/hideo-shell/instance.h

This file was deleted.

27 changes: 14 additions & 13 deletions src/apps/hideo-shell/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <mdi/table.h>

#include "../app.h"
#include "../mock.h"

Async::Task<> entryPointAsync(Sys::Context &ctx) {
auto args = useArgs(ctx);
Expand All @@ -26,19 +27,19 @@ Async::Task<> entryPointAsync(Sys::Context &ctx) {
.dateTime = Sys::dateTime(),
.background = co_try$(Image::loadOrFallback("bundle://hideo-shell/wallpapers/winter.qoi"_url)),
.noti = {},
.manifests = {
makeStrong<Hideo::Shell::Manifest>(Mdi::INFORMATION_OUTLINE, "About"s, Gfx::BLUE_RAMP),
makeStrong<Hideo::Shell::Manifest>(Mdi::CALCULATOR, "Calculator"s, Gfx::ORANGE_RAMP),
makeStrong<Hideo::Shell::Manifest>(Mdi::PALETTE_SWATCH, "Color Picker"s, Gfx::RED_RAMP),
makeStrong<Hideo::Shell::Manifest>(Mdi::COUNTER, "Counter"s, Gfx::GREEN_RAMP),
makeStrong<Hideo::Shell::Manifest>(Mdi::DUCK, "Demos"s, Gfx::YELLOW_RAMP),
makeStrong<Hideo::Shell::Manifest>(Mdi::FILE, "Files"s, Gfx::ORANGE_RAMP),
makeStrong<Hideo::Shell::Manifest>(Mdi::FORMAT_FONT, "Fonts"s, Gfx::BLUE_RAMP),
makeStrong<Hideo::Shell::Manifest>(Mdi::EMOTICON, "Hello World"s, Gfx::RED_RAMP),
makeStrong<Hideo::Shell::Manifest>(Mdi::IMAGE, "Icons"s, Gfx::GREEN_RAMP),
makeStrong<Hideo::Shell::Manifest>(Mdi::IMAGE, "Image Viewer"s, Gfx::YELLOW_RAMP),
makeStrong<Hideo::Shell::Manifest>(Mdi::COG, "Settings"s, Gfx::ZINC_RAMP),
makeStrong<Hideo::Shell::Manifest>(Mdi::TABLE, "Spreadsheet"s, Gfx::GREEN_RAMP),
.launchers = {
makeStrong<Hideo::Shell::MockLauncher>(Mdi::INFORMATION_OUTLINE, "About"s, Gfx::BLUE_RAMP),
makeStrong<Hideo::Shell::MockLauncher>(Mdi::CALCULATOR, "Calculator"s, Gfx::ORANGE_RAMP),
makeStrong<Hideo::Shell::MockLauncher>(Mdi::PALETTE_SWATCH, "Color Picker"s, Gfx::RED_RAMP),
makeStrong<Hideo::Shell::MockLauncher>(Mdi::COUNTER, "Counter"s, Gfx::GREEN_RAMP),
makeStrong<Hideo::Shell::MockLauncher>(Mdi::DUCK, "Demos"s, Gfx::YELLOW_RAMP),
makeStrong<Hideo::Shell::MockLauncher>(Mdi::FILE, "Files"s, Gfx::ORANGE_RAMP),
makeStrong<Hideo::Shell::MockLauncher>(Mdi::FORMAT_FONT, "Fonts"s, Gfx::BLUE_RAMP),
makeStrong<Hideo::Shell::MockLauncher>(Mdi::EMOTICON, "Hello World"s, Gfx::RED_RAMP),
makeStrong<Hideo::Shell::MockLauncher>(Mdi::IMAGE, "Icons"s, Gfx::GREEN_RAMP),
makeStrong<Hideo::Shell::MockLauncher>(Mdi::IMAGE, "Image Viewer"s, Gfx::YELLOW_RAMP),
makeStrong<Hideo::Shell::MockLauncher>(Mdi::COG, "Settings"s, Gfx::ZINC_RAMP),
makeStrong<Hideo::Shell::MockLauncher>(Mdi::TABLE, "Spreadsheet"s, Gfx::GREEN_RAMP),
},
.instances = {}
};
Expand Down
31 changes: 31 additions & 0 deletions src/apps/hideo-shell/mock.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <karm-kira/scaffold.h>
#include <karm-ui/layout.h>

#include "mock.h"

namespace Hideo::Shell {

void MockLauncher::launch(State &s) {
auto instance = makeStrong<MockInstance>(
icon,
name,
ramp
);
s.activePanel = Panel::NIL;
s.instances.emplaceFront(instance);
}

Ui::Child MockInstance::build() const {
return Kr::scaffold({
.icon = icon,
.title = name,
.body = [name = this->name] {
return Ui::labelMedium(name) | Ui::center();
},
}) |
Ui::box({
.backgroundFill = Ui::GRAY950,
});
}

} // namespace Hideo::Shell
24 changes: 24 additions & 0 deletions src/apps/hideo-shell/mock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include "model.h"

namespace Hideo::Shell {

struct MockLauncher : public Launcher {
using Launcher::Launcher;

void launch(State &) override;
};

struct MockInstance : public Instance {
Mdi::Icon icon;
String name;
Gfx::ColorRamp ramp;

MockInstance(Mdi::Icon icon, String name, Gfx::ColorRamp ramp)
: icon(icon), name(name), ramp(ramp) {}

Ui::Child build() const override;
};

} // namespace Hideo::Shell
10 changes: 1 addition & 9 deletions src/apps/hideo-shell/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,7 @@ Ui::Task<Action> reduce(State &s, Action a) {
s.noti.removeAt(dismis.index);
},
[&](StartInstance start) {
auto instance = makeStrong<Instance>(
0,
Math::Recti{100, 100, 600, 400},
Gfx::randomColor(),
s.manifests[start.index]
);

s.activePanel = Panel::NIL;
s.instances.emplaceFront(instance);
s.launchers[start.index]->launch(s);
},
[&](MoveInstance move) {
s.activePanel = Panel::NIL;
Expand Down
41 changes: 37 additions & 4 deletions src/apps/hideo-shell/model.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,53 @@
#pragma once

#include <karm-app/form-factor.h>
#include <karm-gfx/icon.h>
#include <karm-image/picture.h>
#include <karm-ui/reducer.h>

#include "instance.h"
#include <mdi/application.h>

namespace Hideo::Shell {

struct State;
struct Launcher;

// MARK: Notification ----------------------------------------------------------

struct Noti {
usize id;
String title;
String body;
Vec<String> actions{};
Strong<Manifest> manifest;
};

// MARK: Manifest & Instance ---------------------------------------------------

struct Launcher {
Mdi::Icon icon = Mdi::APPLICATION;
String name;
Gfx::ColorRamp ramp;

Launcher(Mdi::Icon icon, String name, Gfx::ColorRamp ramp)
: icon(icon), name(name), ramp(ramp) {}

virtual ~Launcher() = default;

virtual void launch(State &) = 0;
};

struct Instance {
usize id;
Math::Recti bound = {100, 100, 600, 400};

Instance() = default;

virtual ~Instance() = default;

virtual Ui::Child build() const = 0;
};

// MARK: Model -----------------------------------------------------------------

enum struct Panel {
NIL,
APPS,
Expand All @@ -36,7 +69,7 @@ struct State : Meta::NoCopy {

Image::Picture background;
Vec<Noti> noti;
Vec<Strong<Manifest>> manifests;
Vec<Strong<Launcher>> launchers;
Vec<Strong<Instance>> instances;
};

Expand Down
8 changes: 4 additions & 4 deletions src/apps/hideo-shell/tray-apps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Ui::Child appIcon(Mdi::Icon const &icon, Gfx::ColorRamp ramp, isize size = 22) {
});
}

Ui::Child appRow(Manifest const &manifest, usize i) {
Ui::Child appRow(Launcher const &manifest, usize i) {
return Ui::ButtonStyle::subtle(),
Ui::hflow(
12,
Expand All @@ -41,15 +41,15 @@ Ui::Child appRow(Manifest const &manifest, usize i) {

Ui::Child appsList(State const &state) {
return Ui::vflow(
iter(state.manifests)
iter(state.launchers)
.mapi([](auto &man, usize i) {
return appRow(*man, i);
})
.collect<Ui::Children>()
);
}

Ui::Child appTile(Manifest const &manifest, usize i) {
Ui::Child appTile(Launcher const &manifest, usize i) {
return Ui::vflow(
26,
appIcon(manifest.icon, manifest.ramp, 26),
Expand All @@ -64,7 +64,7 @@ Ui::Child appTile(Manifest const &manifest, usize i) {
Ui::Child appsGrid(State const &state) {
return Ui::grid(
Ui::GridStyle::simpleFixed({8, 64}, {4, 64}),
iter(state.manifests)
iter(state.launchers)
.mapi([](auto &man, usize i) {
return appTile(*man, i);
})
Expand Down
5 changes: 2 additions & 3 deletions src/apps/hideo-shell/tray-sys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,12 @@ Ui::Child quickSettings(State const &state) {
}

Ui::Child noti(Noti const &noti, usize i) {
auto const &manifest = *noti.manifest;
return Ui::vflow(
8,
Ui::hflow(
4,
Ui::icon(manifest.icon, 12) | Ui::box({.foregroundFill = manifest.ramp[4]}),
Ui::text(Ui::TextStyles::labelMedium().withColor(Ui::GRAY400), manifest.name)
Ui::icon(Mdi::INFORMATION, 12) | Ui::box({.foregroundFill = Gfx::BLUE_RAMP[4]}),
Ui::text(Ui::TextStyles::labelMedium().withColor(Ui::GRAY400), "Hideo Shell")
),
Ui::vflow(
6,
Expand Down
2 changes: 1 addition & 1 deletion src/impls/impl-uring/async.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

#include <liburing.h>

//
#include <impl-posix/fd.h>
#include <impl-posix/utils.h>
#include <karm-async/promise.h>
#include <karm-base/map.h>
#include <karm-logger/logger.h>
#include <karm-sys/_embed.h>
Expand Down
5 changes: 3 additions & 2 deletions src/srvs/grund-shell/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <hideo-shell/app.h>
#include <hideo-shell/mock.h>
#include <karm-app/host.h>
#include <karm-gfx/cpu/canvas.h>
#include <karm-image/loader.h>
Expand Down Expand Up @@ -112,8 +113,8 @@ Async::Task<> servAsync(Sys::Context &ctx) {
.dateTime = Sys::dateTime(),
.background = co_try$(Image::loadOrFallback("bundle://hideo-shell/wallpapers/winter.qoi"_url)),
.noti = {},
.manifests = {
makeStrong<Hideo::Shell::Manifest>(Mdi::CALCULATOR, "hideo-calculator.main"s, Gfx::ORANGE_RAMP),
.launchers = {
makeStrong<Hideo::Shell::MockLauncher>(Mdi::CALCULATOR, "hideo-calculator.main"s, Gfx::ORANGE_RAMP),
},
.instances = {}
};
Expand Down

0 comments on commit 9d424b7

Please sign in to comment.