Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
ex_gui_detach.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "nilorea/n_common.h"
#include "nilorea/n_gui.h"
#include "nilorea/n_log.h"
+ Include dependency graph for ex_gui_detach.c:

Go to the source code of this file.

Data Structures

struct  DEMO_PANEL
 one demo panel: a window plus the button that detaches / attaches it More...
 

Macros

#define ALLEGRO_UNSTABLE   1
 
#define HEIGHT   640
 
#define LAYOUT_FILE   "ex_gui_detach_layout.json"
 
#define WIDTH   960
 

Functions

static int build_panel (const char *title, float x, float y, float w, float h, int detach_flags, const char *name)
 build one demo panel: a few ordinary widgets plus its detach button
 
int main (int argc, char **argv)
 
static void on_attach_all (int widget_id, void *user_data)
 
static void on_detach_all (int widget_id, void *user_data)
 
static void on_load_layout (int widget_id, void *user_data)
 
static void on_panel_close (int window_id, void *user_data)
 A native window's close button (the window manager's, or N_GUI's own when the panel keeps its chrome) lands here exactly like a pop-up's would.
 
static void on_save_layout (int widget_id, void *user_data)
 
static void on_show_all (int widget_id, void *user_data)
 
static void on_slider_change (int widget_id, double value, void *user_data)
 
static void on_toggle_detach (int widget_id, void *user_data)
 the per-panel button: toggle this panel between pop-up and native window
 
static DEMO_PANELpanel_of (int window_id)
 find the panel a window id belongs to, or NULL
 
static void process_args (int argc, char **argv)
 
static void refresh_buttons (void)
 keep each panel's button label in sync with what it will do next
 

Variables

static int auto_detach = 0
 1 to detach every panel at startup (-a)
 
static int DONE = 0
 
static N_GUI_CTXgui = NULL
 
static int lbl_hint = -1
 
static int lbl_status = -1
 
static int log_level = 5
 
static int nb_panels = 0
 
static int notes_txt = -1
 text area of the "Notes" panel, used by the copy/paste hint
 
static DEMO_PANEL panels [3]
 
static double quit_after = 0.0
 seconds after which the demo quits on its own (0 = run until ESC)
 

Data Structure Documentation

◆ DEMO_PANEL

struct DEMO_PANEL

one demo panel: a window plus the button that detaches / attaches it

Examples
ex_gui_detach.c.

Definition at line 60 of file ex_gui_detach.c.

+ Collaboration diagram for DEMO_PANEL:
Data Fields
int btn id of the panel's own detach / attach button
int detach_flags options this panel detaches with (N_GUI_DETACH_*)
const char * name short name used in the status line
int win window id

Macro Definition Documentation

◆ ALLEGRO_UNSTABLE

#define ALLEGRO_UNSTABLE   1

Definition at line 44 of file ex_gui_detach.c.

◆ HEIGHT

#define HEIGHT   640

Definition at line 56 of file ex_gui_detach.c.

◆ LAYOUT_FILE

#define LAYOUT_FILE   "ex_gui_detach_layout.json"
Examples
ex_gui_detach.c.

Definition at line 57 of file ex_gui_detach.c.

◆ WIDTH

#define WIDTH   960

Definition at line 55 of file ex_gui_detach.c.

Function Documentation

◆ build_panel()

static int build_panel ( const char *  title,
float  x,
float  y,
float  w,
float  h,
int  detach_flags,
const char *  name 
)
static

build one demo panel: a few ordinary widgets plus its detach button

Examples
ex_gui_detach.c.

Definition at line 237 of file ex_gui_detach.c.

References DEMO_PANEL::btn, DEMO_PANEL::detach_flags, gui, n_gui_add_button(), n_gui_add_window(), n_gui_set_widget_tooltip(), N_GUI_SHAPE_ROUNDED, N_GUI_WIN_BTN_ALL, N_GUI_WIN_RESIZABLE, n_gui_window_set_close_callback(), n_gui_window_set_flags(), DEMO_PANEL::name, nb_panels, on_panel_close(), on_toggle_detach(), panels, and DEMO_PANEL::win.

Referenced by main().

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

◆ main()

◆ on_attach_all()

static void on_attach_all ( int  widget_id,
void *  user_data 
)
static
Examples
ex_gui_detach.c.

Definition at line 180 of file ex_gui_detach.c.

References gui, n_gui_window_attach(), nb_panels, panels, and refresh_buttons().

Referenced by main().

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

◆ on_detach_all()

static void on_detach_all ( int  widget_id,
void *  user_data 
)
static
Examples
ex_gui_detach.c.

Definition at line 170 of file ex_gui_detach.c.

References gui, n_gui_window_detach(), n_gui_window_is_detached(), nb_panels, panels, and refresh_buttons().

Referenced by main().

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

◆ on_load_layout()

static void on_load_layout ( int  widget_id,
void *  user_data 
)
static
Examples
ex_gui_detach.c.

Definition at line 220 of file ex_gui_detach.c.

References gui, LAYOUT_FILE, LOG_ERR, LOG_NOTICE, n_gui_load_layout_json(), n_log, and refresh_buttons().

Referenced by main().

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

◆ on_panel_close()

static void on_panel_close ( int  window_id,
void *  user_data 
)
static

A native window's close button (the window manager's, or N_GUI's own when the panel keeps its chrome) lands here exactly like a pop-up's would.

The display itself is released at the next n_gui_draw_detached, never from inside this callback.

Examples
ex_gui_detach.c.

Definition at line 193 of file ex_gui_detach.c.

References gui, LOG_NOTICE, n_gui_close_window(), n_log, DEMO_PANEL::name, and panel_of().

Referenced by build_panel().

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

◆ on_save_layout()

static void on_save_layout ( int  widget_id,
void *  user_data 
)
static
Examples
ex_gui_detach.c.

Definition at line 211 of file ex_gui_detach.c.

References gui, LAYOUT_FILE, LOG_ERR, LOG_NOTICE, n_gui_save_layout_json(), and n_log.

Referenced by main().

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

◆ on_show_all()

static void on_show_all ( int  widget_id,
void *  user_data 
)
static
Examples
ex_gui_detach.c.

Definition at line 200 of file ex_gui_detach.c.

References gui, n_gui_open_window(), nb_panels, panels, and refresh_buttons().

Referenced by main().

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

◆ on_slider_change()

static void on_slider_change ( int  widget_id,
double  value,
void *  user_data 
)
static

Definition at line 230 of file ex_gui_detach.c.

References LOG_INFO, and n_log.

◆ on_toggle_detach()

static void on_toggle_detach ( int  widget_id,
void *  user_data 
)
static

the per-panel button: toggle this panel between pop-up and native window

Examples
ex_gui_detach.c.

Definition at line 155 of file ex_gui_detach.c.

References DEMO_PANEL::detach_flags, gui, LOG_ERR, LOG_NOTICE, n_gui_window_attach(), n_gui_window_detach(), n_gui_window_is_detached(), n_log, DEMO_PANEL::name, refresh_buttons(), and DEMO_PANEL::win.

Referenced by build_panel().

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

◆ panel_of()

static DEMO_PANEL * panel_of ( int  window_id)
static

find the panel a window id belongs to, or NULL

Examples
ex_gui_detach.c.

Definition at line 126 of file ex_gui_detach.c.

References nb_panels, and panels.

Referenced by on_panel_close().

+ Here is the caller graph for this function:

◆ process_args()

static void process_args ( int  argc,
char **  argv 
)
static

Definition at line 86 of file ex_gui_detach.c.

References auto_detach, LOG_DEBUG, LOG_ERR, LOG_INFO, log_level, LOG_NOTICE, LOG_NULL, n_log, quit_after, and set_log_level().

+ Here is the call graph for this function:

◆ refresh_buttons()

static void refresh_buttons ( void  )
static

keep each panel's button label in sync with what it will do next

Examples
ex_gui_detach.c.

Definition at line 134 of file ex_gui_detach.c.

References gui, lbl_status, n_gui_button_set_label(), n_gui_count_detached(), n_gui_label_set_text(), n_gui_window_is_detached(), DEMO_PANEL::name, nb_panels, and panels.

Referenced by main(), on_attach_all(), on_detach_all(), on_load_layout(), on_show_all(), and on_toggle_detach().

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

Variable Documentation

◆ auto_detach

int auto_detach = 0
static

1 to detach every panel at startup (-a)

Examples
ex_gui_detach.c.

Definition at line 76 of file ex_gui_detach.c.

Referenced by main(), and process_args().

◆ DONE

int DONE = 0
static

Definition at line 72 of file ex_gui_detach.c.

◆ gui

◆ lbl_hint

int lbl_hint = -1
static
Examples
ex_gui_detach.c.

Definition at line 82 of file ex_gui_detach.c.

Referenced by main().

◆ lbl_status

int lbl_status = -1
static

Definition at line 81 of file ex_gui_detach.c.

◆ log_level

int log_level = 5
static

Definition at line 71 of file ex_gui_detach.c.

◆ nb_panels

int nb_panels = 0
static

◆ notes_txt

int notes_txt = -1
static

text area of the "Notes" panel, used by the copy/paste hint

Examples
ex_gui_detach.c.

Definition at line 84 of file ex_gui_detach.c.

Referenced by main().

◆ panels

DEMO_PANEL panels[3]
static

◆ quit_after

double quit_after = 0.0
static

seconds after which the demo quits on its own (0 = run until ESC)

Examples
ex_gui_detach.c.

Definition at line 74 of file ex_gui_detach.c.

Referenced by main(), and process_args().