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
|
/* 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);
/* 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);
void kon_uiSeparator(kon_ui_t *ui);
void kon_uiSameLine(kon_ui_t *ui);
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
|