Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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