Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
GUI POPUP: a popup menu with submenus

Macros

#define N_GUI_POPUP_ROOT   0
 the top level, as a parent for n_gui_popup_add_item() and the others

Typedefs

typedef void(* N_GUI_POPUP_FN) (N_GUI_POPUP *popup, int tag, void *user_data)
 called when an item is picked, after the popup has closed.

Functions

int n_gui_popup_add_item (N_GUI_POPUP *popup, int parent, const char *text, int tag, const char *tip)
 Add an item at the end of a level.
int n_gui_popup_add_separator (N_GUI_POPUP *popup, int parent)
 Add a separator at the end of a level.
int n_gui_popup_add_submenu (N_GUI_POPUP *popup, int parent, const char *text, const char *tip)
 Add a submenu at the end of a level.
void n_gui_popup_close (N_GUI_POPUP *popup)
 Close every level without picking anything.
void n_gui_popup_free (N_GUI_POPUP **popup)
 Close the popup and release the handle.
int n_gui_popup_hit (const N_GUI_POPUP *popup, float x, float y)
 Is a point on any of its open levels.
int n_gui_popup_is_open (const N_GUI_POPUP *popup)
 Is its top level on screen.
N_GUI_POPUP * n_gui_popup_new (N_GUI_CTX *ctx, float scale, N_GUI_POPUP_FN on_pick, void *user_data)
 Make an empty popup menu in ctx, closed.
int n_gui_popup_open (N_GUI_POPUP *popup, float x, float y)
 Open the top level with its corner at a point.
int n_gui_popup_press (N_GUI_POPUP *popup, int entry)
 Press the row of an entry, as a click on it would.
void n_gui_popup_set_enabled (N_GUI_POPUP *popup, int entry, int enabled)
 Enable or grey out an entry.
void n_gui_popup_set_shown (N_GUI_POPUP *popup, int entry, int shown)
 Show or hide an entry.
void n_gui_popup_set_title (N_GUI_POPUP *popup, const char *text)
 Set the heading line over the top level.
int n_gui_popup_window (const N_GUI_POPUP *popup, int level)
 The window of a level, for an application that wants to test it.

Detailed Description

Macro Definition Documentation

◆ N_GUI_POPUP_ROOT

Typedef Documentation

◆ N_GUI_POPUP_FN

typedef void(* N_GUI_POPUP_FN) (N_GUI_POPUP *popup, int tag, void *user_data)

called when an item is picked, after the popup has closed.

Parameters
popupthe popup
tagthe tag the item was added with
user_datawhat was handed to n_gui_popup_new()

Definition at line 78 of file n_gui_popup.h.

Function Documentation

◆ n_gui_popup_add_item()

int n_gui_popup_add_item ( N_GUI_POPUP * popup,
int parent,
const char * text,
int tag,
const char * tip )

Add an item at the end of a level.

Parameters
popupthe popup
parentN_GUI_POPUP_ROOT, or an id from n_gui_popup_add_submenu()
textwhat the row says. Copied.
taghanded to on_pick when it is picked
tiptooltip for the row, or NULL. Copied.
Returns
the entry's id, or -1 on failure (no memory, a parent that is not a level).

Definition at line 522 of file n_gui_popup.c.

References _popup_append(), _popup_is_level(), and _POPUP_KIND_ITEM.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_gui_popup_add_separator()

int n_gui_popup_add_separator ( N_GUI_POPUP * popup,
int parent )

Add a separator at the end of a level.

Parameters
popupthe popup
parentN_GUI_POPUP_ROOT or a submenu's id
Returns
the separator's id, or -1 on failure.

Definition at line 532 of file n_gui_popup.c.

References _popup_append(), _popup_is_level(), and _POPUP_KIND_SEP.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_gui_popup_add_submenu()

int n_gui_popup_add_submenu ( N_GUI_POPUP * popup,
int parent,
const char * text,
const char * tip )

Add a submenu at the end of a level.

Parameters
popupthe popup
parentN_GUI_POPUP_ROOT, or another submenu's id
textwhat its row says; the arrow is drawn, not written. Copied.
tiptooltip for the row, or NULL. Copied.
Returns
the submenu's id, a parent for its own entries, or -1 on failure.

Definition at line 527 of file n_gui_popup.c.

References _popup_append(), _popup_is_level(), and _POPUP_KIND_SUB.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_gui_popup_close()

void n_gui_popup_close ( N_GUI_POPUP * popup)

Close every level without picking anything.

Parameters
popupthe popup. NULL is a no-op.

Definition at line 563 of file n_gui_popup.c.

References _popup_close_level(), N_GUI_POPUP::ctx, N_GUI_POPUP::entries, n_gui_mark_dirty(), and N_GUI_POPUP_ROOT.

Referenced by _popup_activate(), main(), n_gui_popup_free(), and n_gui_popup_open().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_gui_popup_free()

void n_gui_popup_free ( N_GUI_POPUP ** popup)

Close the popup and release the handle.

Its windows stay in the context, closed, and their widgets no longer call into the freed handle.

Parameters
popupthe popup; set to NULL. NULL or *NULL is a no-op.

Definition at line 607 of file n_gui_popup.c.

References FreeNoLog, _N_GUI_POPUP_ENTRY::hook, n_gui_custom_set_mouse(), n_gui_popup_close(), n_gui_set_widget_visible(), _N_GUI_POPUP_ENTRY::row_y, _N_GUI_POPUP_ENTRY::rows, _N_GUI_POPUP_ENTRY::text, _N_GUI_POPUP_ENTRY::tip, and _N_GUI_POPUP_ENTRY::widget.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_gui_popup_hit()

int n_gui_popup_hit ( const N_GUI_POPUP * popup,
float x,
float y )

Is a point on any of its open levels.

Parameters
popupthe popup
xscreen x
yscreen y
Returns
1 when the point is inside an open level, 0 otherwise.

Definition at line 574 of file n_gui_popup.c.

References _N_GUI_POPUP_ENTRY::child, N_GUI_POPUP::entries, _N_GUI_POPUP_ENTRY::h, n_gui_popup_is_open(), N_GUI_POPUP_ROOT, _N_GUI_POPUP_ENTRY::w, _N_GUI_POPUP_ENTRY::x, and _N_GUI_POPUP_ENTRY::y.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_gui_popup_is_open()

int n_gui_popup_is_open ( const N_GUI_POPUP * popup)

Is its top level on screen.

Parameters
popupthe popup
Returns
1 when it is open.

Definition at line 569 of file n_gui_popup.c.

References N_GUI_POPUP::ctx, N_GUI_POPUP::entries, N_GUI_POPUP_ROOT, n_gui_window_is_open(), and _N_GUI_POPUP_ENTRY::window.

Referenced by main(), n_gui_popup_hit(), and on_pick().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_gui_popup_new()

N_GUI_POPUP * n_gui_popup_new ( N_GUI_CTX * ctx,
float scale,
N_GUI_POPUP_FN on_pick,
void * user_data )

Make an empty popup menu in ctx, closed.

No window is made until a level is first opened. The windows belong to ctx like any others and outlive the handle, closed and inert.

Parameters
ctxthe GUI context
scaleinterface scale, for padding and the arrow; 1.0 at 96 dpi
on_pickcalled with an item's tag when it is picked. Required.
user_datahanded back to on_pick
Returns
the popup, or NULL on failure. Release it with n_gui_popup_free().

Definition at line 503 of file n_gui_popup.c.

References __n_assert, _popup_append(), _POPUP_KIND_ROOT, N_GUI_POPUP::ctx, N_GUI_POPUP::entries, N_GUI_POPUP_ROOT, N_GUI_POPUP::on_pick, on_pick(), N_GUI_POPUP::scale, and N_GUI_POPUP::user_data.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_gui_popup_open()

int n_gui_popup_open ( N_GUI_POPUP * popup,
float x,
float y )

Open the top level with its corner at a point.

Below and to the right of the point, pulled back inside the display rather than flipped. Any level already open is closed first.

Parameters
popupthe popup
xscreen x, usually where the click was
yscreen y
Returns
0, or -1 when a window could not be made or nothing is shown.

Definition at line 557 of file n_gui_popup.c.

References _popup_show_level(), n_gui_popup_close(), and N_GUI_POPUP_ROOT.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_gui_popup_press()

int n_gui_popup_press ( N_GUI_POPUP * popup,
int entry )

Press the row of an entry, as a click on it would.

For tests and for keyboard front ends: an item is picked (the popup closes, then on_pick is called), a submenu opens beside its row. The entry's level must be open and the entry shown and enabled.

Parameters
popupthe popup
entrythe entry's id
Returns
1 when something happened, 0 otherwise.

Definition at line 593 of file n_gui_popup.c.

References _popup_activate(), _popup_valid(), N_GUI_POPUP::ctx, N_GUI_POPUP::entries, N_GUI_POPUP_ROOT, n_gui_window_is_open(), _N_GUI_POPUP_ENTRY::nb_rows, _N_GUI_POPUP_ENTRY::parent, _N_GUI_POPUP_ENTRY::rows, and _N_GUI_POPUP_ENTRY::window.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_gui_popup_set_enabled()

void n_gui_popup_set_enabled ( N_GUI_POPUP * popup,
int entry,
int enabled )

Enable or grey out an entry.

A disabled row is drawn greyed, is not highlighted and does nothing when pressed; a disabled submenu does not open.

Parameters
popupthe popup
entryan id returned by one of the add functions
enablednon-zero to enable it

Definition at line 552 of file n_gui_popup.c.

References _popup_valid(), _N_GUI_POPUP_ENTRY::enabled, N_GUI_POPUP::entries, and N_GUI_POPUP_ROOT.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_gui_popup_set_shown()

void n_gui_popup_set_shown ( N_GUI_POPUP * popup,
int entry,
int shown )

Show or hide an entry.

Parameters
popupthe popup
entryan id returned by one of the add functions
shownnon-zero to show it

Definition at line 547 of file n_gui_popup.c.

References _popup_valid(), N_GUI_POPUP::entries, N_GUI_POPUP_ROOT, and _N_GUI_POPUP_ENTRY::shown.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ n_gui_popup_set_title()

void n_gui_popup_set_title ( N_GUI_POPUP * popup,
const char * text )

Set the heading line over the top level.

Not a row that can be picked: it says what the popup is about, a file name or a count. Takes effect at the next n_gui_popup_open().

Parameters
popupthe popup
textthe heading, or NULL or "" for none. Copied.

Definition at line 537 of file n_gui_popup.c.

References N_GUI_POPUP::entries, FreeNoLog, N_GUI_POPUP_ROOT, and _N_GUI_POPUP_ENTRY::text.

Referenced by main().

Here is the caller graph for this function:

◆ n_gui_popup_window()

int n_gui_popup_window ( const N_GUI_POPUP * popup,
int level )

The window of a level, for an application that wants to test it.

Parameters
popupthe popup
levelN_GUI_POPUP_ROOT or a submenu's id
Returns
the window id, or -1 when that level has not been opened yet.

Definition at line 588 of file n_gui_popup.c.

References _popup_is_level(), N_GUI_POPUP::entries, and _N_GUI_POPUP_ENTRY::window.

Referenced by level_window(), and main().

Here is the call graph for this function:
Here is the caller graph for this function: