GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
Data Structures | Enumerations | Functions
gp_widget_ops.h File Reference

Widget internals. More...

#include <input/gp_event.h>
#include <utils/gp_bbox.h>
#include <utils/gp_json.h>
#include <widgets/gp_widget.h>
#include <widgets/gp_widget_render.h>

Go to the source code of this file.

Data Structures

struct  gp_widget_ops
 Callbacks that implements a widget. More...
 

Enumerations

enum  gp_widget_focus_flag {
  GP_FOCUS_OUT , GP_FOCUS_IN , GP_FOCUS_LEFT , GP_FOCUS_RIGHT ,
  GP_FOCUS_UP , GP_FOCUS_DOWN , GP_FOCUS_NEXT , GP_FOCUS_PREV
}
 Flags to move focus around. More...
 
enum  gp_widget_render_flags { GP_WIDGET_REDRAW = 0x01 , GP_WIDGET_REDRAW_CHILDREN = 0x02 , GP_WIDGET_COLOR_SCHEME = 0x04 , GP_WIDGET_RESIZE = 0x08 , GP_WIDGET_DISABLED = 0x10 }
 Widget rendering flags. More...
 

Functions

int gp_widget_ops_event (gp_widget *self, const gp_widget_render_ctx *ctx, gp_event *ev)
 Send an event to a widget.
 
int gp_widget_ops_render_focus (gp_widget *self, int focus_dir)
 Moves focus, if possible, in the direction requested by the focus_dir.
 
int gp_widget_ops_render_focus_xy (gp_widget *self, const gp_widget_render_ctx *ctx, unsigned int x, unsigned int y)
 Tries to focus a widget on a given coordinates in a layout.
 
int gp_widget_ops_focus_widget (gp_widget *self)
 Moves focus to a particular widget.
 
void gp_widget_ops_for_each_child (gp_widget *self, void(*func)(gp_widget *child))
 Calls a callback on each child widget.
 
static void gp_widget_ops_blit (const gp_widget_render_ctx *ctx, gp_coord x, gp_coord y, gp_size w, gp_size h)
 Marks an area to be blit on the screen from a buffer.
 
static int gp_widget_should_redraw (gp_widget *self, int flags)
 Returns true if widget should be repainted.
 
void gp_widget_calc_size (gp_widget *layout, const gp_widget_render_ctx *ctx, unsigned int w, unsigned int h, int new_wh)
 Calculates layout size recursively.
 
void gp_widget_redraw (gp_widget *self)
 Requests widget repaint.
 
void gp_widget_resize (gp_widget *self)
 Requests widget resize.
 
void gp_widget_redraw_children (gp_widget *self)
 Redraw all child widgets.
 
void gp_widget_render (gp_widget *self, const gp_widget_render_ctx *ctx, int new_wh)
 Resizes and redraws changed widgets.
 

Detailed Description

Widget internals.

You will not need to understand this part of the library unless you need to add a custom widget types.

Definition in file gp_widget_ops.h.

Enumeration Type Documentation

◆ gp_widget_focus_flag

Flags to move focus around.

Enumerator
GP_FOCUS_OUT 

Defocus any focused widget in the layout.

GP_FOCUS_IN 

Focus first widget in the layout.

GP_FOCUS_LEFT 

Moves focus left.

GP_FOCUS_RIGHT 

Moves focus right.

GP_FOCUS_UP 

Moves focus up.

GP_FOCUS_DOWN 

Moves focus down.

GP_FOCUS_NEXT 

Focus next widget.

GP_FOCUS_PREV 

Focus previous widget.

Definition at line 27 of file gp_widget_ops.h.

◆ gp_widget_render_flags

Widget rendering flags.

Enumerator
GP_WIDGET_REDRAW 

Widget needs to be repainted.

Set by the widget to request a repaint next time the main loop returns to the library.

GP_WIDGET_COLOR_SCHEME 

A color scheme has changed.

Passed down from the widget render when color scheme changed and everything has to be repainted.

GP_WIDGET_RESIZE 

Layout needs to be resized.

TODO description.

GP_WIDGET_DISABLED 

Widget is disabled.

When a widget is disabled all it's children gets this flag passed down to their render functions.

Definition at line 54 of file gp_widget_ops.h.

Function Documentation

◆ gp_widget_calc_size()

void gp_widget_calc_size ( gp_widget layout,
const gp_widget_render_ctx ctx,
unsigned int  w,
unsigned int  h,
int  new_wh 
)

Calculates layout size recursively.

The size may end up larger than WxH if there is too much widgets or smaller than WxH if align is not set to fill.

Parameters
layoutWidget layout.
ctxRender context, e.g. fonts, pixel type, padding size, etc.
wWidth we are trying to fit into
hHeight we are trying to fit into
new_whIf set the layout size is recalculated, i.e. the layout size has changed.

◆ gp_widget_ops_blit()

static void gp_widget_ops_blit ( const gp_widget_render_ctx ctx,
gp_coord  x,
gp_coord  y,
gp_size  w,
gp_size  h 
)
inlinestatic

Marks an area to be blit on the screen from a buffer.

This function is called by widgets so that the render knows which parts of the screen has to be updated after the call to the render function.

Definition at line 324 of file gp_widget_ops.h.

References gp_bbox_empty(), gp_bbox_merge(), and gp_bbox_pack().

◆ gp_widget_ops_event()

int gp_widget_ops_event ( gp_widget self,
const gp_widget_render_ctx ctx,
gp_event ev 
)

Send an event to a widget.

Parameters
selfA widget to send the event to.
ctxA render context.
evAn input event.
Returns
Zero if event wasn't handled, non-zero otherwise.

◆ gp_widget_ops_focus_widget()

int gp_widget_ops_focus_widget ( gp_widget self)

Moves focus to a particular widget.

Traverses the widget layout tree to the top and sets the focus accordingly.

Parameters
selfA widget to be focused.
Returns
Zero if focus couldn't be changed, non-zero otherwise.

◆ gp_widget_ops_for_each_child()

void gp_widget_ops_for_each_child ( gp_widget self,
void(*)(gp_widget *child)  func 
)

Calls a callback on each child widget.

All non-leaf widgets must implement for_each_child() callback in its ops which is then called by this function.

This function is no-op for NULL self and non-leaf widgets.

Parameters
selfA widget.
funcA function callback

◆ gp_widget_ops_render_focus()

int gp_widget_ops_render_focus ( gp_widget self,
int  focus_dir 
)

Moves focus, if possible, in the direction requested by the focus_dir.

Parameters
selfA widget layout.
focus_dirDirection to move the focus to.
Returns
Zero if focus couldn't be moved, non-zero otherwise.

◆ gp_widget_ops_render_focus_xy()

int gp_widget_ops_render_focus_xy ( gp_widget self,
const gp_widget_render_ctx ctx,
unsigned int  x,
unsigned int  y 
)

Tries to focus a widget on a given coordinates in a layout.

Parameters
selfA widget layout.
ctxA render context.
xX coordinate.
yY coordinate.
Returns
Zero if focus wasn't changed, non-zero otherwise.

◆ gp_widget_redraw()

void gp_widget_redraw ( gp_widget self)

Requests widget repaint.

Marks widget to be repainted on next update.

Parameters
selfA widget.

Referenced by gp_widget_label_tattr_set().

◆ gp_widget_redraw_children()

void gp_widget_redraw_children ( gp_widget self)

Redraw all child widgets.

Marks all children to be repainted on next update. This is used internally by container widgets when layout has changed, e.g. visible tab has changed.

Parameters
selfA container widget.

◆ gp_widget_render()

void gp_widget_render ( gp_widget self,
const gp_widget_render_ctx ctx,
int  new_wh 
)

Resizes and redraws changed widgets.

Parameters
selfA widget layout.
ctxA rendering context.
new_whIf set the layout size is recalculated, i.e. the layout size has changed.

◆ gp_widget_resize()

void gp_widget_resize ( gp_widget self)

Requests widget resize.

Marks widget to be resized on next update. The resize is propagated in the layout to the top. E.g. if widget has to grow, the whole layout will.

Parameters
selfA widget.

Referenced by gp_widget_label_width_set().

◆ gp_widget_should_redraw()

static int gp_widget_should_redraw ( gp_widget self,
int  flags 
)
inlinestatic

Returns true if widget should be repainted.

@self A widget. @flags Render flags passed down to the widget->render() function.

Returns
Non-zero if widget should be repainted.

Definition at line 345 of file gp_widget_ops.h.

References GP_WIDGET_REDRAW, and gp_widget::redraw.