summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAylur <[email protected]>2024-06-05 13:16:28 +0200
committerAylur <[email protected]>2024-06-05 13:16:28 +0200
commite675e9784a20bb07d33f0feb3724a2a1f072f52b (patch)
treee9593e13571b6ec1fab8462721e61f34eee924ff
parentca74fb7ad016f9ceee3756a973baa2d87a8aa1d6 (diff)
more widget subclasses
* levelbar * overlay * scrollable * slider
-rw-r--r--gjs/src/widgets.ts89
-rw-r--r--lua/astal/widget.lua17
-rw-r--r--python/astal/widget.py27
-rw-r--r--src/meson.build6
-rw-r--r--src/widget/box.vala1
-rw-r--r--src/widget/centerbox.vala11
-rw-r--r--src/widget/circularprogress.vala1
-rw-r--r--src/widget/icon.vala4
-rw-r--r--src/widget/levelbar.vala15
-rw-r--r--src/widget/overlay.vala50
-rw-r--r--src/widget/scrollable.vala42
-rw-r--r--src/widget/slider.vala59
12 files changed, 295 insertions, 27 deletions
diff --git a/gjs/src/widgets.ts b/gjs/src/widgets.ts
index e8adf65..c731b02 100644
--- a/gjs/src/widgets.ts
+++ b/gjs/src/widgets.ts
@@ -4,32 +4,89 @@ import astalify, { type ConstructProps } from "./astalify.js"
export { astalify, ConstructProps }
-// Label
-export const Label = astalify<typeof Gtk.Label, LabelProps, "Label">(Gtk.Label)
-export type LabelProps = ConstructProps<typeof Gtk.Label, Gtk.Label.ConstructorProperties>
-
-// Icon
-export const Icon = astalify<typeof Astal.Icon, IconProps, "Icon">(Astal.Icon)
-export type IconProps = ConstructProps<typeof Astal.Icon, Astal.Icon.ConstructorProperties>
+// Box
+export const Box = astalify<typeof Astal.Box, BoxProps, "Box">(Astal.Box)
+export type BoxProps = ConstructProps<typeof Astal.Box, Astal.Box.ConstructorProperties>
// Button
export const Button = astalify<typeof Astal.Button, ButtonProps, "Button">(Astal.Button)
export type ButtonProps = ConstructProps<typeof Astal.Button, Astal.Button.ConstructorProperties, {
onClicked: []
+ onClick: [event: Astal.ClickEvent],
+ onClickRelease: [event: Astal.ClickEvent],
+ onHover: [event: Astal.HoverEvent],
+ onHoverLost: [event: Astal.HoverEvent],
+ onScroll: [event: Astal.ScrollEvent],
}>
-// Window
-export const Window = astalify<typeof Astal.Window, WindowProps, "Window">(Astal.Window)
-export type WindowProps = ConstructProps<typeof Astal.Window, Astal.Window.ConstructorProperties>
-
-// Box
-export const Box = astalify<typeof Astal.Box, BoxProps, "Box">(Astal.Box)
-export type BoxProps = ConstructProps<typeof Astal.Box, Astal.Box.ConstructorProperties>
-
// CenterBox
export const CenterBox = astalify<typeof Astal.CenterBox, CenterBoxProps, "CenterBox">(Astal.CenterBox)
export type CenterBoxProps = ConstructProps<typeof Astal.CenterBox, Astal.CenterBox.ConstructorProperties>
+// TODO: CircularProgress
+
+// DrawingArea
+export const DrawingArea = astalify<typeof Gtk.DrawingArea, DrawingAreaProps, "DrawingArea">(Gtk.DrawingArea)
+export type DrawingAreaProps = ConstructProps<typeof Gtk.DrawingArea, Gtk.DrawingArea.ConstructorProperties, {
+ onDraw: [cr: any] // TODO: cairo types
+}>
+
+// Entry
+export const Entry = astalify<typeof Gtk.Entry, EntryProps, "Entry">(Gtk.Entry)
+export type EntryProps = ConstructProps<typeof Gtk.Entry, Gtk.Entry.ConstructorProperties, {
+ onChanged: []
+ onActivate: []
+}>
+
// EventBox
export const EventBox = astalify<typeof Astal.EventBox, EventBoxProps, "EventBox">(Astal.EventBox)
-export type EventBoxProps = ConstructProps<typeof Astal.EventBox, Astal.EventBox.ConstructorProperties>
+export type EventBoxProps = ConstructProps<typeof Astal.EventBox, Astal.EventBox.ConstructorProperties, {
+ onClick: [event: Astal.ClickEvent],
+ onClickRelease: [event: Astal.ClickEvent],
+ onHover: [event: Astal.HoverEvent],
+ onHoverLost: [event: Astal.HoverEvent],
+ onScroll: [event: Astal.ScrollEvent],
+}>
+
+// TODO: Fixed
+// TODO: FlowBox
+
+// Icon
+export const Icon = astalify<typeof Astal.Icon, IconProps, "Icon">(Astal.Icon)
+export type IconProps = ConstructProps<typeof Astal.Icon, Astal.Icon.ConstructorProperties>
+
+// Label
+export const Label = astalify<typeof Gtk.Label, LabelProps, "Label">(Gtk.Label)
+export type LabelProps = ConstructProps<typeof Gtk.Label, Gtk.Label.ConstructorProperties>
+
+// LevelBar
+export const LevelBar = astalify<typeof Astal.LevelBar, LevelBarProps, "LevelBar">(Astal.LevelBar)
+export type LevelBarProps = ConstructProps<typeof Astal.LevelBar, Astal.LevelBar.ConstructorProperties>
+
+// TODO: ListBox
+
+// Overlay
+export const Overlay = astalify<typeof Astal.Overlay, OverlayProps, "Overlay">(Astal.Overlay)
+export type OverlayProps = ConstructProps<typeof Astal.Overlay, Astal.Overlay.ConstructorProperties>
+
+// Revealer
+export const Revealer = astalify<typeof Gtk.Revealer, RevealerProps, "Revealer">(Gtk.Revealer)
+export type RevealerProps = ConstructProps<typeof Gtk.Revealer, Gtk.Revealer.ConstructorProperties>
+
+// Scrollable
+export const Scrollable = astalify<typeof Astal.Scrollable, ScrollableProps, "Scrollable">(Astal.Scrollable)
+export type ScrollableProps = ConstructProps<typeof Astal.Scrollable, Astal.Scrollable.ConstructorProperties>
+
+// Slider
+export const Slider = astalify<typeof Astal.Slider, SliderProps, "Slider">(Astal.Slider)
+export type SliderProps = ConstructProps<typeof Astal.Slider, Astal.Slider.ConstructorProperties>
+
+// TODO: Stack
+
+// Switch
+export const Switch = astalify<typeof Gtk.Switch, SwitchProps, "Switch">(Gtk.Switch)
+export type SwitchProps = ConstructProps<typeof Gtk.Switch, Gtk.Switch.ConstructorProperties>
+
+// Window
+export const Window = astalify<typeof Astal.Window, WindowProps, "Window">(Astal.Window)
+export type WindowProps = ConstructProps<typeof Astal.Window, Astal.Window.ConstructorProperties>
diff --git a/lua/astal/widget.lua b/lua/astal/widget.lua
index 7be240f..8045db1 100644
--- a/lua/astal/widget.lua
+++ b/lua/astal/widget.lua
@@ -137,10 +137,23 @@ local Widget = {
Box = astalify(Astal.Box),
Button = astalify(Astal.Button),
CenterBox = astalify(Astal.CenterBox),
- Label = astalify(Gtk.Label),
+ -- TODO: CircularProgress
+ DrawingArea = astalify(Gtk.DrawingArea),
+ Entry = astalify(Gtk.Entry),
+ EventBox = astalify(Astal.EventBox),
+ -- TODO: Fixed
+ -- TODO: FlowBox
Icon = astalify(Astal.Icon),
+ Label = astalify(Gtk.Label),
+ LevelBar = astalify(Astal.LevelBar),
+ -- TODO: ListBox
+ Overlay = astalify(Astal.Overlay),
+ Revealer = astalify(Gtk.Revealer),
+ Scrollable = astalify(Astal.Scrollable),
+ Slider = astalify(Astal.Slider),
+ -- TODO: Stack
+ Switch = astalify(Gtk.Switch),
Window = astalify(Astal.Window),
- EventBox = astalify(Astal.EventBox),
}
return setmetatable(Widget, {
diff --git a/python/astal/widget.py b/python/astal/widget.py
index 7a458bf..8f2285f 100644
--- a/python/astal/widget.py
+++ b/python/astal/widget.py
@@ -56,10 +56,23 @@ def astalify(ctor):
return widget
-Window = astalify(Astal.Window)
-Box = astalify(Astal.Box)
-Button = astalify(Astal.Button)
-CenterBox = astalify(Astal.CenterBox)
-Label = astalify(Gtk.Label)
-Icon = astalify(Astal.Icon)
-EventBox = astalify(Astal.EventBox)
+Box = astalify(Astal.Box),
+Button = astalify(Astal.Button),
+CenterBox = astalify(Astal.CenterBox),
+# TODO: CircularProgress
+DrawingArea = astalify(Gtk.DrawingArea),
+Entry = astalify(Gtk.Entry),
+EventBox = astalify(Astal.EventBox),
+# TODO: Fixed
+# TODO: FlowBox
+Icon = astalify(Astal.Icon),
+Label = astalify(Gtk.Label),
+LevelBar = astalify(Astal.LevelBar),
+# TODO: ListBox
+Overlay = astalify(Astal.Overlay),
+Revealer = astalify(Gtk.Revealer),
+Scrollable = astalify(Astal.Scrollable),
+Slider = astalify(Astal.Slider),
+# TODO: Stack
+Switch = astalify(Gtk.Switch),
+Window = astalify(Astal.Window),
diff --git a/src/meson.build b/src/meson.build
index f6b0db0..80e5a33 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -30,9 +30,13 @@ sources = [
'widget/box.vala',
'widget/button.vala',
'widget/centerbox.vala',
+ # 'widget/circularprogress.vala', # TODO: math lib -X -lm
'widget/eventbox.vala',
'widget/icon.vala',
- # 'widget/circularprogress.vala', # TODO: math lib -X -lm
+ 'widget/levelbar.vala',
+ 'widget/overlay.vala',
+ 'widget/scrollable.vala',
+ 'widget/slider.vala',
'widget/widget.vala',
'widget/window.vala',
'astal.vala',
diff --git a/src/widget/box.vala b/src/widget/box.vala
index 482948d..9993a38 100644
--- a/src/widget/box.vala
+++ b/src/widget/box.vala
@@ -1,5 +1,6 @@
namespace Astal {
public class Box : Gtk.Box {
+ [CCode (notify = false)]
public bool vertical {
get { return orientation == Gtk.Orientation.VERTICAL; }
set { orientation = value ? Gtk.Orientation.VERTICAL : Gtk.Orientation.HORIZONTAL; }
diff --git a/src/widget/centerbox.vala b/src/widget/centerbox.vala
index 5f41600..eedee9b 100644
--- a/src/widget/centerbox.vala
+++ b/src/widget/centerbox.vala
@@ -1,10 +1,21 @@
namespace Astal {
public class CenterBox : Gtk.Box {
+ [CCode (notify = false)]
public bool vertical {
get { return orientation == Gtk.Orientation.VERTICAL; }
set { orientation = value ? Gtk.Orientation.VERTICAL : Gtk.Orientation.HORIZONTAL; }
}
+ construct {
+ notify["orientation"].connect(() => {
+ notify_property("vertical");
+ });
+ }
+
+ static construct {
+ set_css_name("centerbox");
+ }
+
private Gtk.Widget _start_widget;
public Gtk.Widget start_widget {
get { return _start_widget; }
diff --git a/src/widget/circularprogress.vala b/src/widget/circularprogress.vala
index e96c4de..9cd3e26 100644
--- a/src/widget/circularprogress.vala
+++ b/src/widget/circularprogress.vala
@@ -20,7 +20,6 @@ public class CircularProgress : Gtk.Bin {
set_css_name("circular-progress");
}
-
public new void get_preferred_height(out int minh, out int nath) {
var val = get_style_context().get_property("min-height", Gtk.StateFlags.NORMAL);
if (val.get_int() <= 0) {
diff --git a/src/widget/icon.vala b/src/widget/icon.vala
index fc493da..5dffd9b 100644
--- a/src/widget/icon.vala
+++ b/src/widget/icon.vala
@@ -44,6 +44,10 @@ public class Icon : Gtk.Image {
}
}
+ static construct {
+ set_css_name("icon");
+ }
+
construct {
notify["icon"].connect(() => {
if(FileUtils.test(icon, GLib.FileTest.EXISTS))
diff --git a/src/widget/levelbar.vala b/src/widget/levelbar.vala
new file mode 100644
index 0000000..1db2cc7
--- /dev/null
+++ b/src/widget/levelbar.vala
@@ -0,0 +1,15 @@
+namespace Astal {
+public class LevelBar : Gtk.LevelBar {
+ [CCode (notify = false)]
+ public bool vertical {
+ get { return orientation == Gtk.Orientation.VERTICAL; }
+ set { orientation = value ? Gtk.Orientation.VERTICAL : Gtk.Orientation.HORIZONTAL; }
+ }
+
+ construct {
+ notify["orientation"].connect(() => {
+ notify_property("vertical");
+ });
+ }
+}
+}
diff --git a/src/widget/overlay.vala b/src/widget/overlay.vala
new file mode 100644
index 0000000..4833180
--- /dev/null
+++ b/src/widget/overlay.vala
@@ -0,0 +1,50 @@
+namespace Astal {
+public class Overlay : Gtk.Overlay {
+ public bool pass_through { get; set; }
+
+ public Gtk.Widget overlay {
+ get { return overlays.nth_data(0); }
+ set {
+ foreach (var ch in get_children())
+ remove(ch);
+
+ add_overlay(value);
+ }
+ }
+
+ public List<weak Gtk.Widget> overlays {
+ owned get { return get_children(); }
+ set {
+ foreach (var ch in get_children())
+ remove(ch);
+
+ foreach (var ch in value)
+ add_overlay(ch);
+ }
+ }
+
+ public void set_child(Gtk.Widget widget) {
+ var ch = get_child();
+ if (ch != null) {
+ remove(ch);
+ }
+ add(widget);
+ }
+
+ construct {
+ notify["pass-through"].connect(() => {
+ update_pass_through();
+ });
+ }
+
+ private void update_pass_through() {
+ foreach (var child in get_children())
+ set_overlay_pass_through(child, pass_through);
+ }
+
+ public new void add_overlay(Gtk.Widget widget) {
+ base.add_overlay(widget);
+ set_overlay_pass_through(widget, pass_through);
+ }
+}
+}
diff --git a/src/widget/scrollable.vala b/src/widget/scrollable.vala
new file mode 100644
index 0000000..1a0e081
--- /dev/null
+++ b/src/widget/scrollable.vala
@@ -0,0 +1,42 @@
+namespace Astal {
+public class Scrollable : Gtk.ScrolledWindow {
+ private Gtk.PolicyType _hscroll = Gtk.PolicyType.AUTOMATIC;
+ private Gtk.PolicyType _vscroll = Gtk.PolicyType.AUTOMATIC;
+
+ public Gtk.PolicyType hscroll {
+ get { return _hscroll; }
+ set {
+ _hscroll = value;
+ set_policy(value, vscroll);
+ }
+ }
+
+ public Gtk.PolicyType vscroll {
+ get { return _vscroll; }
+ set {
+ _vscroll = value;
+ set_policy(hscroll, value);
+ }
+ }
+
+ static construct {
+ set_css_name("scrollable");
+ }
+
+ construct {
+ if (hadjustment != null)
+ hadjustment = new Gtk.Adjustment(0,0,0,0,0,0);
+
+ if (vadjustment != null)
+ vadjustment = new Gtk.Adjustment(0,0,0,0,0,0);
+ }
+
+ public new Gtk.Widget get_child() {
+ var ch = base.get_child();
+ if (ch is Gtk.Viewport) {
+ return ch.get_child();
+ }
+ return ch;
+ }
+}
+}
diff --git a/src/widget/slider.vala b/src/widget/slider.vala
new file mode 100644
index 0000000..4c6cb88
--- /dev/null
+++ b/src/widget/slider.vala
@@ -0,0 +1,59 @@
+namespace Astal {
+public class Slider : Gtk.Scale {
+ [CCode (notify = false)]
+ public bool vertical {
+ get { return orientation == Gtk.Orientation.VERTICAL; }
+ set { orientation = value ? Gtk.Orientation.VERTICAL : Gtk.Orientation.HORIZONTAL; }
+ }
+
+ static construct {
+ set_css_name("slider");
+ }
+
+ construct {
+ if (adjustment == null)
+ adjustment = new Gtk.Adjustment(0,0,0,0,0,0);
+
+ notify["orientation"].connect(() => {
+ notify_property("vertical");
+ });
+
+ button_press_event.connect(() => { dragging = true; });
+ key_press_event.connect(() => { dragging = true; });
+ button_release_event.connect(() => { dragging = false; });
+ key_release_event.connect(() => { dragging = false; });
+ scroll_event.connect((event) => {
+ dragging = true;
+ if (event.delta_y > 0)
+ value -= step;
+ else
+ value += step;
+ dragging = false;
+ });
+ }
+
+ public bool dragging { get; private set; }
+
+ public double value {
+ get { return adjustment.value; }
+ set { adjustment.value = value; }
+ }
+
+ public double min {
+ get { return adjustment.lower; }
+ set { adjustment.lower = value; }
+ }
+
+ public double max {
+ get { return adjustment.upper; }
+ set { adjustment.upper = value; }
+ }
+
+ public double step {
+ get { return adjustment.step_increment; }
+ set { adjustment.step_increment = value; }
+ }
+
+ // TODO: marks
+}
+}