GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
Functions
gp_widget_hvbox.h File Reference

A horizontal and vertical box widget. More...

#include <widgets/gp_widget_grid.h>

Go to the source code of this file.

Functions

static gp_widgetgp_widget_hbox_new (unsigned int cols, enum gp_widget_grid_flags flags)
 Creates a hbox i.e. grid with single row.
 
static gp_widgetgp_widget_vbox_new (unsigned int rows, enum gp_widget_grid_flags flags)
 Creates a vbox i.e. grid with single column.
 
gp_widgetgp_widget_box_put (gp_widget *self, unsigned int pos, gp_widget *child)
 Puts a widget into a hbox or vbox.
 
gp_widgetgp_widget_box_rem (gp_widget *self, unsigned int pos)
 Removes a widget from hbox or vbox.
 

Detailed Description

A horizontal and vertical box widget.

Hbox and vbox widgets are one-dimensional gp_widget_grid.h widgets with rows=1, cols=1 respectively and with a simplified JSON attribute list.

Hbox example buttons apart

{
"info": {"version": 1, "license": "GPL-2.0-or-later"},
"layout": {
"type": "hbox", "border": "none", "uniform": true, "align": "hfill", "widgets": [
{"type": "button", "label": "Ok", "align": "hfill", "on_event": "do_ok"},
{"type": "button", "label": "Cancel", "align": "hfill", "on_event": "do_cancel"}
],
"cell-fill": "0, 0",
"padd-fill": "0, 1, 0"
}
}

The hbox is uniform, that means that both buttons have the same width, otherwise the button OK would be smaller as the button label is shorter.

The padd between the buttons is the only element that can grow, so it fills awailable space as the hbox grows.

Hbox example buttons right

{
"info": {"version": 1, "license": "GPL-2.0-or-later"},
"layout": {
"type": "hbox", "border": "none", "uniform": true, "align": "hfill", "widgets": [
{"type": "button", "label": "Ok", "align": "hfill", "on_event": "do_ok"},
{"type": "button", "label": "Cancel", "align": "hfill", "on_event": "do_cancel"}
],
"cell-fill": "0, 0",
"padd-fill": "1, 0, 0"
}
}

The hbox is uniform, that means that both buttons have the same width, otherwise the button OK would be smaller as the button label is shorter.

The padd on the left is the only element that can grow, so it fills the available space as the hbox grows.

Hbox example buttons fill

{
"info": {"version": 1, "license": "GPL-2.0-or-later"},
"layout": {
"type": "hbox", "border": "none", "uniform": true, "align": "hfill", "widgets": [
{"type": "button", "label": "Ok", "align": "hfill", "on_event": "do_ok"},
{"type": "button", "label": "Cancel", "align": "hfill", "on_event": "do_cancel"}
],
"cell-fill": "4, 4",
"padd-fill": "0, 1, 0"
}
}

The hbox is uniform, that means that both buttons have the same width, otherwise the button OK would be smaller as the button label is shorter.

Both buttons have fill coeficient 4 and the space between them has fill coeficient 1. Available space is divided by 4:1:4.

Hbox and Vbox JSON attributes

Attribute Type Default Description
border string all 1 See gp_widget_grid.h
cell-fill string cnt x 1 Cell fill coeficients.
padd-fill string (cnt+1) x 0 Padding fill coeficients.
padd string (cnt+1) x 1 Padding sizes between cells.
frame bool false Draws a frame around the box.
uniform bool false All cells have the same size.
widgets array Array of widget objects.

Definition in file gp_widget_hvbox.h.

Function Documentation

◆ gp_widget_box_put()

gp_widget * gp_widget_box_put ( gp_widget self,
unsigned int  pos,
gp_widget child 
)

Puts a widget into a hbox or vbox.

Parameters
selfA hbox or vbox widget.
posA position to insert the child into, column for hbox and row for vbox.
childA child widget to insert.
Returns
Previous child occupying the slot or NULL if it was empty.

◆ gp_widget_box_rem()

gp_widget * gp_widget_box_rem ( gp_widget self,
unsigned int  pos 
)

Removes a widget from hbox or vbox.

Parameters
selfA hbox or vbox widget.
posA position to remove the child from.
Returns
A child widget removed from the slot or NULL if it was empty.

◆ gp_widget_hbox_new()

static gp_widget * gp_widget_hbox_new ( unsigned int  cols,
enum gp_widget_grid_flags  flags 
)
inlinestatic

Creates a hbox i.e. grid with single row.

Parameters
colsA number of columns in the box.
flagsA bitwise combination of flags.
Returns
A newly allocated and initialized hbox widget.

Definition at line 80 of file gp_widget_hvbox.h.

References gp_widget_grid_new().

◆ gp_widget_vbox_new()

static gp_widget * gp_widget_vbox_new ( unsigned int  rows,
enum gp_widget_grid_flags  flags 
)
inlinestatic

Creates a vbox i.e. grid with single column.

Parameters
rowsA number of columns in the box.
flagsA bitwise combination of flags.
Returns
A newly allocated and initialized vbox widget.

Definition at line 94 of file gp_widget_hvbox.h.

References gp_widget_grid_new().