Skip to content

Commit

Permalink
Introduce Granite.Bin for subclassing (#730)
Browse files Browse the repository at this point in the history
  • Loading branch information
leolost2605 authored Sep 18, 2024
1 parent add9ee8 commit 77bf292
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
49 changes: 49 additions & 0 deletions lib/Widgets/Bin.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2024 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: GPL-2.0-or-later
*/

/**
* This widget is a simple container that can hold a single child widget.
* It is mostly useful for deriving subclasses.
*
* @since 7.6.0
*/
public class Granite.Bin : Gtk.Widget {
class construct {
set_layout_manager_type (typeof (Gtk.BinLayout));
}

private Gtk.Widget? _child;
/**
* The child widget of the bin.
*/
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);
}
}
}

~Bin () {
if (child != null) {
child.unparent ();
}
}
}
1 change: 1 addition & 0 deletions lib/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ libgranite_sources = files(
'Widgets/AbstractSettingsPage.vala',
'Widgets/AbstractSimpleSettingsPage.vala',
'Widgets/AccelLabel.vala',
'Widgets/Bin.vala',
'Widgets/DatePicker.vala',
'Widgets/Dialog.vala',
'Widgets/HeaderLabel.vala',
Expand Down

0 comments on commit 77bf292

Please sign in to comment.