diff options
-rw-r--r-- | core/gjs/src/astalify.ts | 6 | ||||
-rw-r--r-- | core/gjs/src/jsx/jsx-runtime.ts | 2 | ||||
-rw-r--r-- | core/gjs/src/widgets.ts | 5 | ||||
-rw-r--r-- | core/lua/astal/widget.lua | 6 | ||||
-rw-r--r-- | core/src/meson.build | 1 | ||||
-rw-r--r-- | core/src/widget/box.vala | 2 | ||||
-rw-r--r-- | core/src/widget/stack.vala | 34 | ||||
-rw-r--r-- | docs/ags/first-widgets.md | 2 |
8 files changed, 51 insertions, 7 deletions
diff --git a/core/gjs/src/astalify.ts b/core/gjs/src/astalify.ts index be395ee..612239e 100644 --- a/core/gjs/src/astalify.ts +++ b/core/gjs/src/astalify.ts @@ -20,11 +20,15 @@ function setChildren(parent: Gtk.Widget, children: Gtk.Widget[]) { parent.remove(ch) } - // FIXME: add rest of the edge cases like Stack + // TODO: add more container types if (parent instanceof Astal.Box) { parent.set_children(children) } + else if (parent instanceof Astal.Stack) { + parent.set_children(children) + } + else if (parent instanceof Astal.CenterBox) { parent.startWidget = children[0] parent.centerWidget = children[1] diff --git a/core/gjs/src/jsx/jsx-runtime.ts b/core/gjs/src/jsx/jsx-runtime.ts index 02fd39d..73aaf63 100644 --- a/core/gjs/src/jsx/jsx-runtime.ts +++ b/core/gjs/src/jsx/jsx-runtime.ts @@ -49,7 +49,7 @@ const ctors = { revealer: Widget.Revealer, scrollable: Widget.Scrollable, slider: Widget.Slider, - // TODO: stack + stack: Widget.Stack, switch: Widget.Switch, window: Widget.Window, } diff --git a/core/gjs/src/widgets.ts b/core/gjs/src/widgets.ts index 0a71d8b..82d3b8f 100644 --- a/core/gjs/src/widgets.ts +++ b/core/gjs/src/widgets.ts @@ -100,7 +100,10 @@ export type SliderProps = ConstructProps<Astal.Slider, Astal.Slider.ConstructorP onDragged: [] }> -// TODO: Stack +// Stack +export type Stack = Widget<Astal.Stack> +export const Stack = astalify<typeof Astal.Stack, StackProps, "Stack">(Astal.Stack) +export type StackProps = ConstructProps<Astal.Stack, Astal.Stack.ConstructorProps> // Switch export type Switch = Widget<Gtk.Switch> diff --git a/core/lua/astal/widget.lua b/core/lua/astal/widget.lua index e2bd612..23b045f 100644 --- a/core/lua/astal/widget.lua +++ b/core/lua/astal/widget.lua @@ -62,9 +62,11 @@ local function set_children(parent, children) end end - -- FIXME: add rest of the edge cases like Stack + -- TODO: add more container types if Astal.Box:is_type_of(parent) then parent:set_children(children) + elseif Astal.Stack:is_type_of(parent) then + parent:set_children(children) elseif Astal.CenterBox:is_type_of(parent) then parent.start_widget = children[1] parent.center_widget = children[2] @@ -223,7 +225,7 @@ local Widget = { Revealer = astalify(Gtk.Revealer), Scrollable = astalify(Astal.Scrollable), Slider = astalify(Astal.Slider), - -- TODO: Stack + Stack = astalify(Astal.Stack), Switch = astalify(Gtk.Switch), Window = astalify(Astal.Window), } diff --git a/core/src/meson.build b/core/src/meson.build index 7cb7762..d7d3871 100644 --- a/core/src/meson.build +++ b/core/src/meson.build @@ -39,6 +39,7 @@ sources = [ 'widget/overlay.vala', 'widget/scrollable.vala', 'widget/slider.vala', + 'widget/stack.vala', 'widget/widget.vala', 'widget/window.vala', 'astal.vala', diff --git a/core/src/widget/box.vala b/core/src/widget/box.vala index 6bd1bcb..d522967 100644 --- a/core/src/widget/box.vala +++ b/core/src/widget/box.vala @@ -7,7 +7,7 @@ public class Box : Gtk.Box { } /** - * wether to implicity destroy previous children when setting them + * whether to implicity destroy previous children when setting them */ public bool no_implicit_destroy { get; set; default = false; } diff --git a/core/src/widget/stack.vala b/core/src/widget/stack.vala new file mode 100644 index 0000000..d1d345f --- /dev/null +++ b/core/src/widget/stack.vala @@ -0,0 +1,34 @@ +public class Astal.Switch : Gtk.Stack { + /** + * whether to implicity destroy previous children when setting them + */ + public bool no_implicit_destroy { get; set; default = false; } + + public string shown { + get { return visible_child_name; } + set { visible_child_name = value; } + } + + public List<weak Gtk.Widget> children { + set { _set_children(value); } + owned get { return get_children(); } + } + + private void _set_children(List<weak Gtk.Widget> arr) { + foreach(var child in get_children()) { + if (no_implicit_destroy) + remove(child); + else if (arr.find(child).length() == 0) + child.destroy(); + } + + var i = 0; + foreach(var child in arr) { + if (child.name != null) { + add_named(child, child.name); + } else { + add_named(child, (++i).to_string()); + } + } + } +} diff --git a/docs/ags/first-widgets.md b/docs/ags/first-widgets.md index f098586..1b18109 100644 --- a/docs/ags/first-widgets.md +++ b/docs/ags/first-widgets.md @@ -350,7 +350,7 @@ return <box> ``` :::warning -Only bind children of the `box` widget. Gtk does not cleanup widgets by default, +Only bind children of the `box` or the `stack` widget. Gtk does not cleanup widgets by default, they have to be explicitly destroyed. The box widget is a special container that will implicitly call `.destroy()` on its removed child widgets. You can disable this behavior by setting the `noImplicityDestroy` property. |