2023-07-01 10:55:19 +00:00
|
|
|
/*
|
|
|
|
imui.h
|
|
|
|
|
|
|
|
Immediate mode user interface
|
|
|
|
|
|
|
|
Copyright (C) 2023 Bill Currie <bill@taniwha.org>
|
|
|
|
|
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
Date: 2023/07/01
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __QF_ui_imui_h
|
|
|
|
#define __QF_ui_imui_h
|
|
|
|
|
2023-07-13 05:08:13 +00:00
|
|
|
#include "QF/ui/view.h"
|
2023-07-11 03:04:32 +00:00
|
|
|
|
2023-07-01 10:55:19 +00:00
|
|
|
typedef struct imui_ctx_s imui_ctx_t;
|
|
|
|
struct canvas_system_s;
|
2023-07-01 16:25:27 +00:00
|
|
|
struct IE_event_s;
|
2023-07-01 10:55:19 +00:00
|
|
|
|
2023-07-04 15:40:29 +00:00
|
|
|
enum {
|
|
|
|
imui_percent_x, ///< int
|
|
|
|
imui_percent_y, ///< int
|
2023-07-13 05:08:13 +00:00
|
|
|
imui_reference, ///< imui_reference_t
|
2023-07-04 15:40:29 +00:00
|
|
|
|
|
|
|
imui_comp_count
|
|
|
|
};
|
|
|
|
|
2023-07-11 03:04:32 +00:00
|
|
|
extern const component_t imui_components[imui_comp_count];
|
2023-07-04 15:40:29 +00:00
|
|
|
|
2023-07-05 15:15:34 +00:00
|
|
|
typedef enum {
|
|
|
|
imui_size_none,
|
|
|
|
imui_size_pixels,
|
|
|
|
imui_size_fittext,
|
|
|
|
imui_size_percent,
|
|
|
|
imui_size_fitchildren,
|
|
|
|
imui_size_expand,
|
|
|
|
} imui_size_t;
|
2023-07-01 10:55:19 +00:00
|
|
|
|
2023-07-05 16:27:46 +00:00
|
|
|
typedef union imui_color_s {
|
|
|
|
struct {
|
|
|
|
uint32_t normal;
|
|
|
|
uint32_t hot;
|
|
|
|
uint32_t active;
|
|
|
|
};
|
|
|
|
uint32_t color[3];
|
|
|
|
} imui_color_t;
|
|
|
|
|
|
|
|
typedef struct imui_style_s {
|
|
|
|
imui_color_t background;
|
|
|
|
imui_color_t foreground;
|
|
|
|
imui_color_t text;
|
|
|
|
} imui_style_t;
|
|
|
|
|
2023-07-13 05:08:13 +00:00
|
|
|
typedef struct imui_reference_s {
|
|
|
|
uint32_t ref_id;
|
|
|
|
} imui_reference_t;
|
|
|
|
|
2023-07-06 03:21:14 +00:00
|
|
|
typedef struct imui_window_s {
|
|
|
|
const char *name;
|
|
|
|
int xpos;
|
|
|
|
int ypos;
|
|
|
|
int xlen;
|
|
|
|
int ylen;
|
2023-07-12 01:17:43 +00:00
|
|
|
int group_offset;
|
2023-07-10 15:26:45 +00:00
|
|
|
int mode;
|
2023-07-06 03:21:14 +00:00
|
|
|
bool is_open;
|
|
|
|
bool is_collapsed;
|
2023-07-13 05:08:13 +00:00
|
|
|
|
|
|
|
const char *reference;
|
|
|
|
grav_t reference_gravity;
|
|
|
|
grav_t anchor_gravity;
|
2023-07-13 14:16:26 +00:00
|
|
|
struct imui_window_s *parent; // for submenus
|
|
|
|
bool no_collapse;
|
2023-07-06 03:21:14 +00:00
|
|
|
} imui_window_t;
|
|
|
|
|
2023-08-07 08:42:59 +00:00
|
|
|
typedef struct imui_io_s {
|
|
|
|
view_pos_t mouse;
|
2023-08-07 13:20:34 +00:00
|
|
|
uint32_t buttons;
|
|
|
|
uint32_t pressed;
|
|
|
|
uint32_t released;
|
2023-08-07 08:42:59 +00:00
|
|
|
uint32_t hot;
|
|
|
|
uint32_t active;
|
|
|
|
} imui_io_t;
|
|
|
|
|
2023-07-01 10:55:19 +00:00
|
|
|
imui_ctx_t *IMUI_NewContext (struct canvas_system_s canvas_sys,
|
|
|
|
const char *font, float fontsize);
|
|
|
|
void IMUI_DestroyContext (imui_ctx_t *ctx);
|
|
|
|
|
|
|
|
void IMUI_SetVisible (imui_ctx_t *ctx, bool visible);
|
|
|
|
void IMUI_SetSize (imui_ctx_t *ctx, int xlen, int ylen);
|
2023-07-14 02:25:50 +00:00
|
|
|
bool IMUI_ProcessEvent (imui_ctx_t *ctx, const struct IE_event_s *ie_event);
|
2023-08-07 08:42:59 +00:00
|
|
|
imui_io_t IMUI_GetIO (imui_ctx_t *ctx) __attribute__((pure));
|
2023-07-01 16:25:27 +00:00
|
|
|
void IMUI_BeginFrame (imui_ctx_t *ctx);
|
2023-07-01 10:55:19 +00:00
|
|
|
void IMUI_Draw (imui_ctx_t *ctx);
|
|
|
|
|
2023-07-13 05:08:13 +00:00
|
|
|
int IMUI_PushLayout (imui_ctx_t *ctx, bool vertical);
|
2023-07-03 16:31:04 +00:00
|
|
|
void IMUI_PopLayout (imui_ctx_t *ctx);
|
2023-07-06 10:24:23 +00:00
|
|
|
void IMUI_Layout_SetXSize (imui_ctx_t *ctx, imui_size_t size, int value);
|
|
|
|
void IMUI_Layout_SetYSize (imui_ctx_t *ctx, imui_size_t size, int value);
|
2023-07-03 16:31:04 +00:00
|
|
|
|
2023-07-13 05:08:13 +00:00
|
|
|
int IMUI_PushStyle (imui_ctx_t *ctx, const imui_style_t *style);
|
2023-07-06 10:34:48 +00:00
|
|
|
void IMUI_PopStyle (imui_ctx_t *ctx);
|
|
|
|
void IMUI_Style_Update (imui_ctx_t *ctx, const imui_style_t *style);
|
|
|
|
void IMUI_Style_Fetch (const imui_ctx_t *ctx, imui_style_t *style);
|
|
|
|
|
|
|
|
void IMUI_Label (imui_ctx_t *ctx, const char *label);
|
2023-07-09 03:10:28 +00:00
|
|
|
void IMUI_Labelf (imui_ctx_t *ctx, const char *fmt, ...)__attribute__((format(PRINTF,2,3)));
|
2023-07-01 10:55:19 +00:00
|
|
|
bool IMUI_Button (imui_ctx_t *ctx, const char *label);
|
|
|
|
bool IMUI_Checkbox (imui_ctx_t *ctx, bool *flag, const char *label);
|
2023-07-03 16:31:04 +00:00
|
|
|
void IMUI_Radio (imui_ctx_t *ctx, int *curvalue, int value, const char *label);
|
2023-07-01 10:55:19 +00:00
|
|
|
void IMUI_Slider (imui_ctx_t *ctx, float *value, float minval, float maxval,
|
|
|
|
const char *label);
|
2023-07-10 13:10:04 +00:00
|
|
|
void IMUI_Spacer (imui_ctx_t *ctx,
|
|
|
|
imui_size_t xsize, int xvalue,
|
|
|
|
imui_size_t ysize, int yvalue);
|
2023-07-01 10:55:19 +00:00
|
|
|
|
2023-07-13 05:08:13 +00:00
|
|
|
int IMUI_StartPanel (imui_ctx_t *ctx, imui_window_t *panel);
|
|
|
|
int IMUI_ExtendPanel (imui_ctx_t *ctx, const char *panel_name);
|
2023-07-10 15:26:45 +00:00
|
|
|
void IMUI_EndPanel (imui_ctx_t *ctx);
|
|
|
|
|
2023-07-13 14:16:26 +00:00
|
|
|
int IMUI_StartMenu (imui_ctx_t *ctx, imui_window_t *menu, bool vertical);
|
|
|
|
void IMUI_EndMenu (imui_ctx_t *ctx);
|
|
|
|
bool IMUI_MenuItem (imui_ctx_t *ctx, const char *label, bool collapse);
|
|
|
|
|
2023-07-13 05:08:13 +00:00
|
|
|
int IMUI_StartWindow (imui_ctx_t *ctx, imui_window_t *window);
|
2023-07-06 10:24:23 +00:00
|
|
|
void IMUI_EndWindow (imui_ctx_t *ctx);
|
2023-07-06 10:34:48 +00:00
|
|
|
|
2023-07-03 16:31:04 +00:00
|
|
|
#define IMUI_DeferLoop(begin, end) \
|
2023-07-13 05:08:13 +00:00
|
|
|
for (int _i_ = (begin); !_i_; _i_++, (end))
|
2023-07-03 16:31:04 +00:00
|
|
|
|
2023-07-01 10:55:19 +00:00
|
|
|
// #define IMUI_context to an imui_ctx_t * variable
|
|
|
|
|
2023-07-06 10:34:48 +00:00
|
|
|
#define UI_Label(label) \
|
|
|
|
IMUI_Label(IMUI_context, label)
|
|
|
|
|
2023-07-09 03:10:28 +00:00
|
|
|
#define UI_Labelf(fmt...) \
|
|
|
|
IMUI_Labelf(IMUI_context, fmt)
|
|
|
|
|
2023-07-01 10:55:19 +00:00
|
|
|
#define UI_Button(label) \
|
|
|
|
IMUI_Button(IMUI_context, label)
|
|
|
|
|
|
|
|
#define UI_Checkbox(flag, label) \
|
|
|
|
IMUI_Checkbox(IMUI_context, flag, label)
|
|
|
|
|
|
|
|
#define UI_Radio(state, value, label) \
|
|
|
|
IMUI_Radio(IMUI_context, state, value, label)
|
|
|
|
|
|
|
|
#define UI_Slider(value, minval, maxval, label) \
|
|
|
|
IMUI_Slider(IMUI_context, value, minval, maxval, label)
|
|
|
|
|
2023-07-04 15:40:29 +00:00
|
|
|
#define UI_FlexibleSpace() \
|
2023-07-10 13:10:04 +00:00
|
|
|
IMUI_Spacer(IMUI_context, imui_size_expand, 100, imui_size_expand, 100)
|
2023-07-04 15:40:29 +00:00
|
|
|
|
2023-07-03 16:31:04 +00:00
|
|
|
#define UI_Layout(vertical) \
|
|
|
|
IMUI_DeferLoop (IMUI_PushLayout (IMUI_context, vertical), \
|
|
|
|
IMUI_PopLayout (IMUI_context ))
|
|
|
|
|
2023-07-10 15:26:45 +00:00
|
|
|
#define UI_Panel(panel) \
|
|
|
|
IMUI_DeferLoop (IMUI_StartPanel (IMUI_context, panel), \
|
|
|
|
IMUI_EndPanel (IMUI_context))
|
|
|
|
|
2023-07-13 05:08:13 +00:00
|
|
|
#define UI_ExtendPanel(panel_name) \
|
|
|
|
IMUI_DeferLoop (IMUI_ExtendPanel (IMUI_context, panel_name), \
|
|
|
|
IMUI_EndPanel (IMUI_context))
|
|
|
|
|
2023-07-13 14:16:26 +00:00
|
|
|
#define UI_Menu(menu) \
|
|
|
|
IMUI_DeferLoop (IMUI_StartMenu (IMUI_context, menu, true), \
|
|
|
|
IMUI_EndMenu (IMUI_context))
|
|
|
|
|
|
|
|
#define UI_MenuBar(menu) \
|
|
|
|
IMUI_DeferLoop (IMUI_StartMenu (IMUI_context, menu, false), \
|
|
|
|
IMUI_EndMenu (IMUI_context))
|
|
|
|
|
|
|
|
#define UI_MenuItem(label) \
|
|
|
|
IMUI_MenuItem (IMUI_context, label, true)
|
|
|
|
|
2023-07-06 03:21:14 +00:00
|
|
|
#define UI_Window(window) \
|
|
|
|
IMUI_DeferLoop (IMUI_StartWindow (IMUI_context, window), \
|
|
|
|
IMUI_EndWindow (IMUI_context))
|
|
|
|
|
2023-07-06 10:34:48 +00:00
|
|
|
#define UI_Style(style) \
|
|
|
|
IMUI_DeferLoop (IMUI_PushStyle (IMUI_context, style), \
|
|
|
|
IMUI_PopStyle (IMUI_context ))
|
|
|
|
|
2023-07-04 15:40:29 +00:00
|
|
|
#define UI_Horizontal UI_Layout(false)
|
|
|
|
#define UI_Vertical UI_Layout(true)
|
|
|
|
|
2023-07-01 10:55:19 +00:00
|
|
|
#endif//__QF_ui_imui_h
|