-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce Granite.Bin for subclassing (#730)
- Loading branch information
1 parent
add9ee8
commit 77bf292
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 (); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters