summaryrefslogtreecommitdiff
path: root/lib/astal/gtk3/src/widget/circularprogress.vala
diff options
context:
space:
mode:
authorkotontrion <[email protected]>2024-11-17 13:32:02 +0100
committerkotontrion <[email protected]>2024-11-17 13:32:02 +0100
commitaab11610d8c9e393ffcb63daf81d24fe5d0ac640 (patch)
tree1e5c8c0883d942f4124b084433328db47d4604b0 /lib/astal/gtk3/src/widget/circularprogress.vala
parent5c7e82b561ec7fda2df463ad12a2b72d59a720a2 (diff)
circularprogress: fix size calculations
Diffstat (limited to 'lib/astal/gtk3/src/widget/circularprogress.vala')
-rw-r--r--lib/astal/gtk3/src/widget/circularprogress.vala64
1 files changed, 46 insertions, 18 deletions
diff --git a/lib/astal/gtk3/src/widget/circularprogress.vala b/lib/astal/gtk3/src/widget/circularprogress.vala
index a3ecdf1..3d7e8bd 100644
--- a/lib/astal/gtk3/src/widget/circularprogress.vala
+++ b/lib/astal/gtk3/src/widget/circularprogress.vala
@@ -44,26 +44,54 @@ public class Astal.CircularProgress : Gtk.Bin {
set_css_name("circular-progress");
}
+ public override Gtk.SizeRequestMode get_request_mode() {
+ if(get_child() != null) return get_child().get_request_mode();
+ return Gtk.SizeRequestMode.HEIGHT_FOR_WIDTH;
+ }
+
public override 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) {
- minh = 40;
- nath = 40;
+ if(get_child() != null) {
+ int minw, natw;
+ get_child().get_preferred_height(out minh, out nath);
+ get_child().get_preferred_width(out minw, out natw);
+
+ minh = int.max(minw, minh);
+ nath = int.max(natw, nath);
}
+ var w_val = get_style_context().get_property("min-width", Gtk.StateFlags.NORMAL);
+ var h_val = get_style_context().get_property("min-height", Gtk.StateFlags.NORMAL);
+ minh = int.max(w_val.get_int(), minh);
+ nath = int.max(w_val.get_int(), nath);
+ minh = int.max(h_val.get_int(), minh);
+ nath = int.max(h_val.get_int(), nath);
+ }
- minh = val.get_int();
- nath = val.get_int();
+ public override void get_preferred_height_for_width(int width, out int minh, out int nath) {
+ minh = width;
+ nath = width;
}
public override void get_preferred_width(out int minw, out int natw) {
- var val = get_style_context().get_property("min-width", Gtk.StateFlags.NORMAL);
- if (val.get_int() <= 0) {
- minw = 40;
- natw = 40;
+ // if(get_child() != null) get_child().get_preferred_width(out minw, out natw);
+ if(get_child() != null) {
+ int minh, nath;
+ get_child().get_preferred_height(out minh, out nath);
+ get_child().get_preferred_width(out minw, out natw);
+
+ minw = int.max(minw, minh);
+ natw = int.max(natw, nath);
}
+ var w_val = get_style_context().get_property("min-width", Gtk.StateFlags.NORMAL);
+ var h_val = get_style_context().get_property("min-height", Gtk.StateFlags.NORMAL);
+ minw = int.max(w_val.get_int(), minw);
+ natw = int.max(w_val.get_int(), natw);
+ minw = int.max(h_val.get_int(), minw);
+ natw = int.max(h_val.get_int(), natw);
+ }
- minw = val.get_int();
- natw = val.get_int();
+ public override void get_preferred_width_for_height(int height, out int minw, out int natw) {
+ minw = height;
+ natw = height;
}
private double to_radian(double percentage) {
@@ -115,6 +143,12 @@ public class Astal.CircularProgress : Gtk.Bin {
Gtk.Allocation allocation;
get_allocation(out allocation);
+ if (get_child() != null) {
+ get_child().size_allocate(allocation);
+ propagate_draw(get_child(), cr);
+ }
+
+
var styles = get_style_context();
var width = allocation.width;
var height = allocation.height;
@@ -195,12 +229,6 @@ public class Astal.CircularProgress : Gtk.Bin {
cr.arc(end_x, end_y, fg_stroke / 2, 0, 0 - 0.01);
cr.fill();
}
-
- if (get_child() != null) {
- get_child().size_allocate(allocation);
- propagate_draw(get_child(), cr);
- }
-
return true;
}
}