Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_gui_popup.h File Reference

A popup menu with submenus for N_GUI, the kind a right click opens. More...

#include "nilorea/n_gui.h"
Include dependency graph for n_gui_popup.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

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

A popup menu with submenus for N_GUI, the kind a right click opens.

A popup is a tree of entries: items, which call back with a tag when picked, submenus, which open beside their row when the pointer rests on it or presses it, and separators. Each level is a frameless popup window holding one owner-drawn widget, so the rows read as a menu: text on the left, an arrow on a submenu's row, the row under the pointer highlighted, greyed rows for what cannot be done now.

The tree is built once. What changes with the context is which entries are shown and which are enabled: n_gui_popup_set_shown() and n_gui_popup_set_enabled() before n_gui_popup_open(). A submenu left with no shown entry is not shown either, and separators never stack up or sit at either end of a level, so hiding entries leaves nothing stray behind.

The popup closes itself when an item is picked, before calling back, so a dialog the callback opens is not opened under it. Closing it on a press elsewhere or on Escape is the application's: n_gui_popup_hit() says whether a point is on any of its levels.

Not to be confused with n_gui_menu_is_open(), which is about the list of an open combo box or drop menu.

Author
Castagnier Mickael
Version
1.0
Date
29/09/2026

Definition in file n_gui_popup.h.