The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
menu.c File Reference

idunn: menus: a card in a popup (the card colour, a border, the radius, the md shadow, 4 pixels inside) with items of 32 pixels: an icon, the text and a shortcut in the muted colour; check items, separators and sub-menus. More...

#include "idunn_internal.h"
#include <stdlib.h>
#include <string.h>

Macros

#define PAD   4
#define ITEM   32
#define ITEM_PAD   8
#define ICON   16
#define GAP   8
#define SEPARATOR   9
#define MIN_WIDTH   160
#define MARGIN   28
#define SUB_MS   150

Enumerations

enum  kind_t { ITEM_ACTION , ITEM_CHECK , ITEM_SEPARATOR , ITEM_SUB }

Functions

idunn_menu_t * idunn_menu_new (void)
void idunn_menu_free (idunn_menu_t *menu)
 free a menu (not while it is open) and its sub-menus
int idunn_menu_add (idunn_menu_t *menu, const char *icon, const char *text, const char *shortcut, idunn_callback_t on_choose, void *data)
 an item: a Lucide icon (or NULL), text and a shortcut to show (or NULL).
int idunn_menu_add_check (idunn_menu_t *menu, const char *text, bool checked, idunn_callback_t on_choose, void *data)
 an item with a check that a choice turns on and off
void idunn_menu_add_separator (idunn_menu_t *menu)
int idunn_menu_add_sub (idunn_menu_t *menu, const char *icon, const char *text, idunn_menu_t *sub)
 an item that opens a sub-menu (the menu owns it)
void idunn_menu_set_disabled (idunn_menu_t *menu, int item, bool disabled)
bool idunn_menu_checked (const idunn_menu_t *menu, int item)
void idunn_menu_set_checked (idunn_menu_t *menu, int item, bool checked)
void idunn_menu_set_min_width (idunn_menu_t *menu, int32_t width)
 the least width of the menu, in design pixels (160 by default)
idunn_window_t * idunn_menu_open (idunn_menu_t *menu, idunn_widget_t *owner, gfx_rect_t anchor, int current, void(*on_closed)(void *data), void *data)
 open a menu next to anchor (a rect in owner's window), with item current (or -1) as the current one; on_closed (or NULL) is called when it closes.
void idunn_menu_popup (idunn_menu_t *menu, idunn_widget_t *owner)
 open the menu under a widget (a button's on_click does it)
void idunn_menu_popup_at_pointer (idunn_menu_t *menu, idunn_widget_t *owner)
 open the menu where the last right click was (a context menu)

Detailed Description

idunn: menus: a card in a popup (the card colour, a border, the radius, the md shadow, 4 pixels inside) with items of 32 pixels: an icon, the text and a shortcut in the muted colour; check items, separators and sub-menus.

keys: Up and Down (past separators and disabled items), Home and End, Enter and Space choose, Right opens a sub-menu, Left and Escape close a menu, a letter goes to the next item that starts with it. the mouse: the item under the pointer is the current one, a sub-menu opens after 150 ms over its item, a click chooses.

Macro Definition Documentation

◆ PAD

#define PAD   4

◆ ITEM

#define ITEM   32

◆ ITEM_PAD

#define ITEM_PAD   8

◆ ICON

#define ICON   16

◆ GAP

#define GAP   8

◆ SEPARATOR

#define SEPARATOR   9

◆ MIN_WIDTH

#define MIN_WIDTH   160

◆ MARGIN

#define MARGIN   28

◆ SUB_MS

#define SUB_MS   150

Enumeration Type Documentation

◆ kind_t

enum kind_t
Enumerator
ITEM_ACTION 
ITEM_CHECK 
ITEM_SEPARATOR 
ITEM_SUB 

Function Documentation

◆ idunn_menu_new()

idunn_menu_t * idunn_menu_new ( void )

◆ idunn_menu_free()

void idunn_menu_free ( idunn_menu_t * menu)

free a menu (not while it is open) and its sub-menus

◆ idunn_menu_add()

int idunn_menu_add ( idunn_menu_t * menu,
const char * icon,
const char * text,
const char * shortcut,
idunn_callback_t on_choose,
void * data )

an item: a Lucide icon (or NULL), text and a shortcut to show (or NULL).

on_choose gets the widget the menu was opened for.

Returns
the index of the item.

◆ idunn_menu_add_check()

int idunn_menu_add_check ( idunn_menu_t * menu,
const char * text,
bool checked,
idunn_callback_t on_choose,
void * data )

an item with a check that a choice turns on and off

◆ idunn_menu_add_separator()

void idunn_menu_add_separator ( idunn_menu_t * menu)

◆ idunn_menu_add_sub()

int idunn_menu_add_sub ( idunn_menu_t * menu,
const char * icon,
const char * text,
idunn_menu_t * sub )

an item that opens a sub-menu (the menu owns it)

◆ idunn_menu_set_disabled()

void idunn_menu_set_disabled ( idunn_menu_t * menu,
int item,
bool disabled )

◆ idunn_menu_checked()

bool idunn_menu_checked ( const idunn_menu_t * menu,
int item )

◆ idunn_menu_set_checked()

void idunn_menu_set_checked ( idunn_menu_t * menu,
int item,
bool checked )

◆ idunn_menu_set_min_width()

void idunn_menu_set_min_width ( idunn_menu_t * menu,
int32_t width )

the least width of the menu, in design pixels (160 by default)

◆ idunn_menu_open()

idunn_window_t * idunn_menu_open ( idunn_menu_t * menu,
idunn_widget_t * owner,
gfx_rect_t anchor,
int current,
void(* on_closed )(void *data),
void * data )

open a menu next to anchor (a rect in owner's window), with item current (or -1) as the current one; on_closed (or NULL) is called when it closes.

◆ idunn_menu_popup()

void idunn_menu_popup ( idunn_menu_t * menu,
idunn_widget_t * owner )

open the menu under a widget (a button's on_click does it)

◆ idunn_menu_popup_at_pointer()

void idunn_menu_popup_at_pointer ( idunn_menu_t * menu,
idunn_widget_t * owner )

open the menu where the last right click was (a context menu)