mirror of
https://github.com/zoriya/astal.git
synced 2025-12-06 06:06:10 +00:00
add: stack widget
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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),
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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; }
|
||||
|
||||
|
||||
34
core/src/widget/stack.vala
Normal file
34
core/src/widget/stack.vala
Normal file
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user