1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
# Widget
## Gtk3
### Additional widget properties
These are properties that Astal additionally adds to Gtk.Widgets
- class_name: `string` - List of class CSS selectors separated by white space.
- css: `string` - Inline CSS. e.g `label { color: white; }`. If no selector is specified `*` will be assumed. e.g `color: white;` will be inferred as `* { color: white; }`.
- cursor: `string` - Cursor style when hovering over widgets that have hover states, e.g it won't work on labels. [list of valid values](https://docs.gtk.org/gdk3/ctor.Cursor.new_from_name.html).
- click_through: `boolean` - Lets click events through.
To have a full list of available properties, reference the documentation of the widget.
- [Astal3 widgets](https://aylur.github.io/libastal/astal3/index.html#classes)
- [Gtk widgets](https://docs.gtk.org/gtk3/#classes)
### Additional widget methods
#### setup
`setup` is a convenience prop to remove the need to predefine widgets
before returning them in cases where a reference is needed.
without `setup`
```lua
local function MyWidget()
local button = Widget.Button()
-- setup button
return button
end
```
using `setup`
```lua
local function MyWidget()
return Widget.Button({
setup = function(self)
-- setup button
end,
})
end
```
#### hook
Shorthand for connecting and disconnecting to [Subscribable and Connectable](./binding#subscribable-and-connectable-interface) objects.
without `hook`
```lua
local function MyWidget()
local id = gobject.on_signal:connect(callback)
local unsub = variable:subscribe(callback)
return Widget.Box({
on_destroy = function()
GObject.signal_handler_disconnect(gobject, id)
unsub()
end,
})
end
```
with `hook`
```lua
local function MyWidget()
return Widget.Box({
setup = function(self)
self:hook(gobject, "signal", callback)
self:hook(variable, callback)
end,
})
end
```
#### toggle_class_name
Toggle class names based on a condition.
```lua
local function MyWidget()
return Widget.Box({
setup = function(self)
self:toggle_class_name("classname", some_condition)
end,
})
end
```
### How to use non builtin Gtk widgets
Using the `astalify` function you can wrap widgets
to behave like builtin widgets.
It will apply the following:
- set `visible` to true by default (Gtk3 widgets are invisible by default)
- make gobject properties accept and consume `Binding` objects
- add properties and methods listed above
```lua
local astal = require("astal.gtk3")
local astalify = astal.astalify
local Gtk = astal.Gtk
local Gdk = astal.Gdk
local ColorButton = astalify(Gtk.ColorButton)
local function MyWidget()
return ColorButton({
setup = function(self)
-- setup ColorButton instance
end,
use_alpha = true,
rgba = Gdk.RGBA({
red = 1,
green = 0,
blue = 0,
alpha = 0.5,
}),
on_color_set = function(self)
print(self.rgba:to_string())
end
})
end
```
### Builtin Widgets
You can check the [source code](https://github.com/Aylur/astal/blob/main/lang/lua/astal/gtk3/widget.lua) to have a full list of builtin widgets.
These widgets are available by default in Lua.
- Box: [Astal.Box](https://aylur.github.io/libastal/astal3/class.Box.html)
- Button: [Astal.Button](https://aylur.github.io/libastal/astal3/class.Button.html)
- CenterBox: [Astal.CenterBox](https://aylur.github.io/libastal/astal3/class.CenterBox.html)
- CircularProgress: [Astal.CircularProgress](https://aylur.github.io/libastal/astal3/class.CircularProgress.html)
- DrawingArea: [Gtk.DrawingArea](https://docs.gtk.org/gtk3/class.DrawingArea.html)
- Entry: [Gtk.Entry](https://docs.gtk.org/gtk3/class.Entry.html)
- Eventbox: [Astal.EventBox](https://aylur.github.io/libastal/astal3/class.EventBox.html)
- Icon: [Astal.Icon](https://aylur.github.io/libastal/astal3/class.Icon.html)
- Label: [Astal.Label](https://aylur.github.io/libastal/astal3/class.Label.html)
- Levelbar: [Astal.LevelBar](https://aylur.github.io/libastal/astal3/class.LevelBar.html)
- Overlay: [Astal.Overlay](https://aylur.github.io/libastal/astal3/class.Overlay.html)
- Revealer: [Gtk.Revealer](https://docs.gtk.org/gtk3/class.Revealer.html)
- Scrollable: [Astal.Scrollable](https://aylur.github.io/libastal/astal3/class.Scrollable.html)
- Slider: [Astal.Slider](https://aylur.github.io/libastal/astal3/class.Slider.html)
- Stack: [Astal.Stack](https://aylur.github.io/libastal/astal3/class.Stack.html)
- Switch: [Gtk.Switch](https://docs.gtk.org/gtk3/class.Switch.html)
- Window: [Astal.Window](https://aylur.github.io/libastal/astal3/class.Window.html)
## Gtk4
🚧 Work in Progress 🚧
|