1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
/* SPDX-License-Identifier: MIT */
/*
* konui.h
*
* Copyright (c) 2026 KonAki
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef KONUI_H
#define KONUI_H
#include <stdint.h>
#include <stddef.h>
#include "konwinlib.h"
#include "konsofren.h"
#include "konfont.h"
#ifdef __cplusplus
extern "C" {
#endif
/*** definition ***/
typedef struct kon_ui kon_ui_t;
typedef struct kon_uiTheme {
uint32_t panel, title, text, textDim, widget, hover, active, accent, border;
int padding, spacing;
} kon_uiTheme_t;
/* you own this, the ui moves it when the title bar is dragged. w is required, h = 0 sizes to the content */
typedef struct kon_uiPanel {
int x, y, w, h;
int collapsed;
int contentH;
} kon_uiPanel_t;
kon_ui_t *kon_uiCreate(kon_font_t *font);
void kon_uiDestroy(kon_ui_t *ui);
kon_uiTheme_t *kon_uiTheme(kon_ui_t *ui);
/* mouse coordinates have to be in the space of the framebuffer you draw to. use kon_windowToGame for the game one */
void kon_uiFeedEvent(kon_ui_t *ui, const kon_event_t *event);
void kon_uiBegin(kon_ui_t *ui, kon_framebuffer_t *fb);
void kon_uiEnd(kon_ui_t *ui);
/* true when the ui is using the mouse or keyboard, so the game should leave them alone */
int kon_uiWantsMouse(const kon_ui_t *ui);
int kon_uiWantsKeyboard(const kon_ui_t *ui);
/* always call kon_uiEndPanel, even when this returned 0 (collapsed) */
int kon_uiBeginPanel(kon_ui_t *ui, const char *title, kon_uiPanel_t *panel);
void kon_uiEndPanel(kon_ui_t *ui);
/*** areas ***/
/* a fixed part of the window with no title and no dragging, for a layout that stays put: a side bar, a list, a preview. what is inside
is clipped to it and scrolls with the wheel when it is taller than the area. you own this and fill in x, y, w and h, the ui keeps
scroll and contentH. contentH is what the last frame needed, so the scroll bar shows up one frame late */
typedef struct kon_uiArea {
int x, y, w, h;
int scroll;
int contentH;
} kon_uiArea_t;
/* returns 0 when it is not drawn (nothing of it is on screen, or it is inside a panel, an area or a menu). always call kon_uiEndArea */
int kon_uiBeginArea(kon_ui_t *ui, const char *id, kon_uiArea_t *area);
void kon_uiEndArea(kon_ui_t *ui);
/*** menus ***/
/* a bar along the top of the window, kon_uiMenuBarHeight is how tall it is so you can lay the rest out under it.
kon_uiBeginMenu gives 1 while that menu is open, and then its items are kon_uiMenuItem, which gives 1 when one is clicked.
always call kon_uiEndMenu and kon_uiEndMenuBar. what is open is drawn over everything at the end of the frame.
a menu is as long as its items, up to 600 pixels, the rest is cut off
if (kon_uiBeginMenuBar(ui)) {
if (kon_uiBeginMenu(ui, "File")) {
if (kon_uiMenuItem(ui, "Open", "Ctrl+O")) open();
kon_uiMenuSeparator(ui);
if (kon_uiMenuItem(ui, "Quit", NULL)) quit();
}
kon_uiEndMenu(ui);
}
kon_uiEndMenuBar(ui);
*/
int kon_uiBeginMenuBar(kon_ui_t *ui);
void kon_uiEndMenuBar(kon_ui_t *ui);
int kon_uiMenuBarHeight(const kon_ui_t *ui);
int kon_uiBeginMenu(kon_ui_t *ui, const char *label);
int kon_uiMenuItem(kon_ui_t *ui, const char *label, const char *shortcut);
void kon_uiMenuSeparator(kon_ui_t *ui);
void kon_uiEndMenu(kon_ui_t *ui);
/* anything after ## in a label is part of the id but not drawn, so "ok##a" and "ok##b" are different buttons */
void kon_uiLabel(kon_ui_t *ui, const char *text);
void kon_uiLabelf(kon_ui_t *ui, const char *format, ...);
int kon_uiButton(kon_ui_t *ui, const char *label);
int kon_uiCheckbox(kon_ui_t *ui, const char *label, int *value);
int kon_uiSliderFloat(kon_ui_t *ui, const char *label, float *value, float min, float max);
int kon_uiSliderInt(kon_ui_t *ui, const char *label, int *value, int min, int max);
int kon_uiSelectable(kon_ui_t *ui, const char *label, int selected);
/* returns 1 when enter is pressed. label is shown while the field is empty */
int kon_uiTextInput(kon_ui_t *ui, const char *label, char *buffer, size_t size);
/* a row of tabs, current is the one shown. returns 1 when another one was clicked */
int kon_uiTabs(kon_ui_t *ui, const char *const *labels, int count, int *current);
/* a line with a + or - in front that opens and closes. returns the new open state, show what is inside when it is 1 and use
kon_uiIndent to push it in */
int kon_uiTreeNode(kon_ui_t *ui, const char *label, int *open);
void kon_uiIndent(kon_ui_t *ui, int amount);
/* a picture drawn at width x height pixels (scaled to it) on a checkerboard, so see through parts show. image can be NULL for just the board */
void kon_uiImage(kon_ui_t *ui, kon_image *image, int width, int height);
void kon_uiSeparator(kon_ui_t *ui);
void kon_uiSameLine(kon_ui_t *ui);
/* the width in pixels of the next widget, for a row of buttons. it is back to the full width after that one widget */
void kon_uiNextWidth(kon_ui_t *ui, int width);
void kon_uiPushId(kon_ui_t *ui, int id);
void kon_uiPopId(kon_ui_t *ui);
kon_rect_t kon_uiLastRect(const kon_ui_t *ui);
#ifdef __cplusplus
}
#endif
#endif
|