From 434aa7327e56074a8f3a620f0fb7e30dbc3392f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Wed, 25 Jun 2025 10:43:32 -0700 Subject: [PATCH] ListItem: subclass Gtk.Widget directly --- lib/Widgets/ListItem.vala | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/Widgets/ListItem.vala b/lib/Widgets/ListItem.vala index 7dcdab2f6..878a9609f 100644 --- a/lib/Widgets/ListItem.vala +++ b/lib/Widgets/ListItem.vala @@ -9,7 +9,7 @@ * @since 7.7.0 */ [Version (since = "7.7.0")] -public class Granite.ListItem : Granite.Bin { +public class Granite.ListItem : Gtk.Widget { /** * The main label for #this */ @@ -20,8 +20,36 @@ public class Granite.ListItem : Granite.Bin { */ public string? description { get; set; } + private Gtk.Widget? _child; + /** + * The child widget of #this + */ + public Gtk.Widget? child { + get { + return _child; + } + + set { + if (value != null && value.get_parent () != null) { + critical ("Tried to set a widget as child that already has a parent."); + return; + } + + if (_child != null) { + _child.unparent (); + } + + _child = value; + + if (_child != null) { + _child.set_parent (this); + } + } + } + class construct { set_css_name ("granite-listitem"); + set_layout_manager_type (typeof (Gtk.BinLayout)); } construct { @@ -59,4 +87,10 @@ public class Granite.ListItem : Granite.Bin { } }); } + + ~ListItem () { + if (child != null) { + child.unparent (); + } + } }