6 n__gui__popup_8h
gullradriel edited this page 2026-10-09 00:55:18 +02:00

include/nilorea/n_gui_popup.h

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

Detailed Description

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

Author: Castagnier Mickael

Version: 1.0

Date: 29/09/2026

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.

Source code

/*
 * Nilorea Library
 * Copyright (C) 2005-2026 Castagnier Mickael
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 */


#ifndef __NILOREA_GUI_POPUP__
#define __NILOREA_GUI_POPUP__

/* Allegro only: the popup is N_GUI windows and custom widgets. */
#ifdef HAVE_ALLEGRO

#ifdef __cplusplus
extern "C" {
#endif


#include "nilorea/n_gui.h"

#define N_GUI_POPUP_ROOT 0

typedef struct N_GUI_POPUP N_GUI_POPUP;

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

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

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

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

int n_gui_popup_add_separator(N_GUI_POPUP* popup, int parent);

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

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

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

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

void n_gui_popup_close(N_GUI_POPUP* popup);

int n_gui_popup_is_open(const N_GUI_POPUP* popup);

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

int n_gui_popup_window(const N_GUI_POPUP* popup, int level);

int n_gui_popup_press(N_GUI_POPUP* popup, int entry);

void n_gui_popup_free(N_GUI_POPUP** popup);


#ifdef __cplusplus
}
#endif

#endif /* HAVE_ALLEGRO */

#endif /* __NILOREA_GUI_POPUP__ */