Widget
Object Hierarchy:
Description:
public abstract class Widget : Object
The base class for all UI components.
Widgets are modeled after GTK (and other modern UI toolkits). Some of the layout properties should also be familiar to those that use
CSS.
Each Widget is essentially three concentric rectangles.
+---------------------------------+
| margin |
| +---------border----------+ |
| | padding | |
| | +-----------------+ | |
| | | content | | |
| | +-----------------+ | |
| | | |
| +-------------------------+ |
| |
+---------------------------------+
The margin is used to control spacing between widgets. Nothing should be drawn in the margin. The border is optional and can also have
rounded corners. The padding area should be filled with a background color unless the widget is "transparent". The actual graphical
representation of the widget is drawn in the content area.
Widgets also have a preferred width and height that is used to help
Containers layout child widgets. Widgets that can reflow their contents, such as widgets displaying text, can also provide a
preferred width and height for a specified height or width respectively. A Container will try to make each widget at least the requested
size. It may stretch the widget if needed but should not make it smaller that the requested size. If a Container does not have enough room
for each widget to be at least the requested size, unexpected results my occur. In this case, you should consider using a
Scroll Container.
Content:
Properties:
- public int margin_top { set; get; }
Gets and sets the top margin for the widget.
- public int margin_bottom { set; get; }
Gets and sets the bottom margin for the widget.
- public int margin_left { set; get; }
Gets and sets the left margin for the widget.
- public int margin_right { set; get; }
Gets and sets the right margin for the widget.
- public int margin { set; }
Sets all margins (top, bottom, left, right) for the widget.
- public int border_top { set; get; }
Gets and sets the top border width for the widget.
- public int border_bottom { set; get; }
Gets and sets the bottom border width for the widget.
- public int border_left { set; get; }
Gets and sets the left border width for the widget.
- public int border_right { set; get; }
Gets and sets the right border width for the widget.
- public int border { set; }
Sets all border widths (top, bottom, left, right) for the widget.
- public int border_radius { set; get; }
Gets and sets the border radius for the widget.
- public int padding_top { set; get; }
Gets and sets the top padding for the widget.
- public int padding_bottom { set; get; }
Gets and sets the bottom padding for the widget.
- public int padding_left { set; get; }
Gets and sets the left padding for the widget.
- public int padding_right { set; get; }
Gets and sets the right padding for the widget.
- public int padding { set; }
Sets all padding (top, bottom, left, right) for the widget.
- public WidgetAlign horizontal_align { set; get; }
Gets and sets the horizontal alignment for the widget.
- public WidgetAlign vertical_align { set; get; }
Gets and sets the vertical alignment for the widget.
- public bool can_focus { set; get; }
This widget can take the focus.
- public bool has_focus { protected set; get; }
Gets and sets the focus of this widget.
- public Widget? next_focus_widget_up { set; get; }
Gets and sets the next widget to focus when navigating up.
- public Widget? next_focus_widget_down { set; get; }
Gets and sets the next widget to focus when navigating down.
- public Widget? next_focus_widget_left { set; get; }
Gets and sets the next widget to focus when navigating left.
- public Widget? next_focus_widget_right { set; get; }
Gets and sets the next widget to focus when navigating right.
- public weak Container? parent { protected set; get; }
Gets the parent Container of this widget.
- public Window? window { owned get; }
Gets the top level window for this widget.
- public bool visible { set; get; }
Gets and sets the visibility of this widget.
- public void* weak_represented_object { set; get; }
Gets and sets a weak reference to a user-defined value.
- public Object? represented_object { set; get; }
Gets and sets a reference to a user-defined Object.
Creation methods:
Methods:
- public inline int get_margin_border_padding_width ()
Gets the combined width of margins, borders and paddings.
- public inline int get_margin_border_padding_height ()
Gets the combined height of margins, borders and paddings.
- protected virtual int get_preferred_width ()
Gets the preferred width of the widget.
- protected virtual int get_preferred_height ()
Gets the preferred height of the widget.
- protected virtual int get_preferred_width_for_height (int height)
Gets the preferred width of the widget for the specified height.
- protected virtual int get_preferred_height_for_width (int width)
Gets the preferred height of the widget for the specified width.
- protected void set_bounds (int x1, int y1, int x2, int y2)
Called by the parent Container to layout this widget.
- public bool focus ()
Focuses this widget.
- public void focus_next (FocusDirection direction)
Focuses the next widget in the specified direction.
- public Widget? get_focused_child ()
Searches this Widget and its children for the currently focused
widget.
- public Widget? do_recursive_children (WidgetFunc func, bool reverse = false)
Run a function recursively over widget and all of its children.
- public Widget? do_recursive_parent (WidgetFunc func)
Run a function recursively over widget and all of its ancestors.
- public virtual void redraw ()
Notifies that this widget has changed and needs to be redrawn.
- protected virtual void do_layout ()
Implementations should override this method if they need to handle
laying out its contents.
- protected virtual void draw_background ()
Implementations can override this method if they need to have a a
background.
- protected virtual void draw_content ()
Implementations should override this method.
- protected virtual void draw_border (Color color = fg_color)
Implementations can override this if they need special handling for
the border.
Signals:
Fields:
Inherited Members:
All known members inherited from class GLib.Object
- @new
- newv
- new_valist
- get_type
- get_class
- @ref
- unref
- ref_sink
- weak_ref
- weak_unref
- add_weak_pointer
- remove_weak_pointer
- @get
- @set
- get_property
- set_property
- get_data
- set_data
- set_data_full
- steal_data
- get_qdata
- set_qdata
- set_qdata_full
- steal_qdata
- freeze_notify
- thaw_notify
- dispose
- constructed
- notify_property
- connect
- disconnect
- add_toggle_ref
- remove_toggle_ref
- bind_property
- notify
- ref_count