/* 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 #include #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