2D bitmap graphics library with emphasis on speed and correctness
No Matches
gp_widget_disable.h File Reference

Functions to disable and enable widgets. More...

#include <widgets/gp_widget_types.h>

Go to the source code of this file.


void gp_widget_disable (gp_widget *self)
 Disables widget and all its subwidgets.
void gp_widget_enable (gp_widget *self)
 Enables widget and all its subwidgets.
void gp_widget_disabled_set (gp_widget *self, bool disabled)
 Sets disabled/enabled widget state.
bool gp_widget_disabled_get (gp_widget *self)
 Returns true if widget is disabled.

Detailed Description

Functions to disable and enable widgets.

Disabled widgets are widgets that does not react to user input and are "grayed out" in the GUI. Once widget is disabled all its subwidgets are disabled as well.

Disabled widget example

//SPDX-License-Identifier: LGPL-2.0-or-later
Copyright (c) 2020 Cyril Hrubis <>
#include <gfxprim.h>
static int disable(gp_widget_event *ev)
return 0;
return 0;
static int enable(gp_widget_event *ev)
return 0;
return 0;
gp_app_info app_info = {
.name = "Disable",
.desc = "Disabled widgets example",
.version = "1.0",
.license = "GPL-2.0-or-later",
.url = "",
.authors = (gp_app_info_author []) {
{.name = "Cyril Hrubis", .email = "", .years = "2020-2023"},
int main(int argc, char *argv[])
const char *choices[] = {
"Choice #1",
"Choice #2",
"Choice #3"
gp_widget *btn_disable = gp_widget_button_new("Disable", 0);
gp_widget *btn_enable = gp_widget_button_new("Enable", 0);
gp_widget *buttons = gp_widget_grid_new(2, 1, 0);
gp_widget *grid = gp_widget_grid_new(1, 2, 0);
gp_widget *choice = gp_widget_radiobutton_new(choices, 3, 0);
gp_widget *frame = gp_widget_frame_new("Target widget", 0, choice);
gp_widget_on_event_set(btn_disable, disable, frame);
gp_widget_on_event_set(btn_enable, enable, frame);
gp_widget_grid_put(buttons, 0, 0, btn_disable);
gp_widget_grid_put(buttons, 1, 0, btn_enable);
gp_widget_grid_put(grid, 0, 0, frame);
gp_widget_grid_put(grid, 0, 1, buttons);
gp_widgets_main_loop(grid, NULL, argc, argv);
return 0;
gp_widget * gp_widget_button_new(const char *label, enum gp_widget_button_type type)
Allocates and initializes a new button widget.
void gp_widget_disable(gp_widget *self)
Disables widget and all its subwidgets.
void gp_widget_enable(gp_widget *self)
Enables widget and all its subwidgets.
Widget specific event.
void gp_widget_on_event_set(gp_widget *self, int(*on_event)(gp_widget_event *), void *priv)
Sets a widget event handler.
gp_widget * gp_widget_frame_new(const char *title, gp_widget_tattr tattr, gp_widget *child)
Allocates and initializes a new frame widget.
gp_widget * gp_widget_grid_put(gp_widget *self, unsigned int col, unsigned int row, gp_widget *child)
Puts a child widget into a frame widget.
gp_widget * gp_widget_grid_new(unsigned int cols, unsigned int rows, enum gp_widget_grid_flags flags)
Allocates and initializes a widget grid.
static void gp_widget_grid_no_border(gp_widget *self)
Disables grid padd and fill.
static gp_widget * gp_widget_radiobutton_new(const char *choices[], size_t cnt, size_t sel)
Allocates and initializes new radiobutton widget.
void gp_widgets_main_loop(struct gp_widget *layout, void(*init)(int argc, char *argv[]), int argc, char *argv[]) __attribute__((noreturn))
Widgets main loop.
Description of the app author.
Definition gp_app_info.h:31
An application information.
Definition gp_app_info.h:64
const char * name
Application name.
Definition gp_app_info.h:66
Event structure passed to widget event handler.
gp_widget * self
The widget the event is for.
uint16_t type
An event type, enum gp_widget_event_type.
A widget base.
Definition gp_widget.h:28
void * priv
A pointer to arbitrary application data.
Definition gp_widget.h:69

Definition in file gp_widget_disable.h.

Function Documentation

◆ gp_widget_disable()

void gp_widget_disable ( gp_widget self)

Disables widget and all its subwidgets.

A disabled widget does not process any input events and is "grayed out".

selfA widget to disable.

◆ gp_widget_disabled_get()

bool gp_widget_disabled_get ( gp_widget self)

Returns true if widget is disabled.

Note that this function returns true only if particular widget is disabled explicitly. It will return false for child widgets that are disabled because of parent widgets have been disabled.

selfA widget.
True if widget is disabled.

◆ gp_widget_disabled_set()

void gp_widget_disabled_set ( gp_widget self,
bool  disabled 

Sets disabled/enabled widget state.

A disabled widget does not process any input events and is "grayed out".

selfA widget.
disabledTrue to disable widget false to enable it.

◆ gp_widget_enable()

void gp_widget_enable ( gp_widget self)

Enables widget and all its subwidgets.

Enables a widget that has been disabled previously.

selfA widget to enable.