Widgets
Widget
functions return an instance of Gtk.Widget.
Most common widgets are subclassed and have a few additional properties.
These widgets have some additional properties on top of the base Gtk.Widget ones:
Property | Type | Description |
---|---|---|
class-name | string | List of class CSS selectors separated by white space. |
class-names | Array<string> | List of class CSS selectors. |
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; } . |
hpack | string | Horizontal alignment, behaves like halign . halign takes an enum, but for convenience hpack can be given with a string, so one of "start" , "center" , "end" , "fill" . |
vpack | string | Vertical alignment. |
cursor | string | Cursor style when hovering over widgets that have hover states, e.g it won’t work on labels. list of valid values. |
attribute | any | Any additional attributes on self |
setup | (self) => void | A callback function to execute on self |
Setup property
setup
is a convenience prop to have imperative code inside declarative blocks
without setup
using setup
Attribute property
for attaching additional attributes on widgets Object.assign
or
the attribute
property can be used
using attribute
has the benefit of it being a gobject
which means it will signal notify::attribute
when it changes
keep in mind that attribute
will only signal if its value changes
Common Gtk properties
Some common Gtk.Widget properties you might want for example
Property | Type | Description |
---|---|---|
hexpand | boolean | Expand horizontally. |
vexpand | boolean | Expand vertically. |
sensitive | boolean | Makes the widget interactable. |
tooltip-text | string | Tooltip popup when the widget is hovered over. |
visible | boolean | Visibility of the widget. Setting this to false doesn’t have any effect if the parent container calls show_all() , for example when you set a Box’s children dynamically. |
toggleClassName
If you don’t want to mutate the classNames
array,
there is toggleClassName
: (name: string, enable: boolean) => void
The properties listed here are just the additional properties on top of their base Gtk.Widget classes. Refer to the Gtk3 docs for the rest of them.
Window
subclass of Gtk.Window
the toplevel widget that holds everything
Property | Type | Description |
---|---|---|
child | Widget | |
name | string | Name of the window. This has to be unique, if you pass it in config. This will also be the name of the layer. |
anchor | string[] | Valid values are "top" , "bottom" , "left" , "right" . Anchor points of the window. Leave it empty to make it centered. |
exclusivity | string | Specify if the compositor should reserve space for the window automatically or how the window should interact with windows that do. Possible values: exclusive (space should be reserved), normal (the window should move if occluding another), ignore (the window should not be moved). Default: normal . |
layer | string | Valid values are "overlay" , "top" , "bottom" , "background" . It is "top" by default. |
margins | number[] | Corresponds to CSS notation: [TOP, RIGHT, BOTTOM, LEFT] , also [0, 6] would have 0 margin on the top and bottom and would have 6 on the right and left. |
monitor | number | Which monitor to show the window on. If it is left undefined the window will show on the currently focused monitor. |
keymode | string | Valid values are "none" , "on-demand" : can receive keyboard input if focused, "exclusive" : steal keyboard input on top and overlay layers |
gdkmonitor | Gdk.Monitor | alternative to monitor |
Box
subclass of Gtk.Box
the main container widget
Property | Type | Description |
---|---|---|
vertical | bool | setting vertical: true is the same as orientation: 1 |
children | Widget[] | List of child widgets. |
Button
subclass of Gtk.Button
on-clicked
will be executed on Enter
if the button and its window has focus
Property | Type |
---|---|
child | Widget |
on-clicked | () => void |
on-primary-click | (event: Gdk.Event) => boolean |
on-secondary-click | (event: Gdk.Event) => boolean |
on-middle-click | (event: Gdk.Event) => boolean |
on-primary-click-release | (event: Gdk.Event) => boolean |
on-secondary-click-release | (event: Gdk.Event) => boolean |
on-middle-click-release | (event: Gdk.Event) => boolean |
on-hover | (event: Gdk.Event) => boolean |
on-hover-lost | (event: Gdk.Event) => boolean |
on-scroll-up | (event: Gdk.Event) => boolean |
on-scroll-down | (event: Gdk.Event) => boolean |
Calendar
subclass of Gtk.Calendar
Property | Type | Description |
---|---|---|
date | [number, number, number] | readonly [year, month, day] |
detail | (number, number, number) => string | null | |
on-day-selected | () => void |
CenterBox
subclass of Gtk.Box
Property | Type | Description |
---|---|---|
vertical | bool | setting vertical: true is the same as orientation: 1 |
start-widget | Gtk.Widget | |
center-widget | Gtk.Widget | |
end-widget | Gtk.Widget |
CircularProgress
subclass of Gtk.Bin
Property | Type | Description |
---|---|---|
start-at | number | Number between 0 and 1, e.g 0.75 is the top |
end-at | number | Number between 0 and 1 |
inverted | boolean | |
rounded | boolean | Wether the progress bar should have rounded ends |
value | number | Number between 0 and 1 |
ColorButton
subclass of Gtk.ColorButton
Property | Type |
---|---|
on-color-set | () => void |
DrawingArea
subclass of Gtk.DrawingArea
Property | Type |
---|---|
draw-fn | (cr: Cairo.Context, width: number, height: number) => void |
Entry
subclass of Gtk.Entry
Property | Type |
---|---|
on-change | () => void |
on-accept | () => void |
EventBox
subclass of Gtk.EventBox
Property | Type |
---|---|
child | Widget |
on-primary-click | (event: Gdk.Event) => boolean |
on-secondary-click | (event: Gdk.Event) => boolean |
on-middle-click | (event: Gdk.Event) => boolean |
on-primary-click-release | (event: Gdk.Event) => boolean |
on-secondary-click-release | (event: Gdk.Event) => boolean |
on-middle-click-release | (event: Gdk.Event) => boolean |
on-hover | (event: Gdk.Event) => boolean |
on-hover-lost | (event: Gdk.Event) => boolean |
on-scroll-up | (event: Gdk.Event) => boolean |
on-scroll-down | (event: Gdk.Event) => boolean |
FileChooserButton
subclass of Gtk.FileChooserButton
Property | Type | Description |
---|---|---|
on-file-set | () => void | |
uri | () => void | convenience getter for get_uri |
uris | () => void | convenience getter for get_uris |
Fixed
subclass of Gtk.Fixed
FlowBox
subclass of Gtk.FlowBox
FontButton
subclass of Gtk.FontButton
Property | Type | Description |
---|---|---|
on-font-set | () => void |
Icon
subclass of Gtk.Image
Property | Type | Description |
---|---|---|
icon | string | Name of an icon or path to a file |
size | number | Forced size |
Label
subclass of Gtk.Label
Property | Type | Description |
---|---|---|
justification | string | Valid values are "left" , "center" , "right" , "fill" . Same as justify but represented as a string instead of enum. |
truncate | string | Valid values are "none" , "start" , "middle" , "end" . Same as ellipsize but represented as a string instead of enum. |
LevelBar
subclass of Gtk.LevelBar
Property | Type | Description |
---|---|---|
bar-mode | string | Valid values are "continuous" , "discrete" . Same as mode but represented as a string instead of enum. |
vertical | bool | setting vertical: true is the same as orientation: 1 |
ListBox
subclass of Gtk.ListBox
Menu
subclass of Gtk.Menu
Property | Type |
---|---|
children | MenuItem[] |
on-popup | (flipped_rect: void, final_rect: void, flipped_x: boolean, flipped_y: boolean) => void |
on-move-scroll | (scroll_type: Gtk.ScrollType) => void |
MenuBar
subclass of Gtk.MenuBar
MenuItem
subclass of Gtk.MenuItem
Property | Type |
---|---|
child | Widget |
on-activate | () => boolean |
on-select | () => boolean |
on-deselect | () => boolean |
Overlay
subclass of Gtk.Overlay Takes the size of its first child, then places subsequent children on top of each other and won’t render them outside the container.
Property | Type | Description |
---|---|---|
child | Widget | Child which will determine the size of the overlay |
overlays | Widget[] | Overlayed children |
pass-through | boolean | Whether the overlay childs should pass the input through |
ProgressBar
subclass of Gtk.ProgressBar
Property | Type | Description |
---|---|---|
vertical | bool | Setting vertical: true is the same as orientation: 1 |
value | number | Same as ProgressBar.fraction |
Revealer
subclass of Gtk.Revealer
Property | Type | Description |
---|---|---|
child | Widget | |
transition | string | Valid values are "none" , "crossfade" , "slide_left" , "slide_right" , "slide_down" , "slide_up" . This is transitionType represented as a string instead of enum. |
Scrollable
subclass of Gtk.ScrolledWindow
Property | Type | Description |
---|---|---|
child | Widget | |
hscroll | string | Valid values are "always , "automatic" , "external" , "never" . |
vscroll | string | Valid values are "always , "automatic" , "external" , "never" . |
Separator
subclass of Gtk.Separator
Property | Type | Description |
---|---|---|
vertical | bool | Setting vertical: true is the same as orientation: 1 |
Slider
subclass of Gtk.Scale
Property | Type | Description |
---|---|---|
vertical | bool | Setting vertical: true is the same as orientation: 1 |
value | number | |
min | number | |
max | number | |
marks | tuple or number | where tuple is [number, string?, Position?] , Position is "top" , "left , "right , "bottom" |
on-change | (event: Gdk.Event) => void |
SpinButton
subclass of Gtk.SpinButton
Property | Type |
---|---|
on-value-changed | () => void |
range | [min: number, max: number] |
increments | [step: number, page: number] |
Spinner
subclass of Gtk.Spinner spinning icon showing that something is loading
Stack
subclass of Gtk.Stack
Property | Type | Description |
---|---|---|
children | { [string]: Widget } | name, Widget key-value pairs |
shown | string | Name of the widget to show. This can’t be set on construction, instead the first given widget will be shown. |
transition | string | transitionType represented as a string. Valid values are none , crossfade , slide_right , slide_left , slide_up , slide_down , slide_left_right , slide_up_down , over_up , over_down , over_left , over_right , under_up , under_down , under_left , under_right , over_up_down , over_down_up , over_left_right , over_right_left |
Switch
subclass of Gtk.Switch
Property | Type |
---|---|
on-activate | () => void |
ToggleButton
subclass of Gtk.ToggleButton
Property | Type |
---|---|
on-toggled | () => void |