BSB Developer Docs
Loading...
Searching...
No Matches
widget.h File Reference

Base widget class. More...

#include <stdint.h>
#include <stdbool.h>
#include <toolbox/color.h>

Go to the source code of this file.

Typedefs

typedef struct Widget Widget
 Widget opaque structure.
 

Enumerations

enum  Align {
  AlignDefault , AlignTopLeft , AlignTopMid , AlignTopRight ,
  AlignBottomLeft , AlignBottomMid , AlignBottomRight , AlignLeftMid ,
  AlignRightMid , AlignCenter , AlignMax
}
 Enumeration of supported widget alignment modes. More...
 
enum  AlignBitmask {
  AlignBitmaskLeft = (1 << 0) , AlignBitmaskHorCenter = (1 << 1) , AlignBitmaskRight = (1 << 2) , AlignBitmaskTop = (1 << 3) ,
  AlignBitmaskVerCenter = (1 << 4) , AlignBitmaskBottom = (1 << 5)
}
 Like Align, but with coded axes for ease of processing.
 
enum  WidgetBlendMode {
  WidgetBlendModeNormal , WidgetBlendModeAdditive , WidgetBlendModeSubtractive , WidgetBlendModeMultiply ,
  WidgetBlendModeDifference , WidgetBlendModesCount
}
 Enumeration of possible blend modes for widget. More...
 

Functions

AlignBitmask widget_align_to_bitmask (Align align)
 Convert Align into AlignBitmask
 
Widget * widget_alloc (Widget *parent)
 Create a new widget instance.
 
void widget_free (Widget *instance)
 Delete a widget instance.
 
void widget_set_visible (Widget *instance, bool visible)
 Show or hide a Widget instance.
 
bool widget_is_visible (const Widget *instance)
 Check if a Widget instance is currently visible.
 
void widget_set_ignore_layout (Widget *instance, bool ignore_layout)
 Make widget ignore layout (e.g.
 
bool widget_does_ignore_layout (const Widget *instance)
 Check if a Widget instance ignores layout.
 
void widget_set_width (Widget *instance, int32_t width)
 Set the Widget width.
 
int32_t widget_get_width (const Widget *instance)
 Get the Widget width.
 
void widget_set_height (Widget *instance, int32_t height)
 Set the Widget height.
 
int32_t widget_get_height (const Widget *instance)
 Get the Widget height.
 
void widget_set_size (Widget *instance, int32_t width, int32_t height)
 Set both the width and height of a Widget.
 
void widget_set_max_width (Widget *instance, int32_t max_width)
 Set the maximum width of a Widget.
 
void widget_set_max_height (Widget *instance, int32_t max_height)
 Set the maximum height of a Widget.
 
void widget_set_max_size (Widget *instance, int32_t max_width, int32_t max_height)
 Set the maximum width and height of a Widget.
 
void widget_set_size_content (Widget *instance)
 Set both the width and height of a Widget to fit its content.
 
void widget_set_width_content (Widget *instance)
 Set the width of a Widget to fit its content.
 
void widget_set_height_content (Widget *instance)
 Set the height of a Widget to fit its content.
 
int32_t widget_get_max_width (const Widget *instance)
 Get the Widget maximum width.
 
int32_t widget_get_max_height (const Widget *instance)
 Get the Widget maximum height.
 
void widget_set_pos_x (Widget *instance, int32_t x)
 Set the Widget x (horizontal) position.
 
void widget_set_pos_y (Widget *instance, int32_t y)
 Set the Widget y (vertical) position.
 
void widget_set_pos (Widget *instance, int32_t x, int32_t y)
 Set both the x (horizontal) and y (vertical) positions of a Widget.
 
void widget_set_align (Widget *instance, Align align)
 Set the Widget alignment relative to its parent.
 
void widget_move_to_foreground (Widget *instance)
 Make the Widget to be drawn above all others on the same layer.
 
void widget_move_to_background (Widget *instance)
 Make the Widget to be drawn below all others on the same layer.
 
void widget_set_scrollbar_enabled (Widget *instance, bool is_enabled)
 Set widget scrollbar mode.
 
void widget_set_background_color (Widget *instance, Color color)
 Set the background color and opacity of a Widget instance.
 
void widget_set_opacity (Widget *instance, uint8_t opacity)
 Set the global opacity of a Widget instance.
 
void widget_set_padding (Widget *instance, int32_t left, int32_t right, int32_t top, int32_t bottom)
 Set the padding for a Widget instance.
 
void widget_set_margin (Widget *instance, int32_t left, int32_t right, int32_t top, int32_t bottom)
 Set the margin for a Widget instance.
 
void widget_set_blend_mode (Widget *instance, WidgetBlendMode blend_mode)
 Set the blend mode for a Widget instance.
 
WidgetBlendMode widget_get_blend_mode (const Widget *instance)
 Get the blend mode for a Widget instance.
 
void widget_set_context (Widget *instance, void *context)
 Set the widget context.
 
void * widget_get_context (const Widget *instance)
 Get the widget context.
 

Detailed Description

Base widget class.

Rule of thumb: if a class takes a parent Widget* instance, its instances can be safely cast to the Widget* type.

Warning
Although the root widget instance has the same type, it is NOT safe to call any of the below methods on it. It can ONLY be used as a parent for other Widgets.

Enumeration Type Documentation

◆ Align

enum Align

Enumeration of supported widget alignment modes.

Enumerator
AlignDefault 

Use the default alignment from the class.

AlignCenter 

Center the widget inside of its parent.

AlignMax 

Special value, not to be used in application code.

◆ WidgetBlendMode

Enumeration of possible blend modes for widget.

Enumerator
WidgetBlendModeNormal 

Simply mix according to the opacity value.

WidgetBlendModeAdditive 

Add the respective color channels.

WidgetBlendModeSubtractive 

Subtract the foreground from the background.

WidgetBlendModeMultiply 

Multiply the foreground and background.

WidgetBlendModeDifference 

Absolute difference between foreground and background.

WidgetBlendModesCount 

Special value, not to be used in application code.

Function Documentation

◆ widget_align_to_bitmask()

AlignBitmask widget_align_to_bitmask ( Align align)

Convert Align into AlignBitmask

AlignBitmask may be easier to manually parse in some cases.

Parameters
[in]alignAlign value
Returns
Converted AlignBitmap value

◆ widget_alloc()

Widget * widget_alloc ( Widget * parent)

Create a new widget instance.

Either a regular Widget or a root widget can be used as the parent.

Parameters
[in,out]parentpointer to the parent Widget instance
Returns
pointer to the newly created Widget instance

◆ widget_does_ignore_layout()

bool widget_does_ignore_layout ( const Widget * instance)

Check if a Widget instance ignores layout.

Parameters
[in]instancepointer to the Widget instance to be queried
Returns
true if widget instance ignores layout, false otherwise

◆ widget_free()

void widget_free ( Widget * instance)

Delete a widget instance.

Parameters
[in,out]instancepointer to the Widget instance to be deleted

◆ widget_get_blend_mode()

WidgetBlendMode widget_get_blend_mode ( const Widget * instance)

Get the blend mode for a Widget instance.

Parameters
[in]instancepointer to the Widget instance to be queried
Returns
current blend mode from the WidgetBlendMode enumeration

◆ widget_get_context()

void * widget_get_context ( const Widget * instance)

Get the widget context.

Parameters
[in]instancepointer to the Widget instance to be queried
Returns
pointer to the user-specific object (may be NULL)

◆ widget_get_height()

int32_t widget_get_height ( const Widget * instance)

Get the Widget height.

Parameters
[in]instancepointer to the Widget instance to be queried
Returns
widget height in pixels

◆ widget_get_max_height()

int32_t widget_get_max_height ( const Widget * instance)

Get the Widget maximum height.

Parameters
[in]instancepointer to the Widget instance to be queried
Returns
widget maximum height in pixels

◆ widget_get_max_width()

int32_t widget_get_max_width ( const Widget * instance)

Get the Widget maximum width.

Parameters
[in]instancepointer to the Widget instance to be queried
Returns
widget maximum width in pixels

◆ widget_get_width()

int32_t widget_get_width ( const Widget * instance)

Get the Widget width.

Parameters
[in]instancepointer to the Widget instance to be queried
Returns
widget width in pixels

◆ widget_is_visible()

bool widget_is_visible ( const Widget * instance)

Check if a Widget instance is currently visible.

Parameters
[in]instancepointer to the Widget instance to be queried
Returns
true if widget is visible, false otherwise

◆ widget_move_to_background()

void widget_move_to_background ( Widget * instance)

Make the Widget to be drawn below all others on the same layer.

Parameters
[in,out]instancepointer to the Widget instance to be modified

◆ widget_move_to_foreground()

void widget_move_to_foreground ( Widget * instance)

Make the Widget to be drawn above all others on the same layer.

Parameters
[in,out]instancepointer to the Widget instance to be modified

◆ widget_set_align()

void widget_set_align ( Widget * instance,
Align align )

Set the Widget alignment relative to its parent.

Parameters
[in,out]instancepointer to the Widget instance to be modified
[in]alignalignment value from the Align enumeration

◆ widget_set_background_color()

void widget_set_background_color ( Widget * instance,
Color color )

Set the background color and opacity of a Widget instance.

Parameters
[in,out]instancepointer to the Widget instance to be modified
[in]colornew background color including opacity

◆ widget_set_blend_mode()

void widget_set_blend_mode ( Widget * instance,
WidgetBlendMode blend_mode )

Set the blend mode for a Widget instance.

Parameters
[in,out]instancepointer to the Widget instance to be modified
[in]blend_modenew blend mode from the WidgetBlendMode enumeration

◆ widget_set_context()

void widget_set_context ( Widget * instance,
void * context )

Set the widget context.

Parameters
[in,out]instancepointer to the Widget instance to be modified
[in,out]contextpointer to a user-specific object

◆ widget_set_height()

void widget_set_height ( Widget * instance,
int32_t height )

Set the Widget height.

Parameters
[in,out]instancepointer to the Widget instance to be modified
[in]heightnew height in pixels

◆ widget_set_height_content()

void widget_set_height_content ( Widget * instance)

Set the height of a Widget to fit its content.

Parameters
[in,out]instancepointer to the Widget instance to be modified

◆ widget_set_ignore_layout()

void widget_set_ignore_layout ( Widget * instance,
bool ignore_layout )

Make widget ignore layout (e.g.

flex layout).

Parameters
[in,out]instancepointer to the Widget instance to be modified
[in]ignore_layoutmake the Widget instance ignore layout if true, otherwise acknowledge it

◆ widget_set_margin()

void widget_set_margin ( Widget * instance,
int32_t left,
int32_t right,
int32_t top,
int32_t bottom )

Set the margin for a Widget instance.

Parameters
[in,out]instancepointer to the Widget instance to be modified
[in]leftmargin on the left side in pixels
[in]rightmargin on the right side in pixels
[in]topmargin on the top side in pixels
[in]bottommargin on the bottom side in pixels

◆ widget_set_max_height()

void widget_set_max_height ( Widget * instance,
int32_t max_height )

Set the maximum height of a Widget.

Parameters
[in,out]instancepointer to the Widget instance to be modified
[in]max_heightnew height in pixels

◆ widget_set_max_size()

void widget_set_max_size ( Widget * instance,
int32_t max_width,
int32_t max_height )

Set the maximum width and height of a Widget.

Parameters
[in,out]instancepointer to the Widget instance to be modified
[in]max_widthnew width in pixels
[in]max_heightnew height in pixels

◆ widget_set_max_width()

void widget_set_max_width ( Widget * instance,
int32_t max_width )

Set the maximum width of a Widget.

Parameters
[in,out]instancepointer to the Widget instance to be modified
[in]max_widthnew width in pixels

◆ widget_set_opacity()

void widget_set_opacity ( Widget * instance,
uint8_t opacity )

Set the global opacity of a Widget instance.

Parameters
[in,out]instancepointer to the Widget instance to be modified
[in]opacitynew opacity value (0-255)

◆ widget_set_padding()

void widget_set_padding ( Widget * instance,
int32_t left,
int32_t right,
int32_t top,
int32_t bottom )

Set the padding for a Widget instance.

Parameters
[in,out]instancepointer to the Widget instance to be modified
[in]leftpadding on the left side in pixels
[in]rightpadding on the right side in pixels
[in]toppadding on the top side in pixels
[in]bottompadding on the bottom side in pixels

◆ widget_set_pos()

void widget_set_pos ( Widget * instance,
int32_t x,
int32_t y )

Set both the x (horizontal) and y (vertical) positions of a Widget.

Note
Widget positions are always relative to its parent.
Parameters
[in,out]instancepointer to the Widget instance to be modified
[in]xnew horizontal position in pixels
[in]ynew vertical position in pixels

◆ widget_set_pos_x()

void widget_set_pos_x ( Widget * instance,
int32_t x )

Set the Widget x (horizontal) position.

Note
Widget positions are always relative to its parent.
Parameters
[in,out]instancepointer to the Widget instance to be modified
[in]xnew horizontal position in pixels

◆ widget_set_pos_y()

void widget_set_pos_y ( Widget * instance,
int32_t y )

Set the Widget y (vertical) position.

Note
Widget positions are always relative to its parent.
Parameters
[in,out]instancepointer to the Widget instance to be modified
[in]ynew vertical position in pixels

◆ widget_set_scrollbar_enabled()

void widget_set_scrollbar_enabled ( Widget * instance,
bool is_enabled )

Set widget scrollbar mode.

Parameters
[in,out]instancepointer to the widget instance to be modified
[in]is_enabledenable the Widget instance scrollbar drawing if true, disable otherwise

◆ widget_set_size()

void widget_set_size ( Widget * instance,
int32_t width,
int32_t height )

Set both the width and height of a Widget.

Parameters
[in,out]instancepointer to the Widget instance to be modified
[in]widthnew width in pixels
[in]heightnew height in pixels

◆ widget_set_size_content()

void widget_set_size_content ( Widget * instance)

Set both the width and height of a Widget to fit its content.

Parameters
[in,out]instancepointer to the Widget instance to be modified

◆ widget_set_visible()

void widget_set_visible ( Widget * instance,
bool visible )

Show or hide a Widget instance.

Widgets are shown by default.

Parameters
[in,out]instancepointer to the Widget instance to be modified
[in]visiblemake the Widget instance visible if true, otherwise invisible

◆ widget_set_width()

void widget_set_width ( Widget * instance,
int32_t width )

Set the Widget width.

Parameters
[in,out]instancepointer to the Widget instance to be modified
[in]widthnew width in pixels

◆ widget_set_width_content()

void widget_set_width_content ( Widget * instance)

Set the width of a Widget to fit its content.

Parameters
[in,out]instancepointer to the Widget instance to be modified