From c92a766ee2fae46106e8160dbe79e47eb7796208 Mon Sep 17 00:00:00 2001 From: VAN BOSSUYT Nicolas Date: Mon, 16 Sep 2024 09:18:08 +0200 Subject: [PATCH] vendors: Update from upstream. --- meta/plugins/requirements.txt | 2 +- src/compile_flags.txt | 3 +- src/paper-muncher/inspector.cpp | 34 +-- src/paper-muncher/main.cpp | 2 +- src/paper-muncher/manifest.json | 4 +- src/vendors/apps/hideo-base/manifest.json | 10 - src/vendors/apps/hideo-base/scafold.cpp | 259 ------------------ src/vendors/apps/hideo-base/scafold.h | 70 ----- .../mdi => assets/fonts-mdi}/defs/icons.inc | 0 .../spec.cpp => assets/fonts-mdi/icons.cpp} | 2 +- .../mdi/spec.h => assets/fonts-mdi/icons.h} | 0 src/vendors/libs/karm-app/form-factor.h | 18 ++ src/vendors/libs/karm-cli/base.h | 3 - src/vendors/libs/karm-kira/dialog.cpp | 4 +- src/vendors/libs/karm-kira/scaffold.cpp | 138 ++++++++++ src/vendors/libs/karm-kira/scaffold.h | 43 +++ src/vendors/libs/karm-kira/side-nav.cpp | 4 + src/vendors/libs/karm-kira/side-nav.h | 2 + src/vendors/libs/karm-kira/titlebar.cpp | 67 +++++ src/vendors/libs/karm-kira/titlebar.h | 25 ++ src/vendors/libs/karm-kira/toolbar.cpp | 25 ++ src/vendors/libs/karm-kira/toolbar.h | 15 + src/vendors/libs/karm-media/icon.h | 2 +- src/vendors/libs/karm-media/manifest.json | 2 +- src/vendors/libs/karm-mime/mime.h | 2 +- src/vendors/libs/karm-sys/context.h | 16 +- src/vendors/libs/karm-ui/app.cpp | 74 +++++ src/vendors/libs/karm-ui/app.h | 72 +---- src/vendors/specs/mdi/manifest.json | 10 - 29 files changed, 437 insertions(+), 471 deletions(-) delete mode 100644 src/vendors/apps/hideo-base/manifest.json delete mode 100644 src/vendors/apps/hideo-base/scafold.cpp delete mode 100644 src/vendors/apps/hideo-base/scafold.h rename src/vendors/{specs/mdi => assets/fonts-mdi}/defs/icons.inc (100%) rename src/vendors/{specs/mdi/spec.cpp => assets/fonts-mdi/icons.cpp} (97%) rename src/vendors/{specs/mdi/spec.h => assets/fonts-mdi/icons.h} (100%) create mode 100644 src/vendors/libs/karm-app/form-factor.h delete mode 100644 src/vendors/libs/karm-cli/base.h create mode 100644 src/vendors/libs/karm-kira/scaffold.cpp create mode 100644 src/vendors/libs/karm-kira/scaffold.h create mode 100644 src/vendors/libs/karm-kira/titlebar.cpp create mode 100644 src/vendors/libs/karm-kira/titlebar.h create mode 100644 src/vendors/libs/karm-kira/toolbar.cpp create mode 100644 src/vendors/libs/karm-kira/toolbar.h create mode 100644 src/vendors/libs/karm-ui/app.cpp delete mode 100644 src/vendors/specs/mdi/manifest.json diff --git a/meta/plugins/requirements.txt b/meta/plugins/requirements.txt index c4275bc..d234be3 100644 --- a/meta/plugins/requirements.txt +++ b/meta/plugins/requirements.txt @@ -1 +1 @@ -git+https://github.com/cute-engineering/cutekit.git@0.7.3 +git+https://github.com/cute-engineering/cutekit.git@0.7.5 diff --git a/src/compile_flags.txt b/src/compile_flags.txt index ea626b6..42cad3e 100644 --- a/src/compile_flags.txt +++ b/src/compile_flags.txt @@ -7,10 +7,9 @@ -Werror -I./ --I./vendors/apps +-I./vendors/assets -I./vendors/impls -I./vendors/libs --I./vendors/specs -I./web -I../.cutekit/extern/cute-engineering -I../.cutekit/extern/cute-engineering diff --git a/src/paper-muncher/inspector.cpp b/src/paper-muncher/inspector.cpp index 4a429c8..30620d5 100644 --- a/src/paper-muncher/inspector.cpp +++ b/src/paper-muncher/inspector.cpp @@ -1,14 +1,19 @@ -#include #include #include #include +#include #include +#include +#include #include #include #include +#include +#include #include #include #include +#include #include #include #include @@ -181,7 +186,7 @@ Ui::Child app(Mime::Url url, Res> dom) { }, [](State const &s) { return Ui::vflow( - Hideo::toolbar( + Kr::toolbar({ Ui::button( [&](Ui::Node &n) { Ui::showDialog(n, Kr::alert("Paper-Muncher"s, "Copyright © 2024, Odoo S.A."s)); @@ -196,30 +201,11 @@ Ui::Child app(Mime::Url url, Res> dom) { }, Ui::ButtonStyle::subtle(), Mdi::DOTS_HORIZONTAL ), - Hideo::controls() - ) | Ui::dragRegion(), - appContent(s) | Ui::grow() + Kr::titlebarControls(), + }) | Ui::dragRegion(), + appContent(s) | Ui::inspector | Ui::grow() ) | Ui::pinSize({800, 600}) | Ui::dialogLayer() | Ui::popoverLayer(); - - return Hideo::scafold({ - .icon = Mdi::SURFING, - .title = "Vaev"s, - .startTools = slots$( - Ui::button(Model::bind(), Ui::ButtonStyle::subtle(), Mdi::REFRESH) - ), - .midleTools = slots$(addressBar(s.url) | Ui::grow()), - .endTools = slots$( - Ui::button( - [&](Ui::Node &n) { - Ui::showPopover(n, n.bound().bottomEnd(), mainMenu(s)); - }, - Ui::ButtonStyle::subtle(), - Mdi::DOTS_HORIZONTAL - ) - ), - .body = slot$(appContent(s)), - }); } ); } diff --git a/src/paper-muncher/main.cpp b/src/paper-muncher/main.cpp index cba83ea..bb86342 100644 --- a/src/paper-muncher/main.cpp +++ b/src/paper-muncher/main.cpp @@ -250,7 +250,7 @@ Async::Task<> entryPointAsync(Sys::Context &ctx) { co_return Ui::runApp( ctx, - PaperMuncher::Inspector::app(input, dom) | Ui::inspector + PaperMuncher::Inspector::app(input, dom) ); } else { Sys::errln("unknown verb: {} (expected: css-dump-stylesheet, css-dump-sst, css-dump-tokens, style-list-props, markup-dump-dom, markup-dump-tokens, inspector)\n"); diff --git a/src/paper-muncher/manifest.json b/src/paper-muncher/manifest.json index 2987d4f..075c054 100644 --- a/src/paper-muncher/manifest.json +++ b/src/paper-muncher/manifest.json @@ -4,8 +4,8 @@ "type": "exe", "requires": [ "karm-sys", + "karm-kira", "vaev-driver", - "vaev-view", - "hideo-base" + "vaev-view" ] } diff --git a/src/vendors/apps/hideo-base/manifest.json b/src/vendors/apps/hideo-base/manifest.json deleted file mode 100644 index f31c147..0000000 --- a/src/vendors/apps/hideo-base/manifest.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "$schema": "https://schemas.cute.engineering/stable/cutekit.manifest.component.v1", - "id": "hideo-base", - "type": "lib", - "description": "Base component for Hideo", - "requires": [ - "karm-ui", - "karm-kira" - ] -} diff --git a/src/vendors/apps/hideo-base/scafold.cpp b/src/vendors/apps/hideo-base/scafold.cpp deleted file mode 100644 index cb2a25e..0000000 --- a/src/vendors/apps/hideo-base/scafold.cpp +++ /dev/null @@ -1,259 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -#include "scafold.h" - -namespace Hideo { - -#undef __ck_sys_darwin__ - -static Ui::BoxStyle TOOLBAR = { - .backgroundFill = Ui::GRAY900, -}; - -Ui::Child aboutButton([[maybe_unused]] Mdi::Icon icon, String title) { -#ifdef __ck_sys_darwin__ - return Ui::button( - [title](auto &n) { - Ui::showDialog(n, Kr::aboutDialog(title)); - }, - Ui::ButtonStyle::subtle(), title - ); -#else - return Ui::button( - [title](auto &n) { - Ui::showDialog(n, Kr::aboutDialog(title)); - }, - Ui::ButtonStyle::subtle(), icon, title - ); -#endif -} - -Ui::Child controls(TitlebarStyle style) { -#ifdef __ck_sys_darwin__ - return Ui::hflow( - 4, - Ui::button( - Ui::bindBubble(), - Ui::ButtonStyle::subtle(), - Mdi::CLOSE - ), - Ui::button( - Ui::bindBubble(), - Ui::ButtonStyle::subtle(), - Mdi::MINUS - ) | Ui::cond(style == TitlebarStyle::DEFAULT), - Ui::button( - Ui::bindBubble(), - Ui::ButtonStyle::subtle(), - Mdi::PLUS - ) | Ui::cond(style == TitlebarStyle::DEFAULT) - ); -#else - return Ui::hflow( - 4, - Ui::button( - Ui::bindBubble(), - Ui::ButtonStyle::subtle(), - Mdi::MINUS - ) | Ui::cond(style == TitlebarStyle::DEFAULT), - Ui::button( - Ui::bindBubble(), - Ui::ButtonStyle::subtle(), - Mdi::CROP_SQUARE - ) | Ui::cond(style == TitlebarStyle::DEFAULT), - Ui::button( - Ui::bindBubble(), - Ui::ButtonStyle::subtle(), - Mdi::CLOSE - ) - ); -#endif -} - -Ui::Child titlebar(Mdi::Icon icon, String title, TitlebarStyle style) { -#ifdef __ck_sys_darwin__ - return Ui::stack( - aboutButton(icon, title) | Ui::center(), - Ui::hflow( - controls(style), - Ui::grow(NONE) - ) - ) | - Ui::insets(8) | - Ui::dragRegion() | box(TOOLBAR); -#else - return Ui::hflow( - 4, - aboutButton(icon, title), - Ui::grow(NONE), - controls(style) - ) | - Ui::insets(8) | - Ui::dragRegion() | box(TOOLBAR); -#endif -} - -Ui::Child titlebar(Mdi::Icon icon, String title, Ui::Child tabs, TitlebarStyle style) { - return hflow( - 4, - aboutButton(icon, title), - tabs | Ui::grow(), - controls(style) - ) | - Ui::insets(8) | - Ui::dragRegion(); -} - -Ui::Child toolbar(Ui::Children children) { - return Ui::vflow( - Ui::hflow(4, children) | - Ui::insets(8) | - box(TOOLBAR), - Ui::separator() - ); -} - -Ui::Child bottombar(Ui::Children children) { - return Ui::vflow( - Ui::separator(), - Ui::hflow(4, children) | - Ui::insets(8) | - Ui::box(TOOLBAR) - ); -} - -Ui::Child mobileScafold(Scafold::State const &s, Scafold const &scafold) { - Ui::Children body; - - if (scafold.midleTools) - body.pushBack(toolbar(scafold.midleTools().unwrap())); - - if (s.sidebarOpen and scafold.sidebar) { - body.pushBack( - (scafold.sidebar().unwrap()) | - Ui::grow() - ); - } else { - body.pushBack(scafold.body() | Ui::grow()); - } - - Ui::Children tools; - - if (scafold.sidebar) - tools.pushBack( - Ui::button( - Scafold::Model::bind(), - Ui::ButtonStyle::subtle(), - s.sidebarOpen - ? Mdi::MENU_OPEN - : Mdi::MENU - ) - ); - - if (scafold.startTools) - tools.pushBack( - hflow(4, scafold.startTools().unwrap()) - ); - - if (scafold.startTools and scafold.endTools) - tools.pushBack(Ui::grow(NONE)); - - if (scafold.endTools) - tools.pushBack( - hflow(4, scafold.endTools().unwrap()) - ); - - if (tools.len()) - body.pushBack(bottombar(tools)); - - return Ui::vflow(body) | - Ui::pinSize(Math::Vec2i{411, 731}) | - Ui::dialogLayer() | - Ui::popoverLayer(); -} - -Ui::Child desktopScafold(Scafold::State const &s, Scafold const &scafold) { - Ui::Children body; - - body.pushBack(titlebar(scafold.icon, scafold.title, scafold.titlebar)); - - Ui::Children tools; - - if (scafold.sidebar) - tools.pushBack( - button( - Scafold::Model::bind(), - Ui::ButtonStyle::subtle(), - s.sidebarOpen ? Mdi::MENU_OPEN : Mdi::MENU - ) - ); - - if (scafold.startTools) - tools.pushBack( - hflow(4, scafold.startTools().unwrap()) - ); - - if (scafold.midleTools) - tools.pushBack( - hflow(4, scafold.midleTools().unwrap()) | Ui::grow() - ); - - else if (scafold.endTools) - tools.pushBack(Ui::grow(NONE)); - - if (scafold.endTools) - tools.pushBack( - hflow(4, scafold.endTools().unwrap()) - ); - - if (tools.len()) - body.pushBack( - toolbar(tools) - ); - else - body.pushBack( - Ui::separator() - ); - - if (s.sidebarOpen and scafold.sidebar) { - body.pushBack( - hflow( - scafold.sidebar().unwrap(), - Ui::separator(), - scafold.body() | Ui::grow() - ) | - Ui::grow() - ); - } else { - body.pushBack(scafold.body() | Ui::grow()); - } - - return Ui::vflow(body) | - Ui::pinSize(scafold.size) | - Ui::dialogLayer() | - Ui::popoverLayer(); -} - -Ui::Child scafold(Scafold scafold) { - auto isMobile = Sys::useFormFactor() == Sys::FormFactor::MOBILE; - - Scafold::State state{ - .sidebarOpen = not isMobile, - .isMobile = isMobile, - }; - - return Ui::reducer(state, [scafold = std::move(scafold)](Scafold::State const &state) { - return state.isMobile - ? mobileScafold(state, scafold) - : desktopScafold(state, scafold); - }); -} - -} // namespace Hideo diff --git a/src/vendors/apps/hideo-base/scafold.h b/src/vendors/apps/hideo-base/scafold.h deleted file mode 100644 index 8ba1162..0000000 --- a/src/vendors/apps/hideo-base/scafold.h +++ /dev/null @@ -1,70 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace Hideo { - -enum struct TitlebarStyle { - DEFAULT, - FIXED, - DIALOG, -}; - -Ui::Child controls(TitlebarStyle style = TitlebarStyle::DEFAULT); - -Ui::Child titlebar(Mdi::Icon icon, String title, TitlebarStyle style = TitlebarStyle::DEFAULT); - -Ui::Child titlebar(Mdi::Icon icon, String title, Ui::Child tabs, TitlebarStyle style = TitlebarStyle::DEFAULT); - -Ui::Child toolbar(Ui::Children children); - -inline Ui::Child toolbar(Meta::Same auto... children) { - return toolbar({children...}); -} - -Ui::Child bottombar(Ui::Children children); - -inline Ui::Child bottombar(Meta::Same auto... children) { - return bottombar({children...}); -} - -struct Scafold : Meta::NoCopy { - Mdi::Icon icon; - String title; - TitlebarStyle titlebar = TitlebarStyle::DEFAULT; - - Opt startTools = NONE; - Opt midleTools = NONE; - Opt endTools = NONE; - Opt sidebar = NONE; - Ui::Slot body; - - Math::Vec2i size = {800, 600}; - - struct State { - bool sidebarOpen = false; - bool isMobile = false; - }; - - struct ToggleSidebar {}; - - using Action = Union; - - static void reduce(State &s, Action a) { - if (a.is()) { - s.sidebarOpen = !s.sidebarOpen; - } - } - - using Model = Ui::Model; -}; - -Ui::Child scafold(Scafold scafold); - -} // namespace Hideo diff --git a/src/vendors/specs/mdi/defs/icons.inc b/src/vendors/assets/fonts-mdi/defs/icons.inc similarity index 100% rename from src/vendors/specs/mdi/defs/icons.inc rename to src/vendors/assets/fonts-mdi/defs/icons.inc diff --git a/src/vendors/specs/mdi/spec.cpp b/src/vendors/assets/fonts-mdi/icons.cpp similarity index 97% rename from src/vendors/specs/mdi/spec.cpp rename to src/vendors/assets/fonts-mdi/icons.cpp index f31665a..a1a0e3d 100644 --- a/src/vendors/specs/mdi/spec.cpp +++ b/src/vendors/assets/fonts-mdi/icons.cpp @@ -1,4 +1,4 @@ -#include "spec.h" +#include "icons.h" namespace Mdi { diff --git a/src/vendors/specs/mdi/spec.h b/src/vendors/assets/fonts-mdi/icons.h similarity index 100% rename from src/vendors/specs/mdi/spec.h rename to src/vendors/assets/fonts-mdi/icons.h diff --git a/src/vendors/libs/karm-app/form-factor.h b/src/vendors/libs/karm-app/form-factor.h new file mode 100644 index 0000000..15074cd --- /dev/null +++ b/src/vendors/libs/karm-app/form-factor.h @@ -0,0 +1,18 @@ +#pragma once + +#include + +namespace Karm::App { + +enum struct FormFactor { + DESKTOP, + MOBILE, +}; + +inline FormFactor useFormFactor(Sys::Context &ctx = Sys::globalContext()) { + if (useArgs(ctx).has("--mobile")) + return FormFactor::MOBILE; + return FormFactor::DESKTOP; +} + +} // namespace Karm::App diff --git a/src/vendors/libs/karm-cli/base.h b/src/vendors/libs/karm-cli/base.h deleted file mode 100644 index 88e67d2..0000000 --- a/src/vendors/libs/karm-cli/base.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include diff --git a/src/vendors/libs/karm-kira/dialog.cpp b/src/vendors/libs/karm-kira/dialog.cpp index ec275eb..596ba8a 100644 --- a/src/vendors/libs/karm-kira/dialog.cpp +++ b/src/vendors/libs/karm-kira/dialog.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -50,7 +50,7 @@ Ui::Child dialogDescription(String text) { } Ui::Child dialogFooter(Ui::Children children) { - auto isMobile = Sys::useFormFactor() == Sys::FormFactor::MOBILE; + auto isMobile = App::useFormFactor() == App::FormFactor::MOBILE; if (not isMobile) children.pushFront(Ui::grow(NONE)); return Ui::flow( diff --git a/src/vendors/libs/karm-kira/scaffold.cpp b/src/vendors/libs/karm-kira/scaffold.cpp new file mode 100644 index 0000000..0ac9438 --- /dev/null +++ b/src/vendors/libs/karm-kira/scaffold.cpp @@ -0,0 +1,138 @@ +#include +#include +#include +#include +#include + +#include "scaffold.h" + +namespace Karm::Kira { + +Ui::Child mobilescaffold(Scaffold::State const &s, Scaffold const &scaffold) { + Ui::Children body; + + if (scaffold.midleTools) + body.pushBack(toolbar(scaffold.midleTools().unwrap())); + + if (s.sidebarOpen and scaffold.sidebar) { + body.pushBack( + (scaffold.sidebar().unwrap()) | + Ui::grow() + ); + } else { + body.pushBack(scaffold.body() | Ui::grow()); + } + + Ui::Children tools; + + if (scaffold.sidebar) + tools.pushBack( + Ui::button( + Scaffold::Model::bind(), + Ui::ButtonStyle::subtle(), + s.sidebarOpen + ? Mdi::MENU_OPEN + : Mdi::MENU + ) + ); + + if (scaffold.startTools) + tools.pushBack( + hflow(4, scaffold.startTools().unwrap()) + ); + + if (scaffold.startTools and scaffold.endTools) + tools.pushBack(Ui::grow(NONE)); + + if (scaffold.endTools) + tools.pushBack( + hflow(4, scaffold.endTools().unwrap()) + ); + + if (tools.len()) + body.pushBack(bottombar(tools)); + + return Ui::vflow(body) | + Ui::pinSize(Math::Vec2i{411, 731}) | + Ui::dialogLayer() | + Ui::popoverLayer(); +} + +Ui::Child desktopscaffold(Scaffold::State const &s, Scaffold const &scaffold) { + Ui::Children body; + + body.pushBack(titlebar(scaffold.icon, scaffold.title, scaffold.titlebar)); + + Ui::Children tools; + + if (scaffold.sidebar) + tools.pushBack( + button( + Scaffold::Model::bind(), + Ui::ButtonStyle::subtle(), + s.sidebarOpen ? Mdi::MENU_OPEN : Mdi::MENU + ) + ); + + if (scaffold.startTools) + tools.pushBack( + hflow(4, scaffold.startTools().unwrap()) + ); + + if (scaffold.midleTools) + tools.pushBack( + hflow(4, scaffold.midleTools().unwrap()) | Ui::grow() + ); + + else if (scaffold.endTools) + tools.pushBack(Ui::grow(NONE)); + + if (scaffold.endTools) + tools.pushBack( + hflow(4, scaffold.endTools().unwrap()) + ); + + if (tools.len()) + body.pushBack( + toolbar(tools) + ); + else + body.pushBack( + Ui::separator() + ); + + if (s.sidebarOpen and scaffold.sidebar) { + body.pushBack( + hflow( + scaffold.sidebar().unwrap(), + Ui::separator(), + scaffold.body() | Ui::grow() + ) | + Ui::grow() + ); + } else { + body.pushBack(scaffold.body() | Ui::grow()); + } + + return Ui::vflow(body) | + Ui::pinSize(scaffold.size) | + Ui::dialogLayer() | + Ui::popoverLayer(); +} + +Ui::Child scaffold(Scaffold scaffold) { + auto isMobile = App::useFormFactor() == App::FormFactor::MOBILE; + + Scaffold::State state{ + .sidebarOpen = not isMobile, + .isMobile = isMobile, + }; + + return Ui::reducer(state, [scaffold = std::move(scaffold)](Scaffold::State const &state) { + return state.isMobile + ? mobilescaffold(state, scaffold) + : desktopscaffold(state, scaffold); + }); +} + +} // namespace Karm::Kira diff --git a/src/vendors/libs/karm-kira/scaffold.h b/src/vendors/libs/karm-kira/scaffold.h new file mode 100644 index 0000000..67f386d --- /dev/null +++ b/src/vendors/libs/karm-kira/scaffold.h @@ -0,0 +1,43 @@ +#pragma once + +#include +#include + +#include "_prelude.h" + +namespace Karm::Kira { + +struct Scaffold : Meta::NoCopy { + Mdi::Icon icon; + String title; + Kr::TitlebarStyle titlebar = Kr::TitlebarStyle::DEFAULT; + + Opt startTools = NONE; + Opt midleTools = NONE; + Opt endTools = NONE; + Opt sidebar = NONE; + Ui::Slot body; + + Math::Vec2i size = {800, 600}; + + struct State { + bool sidebarOpen = false; + bool isMobile = false; + }; + + struct ToggleSidebar {}; + + using Action = Union; + + static void reduce(State &s, Action a) { + if (a.is()) { + s.sidebarOpen = !s.sidebarOpen; + } + } + + using Model = Ui::Model; +}; + +Ui::Child scaffold(Scaffold scaffold); + +} // namespace Karm::Kira diff --git a/src/vendors/libs/karm-kira/side-nav.cpp b/src/vendors/libs/karm-kira/side-nav.cpp index f035bf3..9a26531 100644 --- a/src/vendors/libs/karm-kira/side-nav.cpp +++ b/src/vendors/libs/karm-kira/side-nav.cpp @@ -72,4 +72,8 @@ Ui::Child sidenavItem(bool selected, Ui::OnPress onPress, Mdi::Icon icon, String ); } +Ui::Child sidenavTitle(String title) { + return Ui::titleMedium(title) | Ui::insets({8, 8, 12, 8}); +} + } // namespace Karm::Kira diff --git a/src/vendors/libs/karm-kira/side-nav.h b/src/vendors/libs/karm-kira/side-nav.h index 7a28f22..9c9492c 100644 --- a/src/vendors/libs/karm-kira/side-nav.h +++ b/src/vendors/libs/karm-kira/side-nav.h @@ -12,4 +12,6 @@ Ui::Child sidenavTree(Mdi::Icon icon, String title, Ui::Slot child); Ui::Child sidenavItem(bool selected, Ui::OnPress onPress, Mdi::Icon icon, String title); +Ui::Child sidenavTitle(String title); + } // namespace Karm::Kira diff --git a/src/vendors/libs/karm-kira/titlebar.cpp b/src/vendors/libs/karm-kira/titlebar.cpp new file mode 100644 index 0000000..f6ff667 --- /dev/null +++ b/src/vendors/libs/karm-kira/titlebar.cpp @@ -0,0 +1,67 @@ +#include +#include +#include +#include + +#include "about-dialog.h" +#include "titlebar.h" + +namespace Karm::Kira { + +Ui::Child titlebarTitle(Mdi::Icon icon, String title) { + return Ui::button( + [title](auto &n) { + Ui::showDialog(n, Kr::aboutDialog(title)); + }, + Ui::ButtonStyle::subtle(), icon, title + ); +} + +Ui::Child titlebarControls(TitlebarStyle style) { + return Ui::hflow( + 4, + Ui::button( + Ui::bindBubble(), + Ui::ButtonStyle::subtle(), + Mdi::MINUS + ) | Ui::cond(style == TitlebarStyle::DEFAULT), + Ui::button( + Ui::bindBubble(), + Ui::ButtonStyle::subtle(), + Mdi::CROP_SQUARE + ) | Ui::cond(style == TitlebarStyle::DEFAULT), + Ui::button( + Ui::bindBubble(), + Ui::ButtonStyle::subtle(), + Mdi::CLOSE + ) + ); +} + +Ui::Child titlebarContent(Ui::Children children) { + return Ui::hflow( + 4, + children + ) | + Ui::insets(8) | + Ui::dragRegion() | + Ui::box({.backgroundFill = Ui::GRAY900}); +} + +Ui::Child titlebar(Mdi::Icon icon, String title, TitlebarStyle style) { + return titlebarContent({ + titlebarTitle(icon, title), + Ui::grow(NONE), + titlebarControls(style), + }); +} + +Ui::Child titlebar(Mdi::Icon icon, String title, Ui::Child middle, TitlebarStyle style) { + return titlebarContent({ + titlebarTitle(icon, title), + middle | Ui::grow(), + titlebarControls(style), + }); +} + +} // namespace Karm::Kira diff --git a/src/vendors/libs/karm-kira/titlebar.h b/src/vendors/libs/karm-kira/titlebar.h new file mode 100644 index 0000000..928d5bf --- /dev/null +++ b/src/vendors/libs/karm-kira/titlebar.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +#include "_prelude.h" + +namespace Karm::Kira { + +enum struct TitlebarStyle { + DEFAULT, + FIXED, + DIALOG, +}; + +Ui::Child titlebarTitle(Mdi::Icon icon, String title); + +Ui::Child titlebarControls(TitlebarStyle style = TitlebarStyle::DEFAULT); + +Ui::Child titlebarContent(Ui::Children children); + +Ui::Child titlebar(Mdi::Icon icon, String title, TitlebarStyle style = TitlebarStyle::DEFAULT); + +Ui::Child titlebar(Mdi::Icon icon, String title, Ui::Child middle, TitlebarStyle style = TitlebarStyle::DEFAULT); + +} // namespace Karm::Kira diff --git a/src/vendors/libs/karm-kira/toolbar.cpp b/src/vendors/libs/karm-kira/toolbar.cpp new file mode 100644 index 0000000..3f62d8d --- /dev/null +++ b/src/vendors/libs/karm-kira/toolbar.cpp @@ -0,0 +1,25 @@ +#include + +#include "toolbar.h" + +namespace Karm::Kira { + +Ui::Child toolbar(Ui::Children children) { + return Ui::vflow( + Ui::hflow(4, children) | + Ui::insets(8) | + Ui::box({.backgroundFill = Ui::GRAY900}), + Ui::separator() + ); +} + +Ui::Child bottombar(Ui::Children children) { + return Ui::vflow( + Ui::separator(), + Ui::hflow(4, children) | + Ui::insets(8) | + Ui::box({.backgroundFill = Ui::GRAY900}) + ); +} + +} // namespace Karm::Kira diff --git a/src/vendors/libs/karm-kira/toolbar.h b/src/vendors/libs/karm-kira/toolbar.h new file mode 100644 index 0000000..23ad38e --- /dev/null +++ b/src/vendors/libs/karm-kira/toolbar.h @@ -0,0 +1,15 @@ +#pragma once + +#pragma once + +#include + +#include "_prelude.h" + +namespace Karm::Kira { + +Ui::Child toolbar(Ui::Children children); + +Ui::Child bottombar(Ui::Children children); + +} // namespace Karm::Kira diff --git a/src/vendors/libs/karm-media/icon.h b/src/vendors/libs/karm-media/icon.h index 7175d7d..e43da4c 100644 --- a/src/vendors/libs/karm-media/icon.h +++ b/src/vendors/libs/karm-media/icon.h @@ -1,7 +1,7 @@ #pragma once +#include #include -#include namespace Karm::Media { diff --git a/src/vendors/libs/karm-media/manifest.json b/src/vendors/libs/karm-media/manifest.json index dfaaedb..cb05335 100644 --- a/src/vendors/libs/karm-media/manifest.json +++ b/src/vendors/libs/karm-media/manifest.json @@ -5,6 +5,6 @@ "description": "A media loader library", "requires": [ "karm-text", - "mdi-spec" + "fonts-mdi" ] } diff --git a/src/vendors/libs/karm-mime/mime.h b/src/vendors/libs/karm-mime/mime.h index e92144e..9f23bc7 100644 --- a/src/vendors/libs/karm-mime/mime.h +++ b/src/vendors/libs/karm-mime/mime.h @@ -1,9 +1,9 @@ #pragma once +#include #include #include #include -#include namespace Karm::Mime { diff --git a/src/vendors/libs/karm-sys/context.h b/src/vendors/libs/karm-sys/context.h index 24236d9..355cced 100644 --- a/src/vendors/libs/karm-sys/context.h +++ b/src/vendors/libs/karm-sys/context.h @@ -51,9 +51,8 @@ struct ArgsHook : } Str operator[](usize i) const { - if (i >= len()) { - panic("out of range"); - } + if (i >= len()) + panic("index out of bounds"); return _argv[i + 1]; } @@ -69,17 +68,6 @@ inline auto &useArgs(Context &ctx = globalContext()) { return ctx.use(); } -enum struct FormFactor { - DESKTOP, - MOBILE, -}; - -inline FormFactor useFormFactor(Context &ctx = globalContext()) { - if (useArgs(ctx).has("--mobile")) - return FormFactor::MOBILE; - return FormFactor::DESKTOP; -} - } // namespace Karm::Sys Async::Task<> entryPointAsync(Sys::Context &); diff --git a/src/vendors/libs/karm-ui/app.cpp b/src/vendors/libs/karm-ui/app.cpp new file mode 100644 index 0000000..53b55f5 --- /dev/null +++ b/src/vendors/libs/karm-ui/app.cpp @@ -0,0 +1,74 @@ +#include "app.h" + +#include "_embed.h" + +#include "host.h" +#include "input.h" +#include "layout.h" + +namespace Karm::Ui { + +Child inspector(Child child) { + return hflow( + child | Ui::grow(), + separator(), + vflow( + 4, + icon(Mdi::FLASK, 24, GRAY600) | Ui::insets(6) | Ui::center(), + separator(), + button( + [](auto &n) { + debugShowLayoutBounds = !debugShowLayoutBounds; + Ui::shouldLayout(n); + }, + ButtonStyle::subtle(), + Mdi::RULER_SQUARE + ), + button( + [](auto &n) { + debugShowRepaintBounds = !debugShowRepaintBounds; + Ui::shouldLayout(n); + }, + ButtonStyle::subtle(), + Mdi::BRUSH + ), + button( + [](auto &n) { + debugShowEmptyBounds = !debugShowEmptyBounds; + Ui::shouldLayout(n); + }, + ButtonStyle::subtle(), + Mdi::BORDER_NONE_VARIANT + ), + button( + [](auto &n) { + debugShowScrollBounds = !debugShowScrollBounds; + Ui::shouldLayout(n); + }, + ButtonStyle::subtle(), + Mdi::ARROW_UP_DOWN + ), + button( + [](auto &n) { + debugShowPerfGraph = !debugShowPerfGraph; + Ui::shouldLayout(n); + }, + ButtonStyle::subtle(), + Mdi::CHART_HISTOGRAM + ) + ) | + Ui::insets(4) | + Ui::box({ + .backgroundFill = GRAY800, + }) + ); +} + +Res<> runApp(Sys::Context &ctx, Child root) { + auto &args = useArgs(ctx); + if (args.has("--debug")) + root = root | inspector; + return try$(_Embed::makeHost(root))->run(); +} + +} // namespace Karm::Ui diff --git a/src/vendors/libs/karm-ui/app.h b/src/vendors/libs/karm-ui/app.h index 800acad..a7f2531 100644 --- a/src/vendors/libs/karm-ui/app.h +++ b/src/vendors/libs/karm-ui/app.h @@ -2,78 +2,12 @@ #include -#include "_embed.h" - -#include "host.h" -#include "input.h" -#include "layout.h" -#include "reducer.h" +#include "node.h" namespace Karm::Ui { -Child inspector(Child child) { - return hflow( - child | Ui::grow(), - separator(), - vflow( - 4, - icon(Mdi::FLASK, 24, GRAY600) | Ui::insets(6) | Ui::center(), - separator(), - button( - [](auto &n) { - debugShowLayoutBounds = !debugShowLayoutBounds; - Ui::shouldLayout(n); - }, - ButtonStyle::subtle(), - Mdi::RULER_SQUARE - ), - button( - [](auto &n) { - debugShowRepaintBounds = !debugShowRepaintBounds; - Ui::shouldLayout(n); - }, - ButtonStyle::subtle(), - Mdi::BRUSH - ), - button( - [](auto &n) { - debugShowEmptyBounds = !debugShowEmptyBounds; - Ui::shouldLayout(n); - }, - ButtonStyle::subtle(), - Mdi::BORDER_NONE_VARIANT - ), - button( - [](auto &n) { - debugShowScrollBounds = !debugShowScrollBounds; - Ui::shouldLayout(n); - }, - ButtonStyle::subtle(), - Mdi::ARROW_UP_DOWN - ), - button( - [](auto &n) { - debugShowPerfGraph = !debugShowPerfGraph; - Ui::shouldLayout(n); - }, - ButtonStyle::subtle(), - Mdi::CHART_HISTOGRAM - ) - ) | - Ui::insets(4) | - Ui::box({ - .backgroundFill = GRAY800, - }) - ); -} +Child inspector(Child child); -inline Res<> runApp(Sys::Context &ctx, Child root) { - auto &args = useArgs(ctx); - if (args.has("--debug")) { - root = inspector(root); - } - auto host = try$(_Embed::makeHost(root)); - return host->run(); -} +Res<> runApp(Sys::Context &ctx, Child root); } // namespace Karm::Ui diff --git a/src/vendors/specs/mdi/manifest.json b/src/vendors/specs/mdi/manifest.json deleted file mode 100644 index 87c6688..0000000 --- a/src/vendors/specs/mdi/manifest.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "$schema": "https://schemas.cute.engineering/stable/cutekit.manifest.component.v1", - "id": "mdi-spec", - "type": "lib", - "description": "Material Design Icons", - "requires": [ - "karm-base", - "fonts-mdi" - ] -}