From 779ec440e209b01d3a44f9377af78653d197fdc8 Mon Sep 17 00:00:00 2001 From: Aylur Date: Thu, 7 Nov 2024 02:40:47 +0000 Subject: example: applauncher --- examples/js/applauncher/widget/Applauncher.scss | 45 +++++++++++++++ examples/js/applauncher/widget/Applauncher.tsx | 73 +++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 examples/js/applauncher/widget/Applauncher.scss create mode 100644 examples/js/applauncher/widget/Applauncher.tsx (limited to 'examples/js/applauncher/widget') diff --git a/examples/js/applauncher/widget/Applauncher.scss b/examples/js/applauncher/widget/Applauncher.scss new file mode 100644 index 0000000..86c5e87 --- /dev/null +++ b/examples/js/applauncher/widget/Applauncher.scss @@ -0,0 +1,45 @@ +@use "sass:string"; + +@function gtkalpha($c, $a) { + @return string.unquote("alpha(#{$c},#{$a})"); +} + +// https://gitlab.gnome.org/GNOME/gtk/-/blob/gtk-3-24/gtk/theme/Adwaita/_colors-public.scss +$fg-color: #{"@theme_fg_color"}; +$bg-color: #{"@theme_bg_color"}; + +window#launcher { + all: unset; + + box.Applauncher { + background-color: $bg-color; + border-radius: 11px; + margin: 1rem; + padding: .8rem; + box-shadow: 2px 3px 8px 0 gtkalpha(black, .4); + + entry { + margin-bottom: .8rem; + } + + button { + min-width: 0; + min-height: 0; + padding: .5rem; + + icon { + font-size: 3em; + margin-right: .3rem; + } + + label.name { + font-weight: bold; + font-size: 1.1em + } + + label.description { + color: gtkalpha($fg-color, .8); + } + } + } +} diff --git a/examples/js/applauncher/widget/Applauncher.tsx b/examples/js/applauncher/widget/Applauncher.tsx new file mode 100644 index 0000000..d92b5e3 --- /dev/null +++ b/examples/js/applauncher/widget/Applauncher.tsx @@ -0,0 +1,73 @@ +import Apps from "gi://AstalApps" +import { App, Astal, Gdk, Gtk } from "astal/gtk3" +import { Variable } from "astal" + +const MAX_ITEMS = 8 + +function AppButton({ app }: { app: Apps.Application }) { + return +} + +export default function Applauncher() { + const apps = new Apps.Apps() + const list = Variable(apps.get_list().slice(0, MAX_ITEMS)) + const hide = () => App.get_window("launcher")!.hide() + + function search(text: string) { + list.set(apps.fuzzy_query(text).slice(0, MAX_ITEMS)) + } + + return list.set(apps.get_list().slice(0, MAX_ITEMS))} + onKeyPressEvent={function (self, event: Gdk.Event) { + if (event.get_keyval()[1] === Gdk.KEY_Escape) + self.hide() + }}> + + + + + + search(text)} + /> + + {list(list => list.map(app => ( + + )))} + + l.length === 0)}> + + No match found + + + + + + + +} -- cgit v1.2.3 From 48b6b0742fb21a298985dc6c86605099e6d5abd1 Mon Sep 17 00:00:00 2001 From: Aylur Date: Fri, 8 Nov 2024 20:54:11 +0000 Subject: example: fix applauncher text reset --- examples/js/applauncher/widget/Applauncher.scss | 14 ++++++++++++++ examples/js/applauncher/widget/Applauncher.tsx | 24 ++++++++++++++---------- 2 files changed, 28 insertions(+), 10 deletions(-) (limited to 'examples/js/applauncher/widget') diff --git a/examples/js/applauncher/widget/Applauncher.scss b/examples/js/applauncher/widget/Applauncher.scss index 86c5e87..ae2453d 100644 --- a/examples/js/applauncher/widget/Applauncher.scss +++ b/examples/js/applauncher/widget/Applauncher.scss @@ -41,5 +41,19 @@ window#launcher { color: gtkalpha($fg-color, .8); } } + + box.not-found { + padding: 1rem; + + icon { + font-size: 6em; + color: gtkalpha($fg-color, .7); + } + + label { + color: gtkalpha($fg-color, .9); + font-size: 1.2em; + } + } } } diff --git a/examples/js/applauncher/widget/Applauncher.tsx b/examples/js/applauncher/widget/Applauncher.tsx index d92b5e3..f52780b 100644 --- a/examples/js/applauncher/widget/Applauncher.tsx +++ b/examples/js/applauncher/widget/Applauncher.tsx @@ -27,13 +27,12 @@ function AppButton({ app }: { app: Apps.Application }) { } export default function Applauncher() { + const { CENTER } = Gtk.Align const apps = new Apps.Apps() - const list = Variable(apps.get_list().slice(0, MAX_ITEMS)) - const hide = () => App.get_window("launcher")!.hide() - function search(text: string) { - list.set(apps.fuzzy_query(text).slice(0, MAX_ITEMS)) - } + const text = Variable("") + const list = text(text => apps.fuzzy_query(text).slice(0, MAX_ITEMS)) + const hide = () => App.get_window("launcher")!.hide() return list.set(apps.get_list().slice(0, MAX_ITEMS))} + onShow={() => text.set("")} onKeyPressEvent={function (self, event: Gdk.Event) { if (event.get_keyval()[1] === Gdk.KEY_Escape) self.hide() @@ -53,16 +52,21 @@ export default function Applauncher() { search(text)} + text={text()} + onChanged={self => text.set(self.text)} /> - {list(list => list.map(app => ( + {list.as(list => list.map(app => ( )))} - l.length === 0)}> + l.length === 0)}> - No match found + -- cgit v1.2.3 From 302fcae7ae0b58767518e6003d0a80966d7ca4bb Mon Sep 17 00:00:00 2001 From: Aylur Date: Fri, 8 Nov 2024 21:23:07 +0000 Subject: example(applauncher): hide on app launch --- examples/js/applauncher/widget/Applauncher.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'examples/js/applauncher/widget') diff --git a/examples/js/applauncher/widget/Applauncher.tsx b/examples/js/applauncher/widget/Applauncher.tsx index f52780b..c7bac68 100644 --- a/examples/js/applauncher/widget/Applauncher.tsx +++ b/examples/js/applauncher/widget/Applauncher.tsx @@ -4,8 +4,14 @@ import { Variable } from "astal" const MAX_ITEMS = 8 +function hide() { + App.get_window("launcher")!.hide() +} + function AppButton({ app }: { app: Apps.Application }) { - return