implement theming

This commit is contained in:
waozi committed 2026-05-27 00:48:45 -03:00
1 parent 310a822ea5
commit c0a9484d7e
23 files changed
+1853 -235

No files matched your search

+21
View File
@@ -1,4 +1,25 @@
# Changelog
## [1.0.4] - 2026-05-26
### Added
- Centralized icon size management system (SMALL, MEDIUM, LARGE)
- Standardized icon button functions for consistent sizing
### Fixed
- Improved accessibility with larger icons for older users (+25-37%)
- DPI scaling for all button padding and bevel borders on mobile
- X button positioning and scaling on high DPI screens
- Button dimensions and icon centering across all screens
- Missing icons (telegram, globe, stripe, monero, home, trash) in WebAssembly build
## [1.0.3] - 2026-05-26
### Fixed
- Improved DPI scaling for scrollbars (width and thumb height now scale properly)
- Fixed scrollbar not appearing on tall viewports/settings screens (content height now scales correctly)
- Fixed X icon too small on mobile (increased max size from 18px to 28px for better touch targets)
- Improved scrollbar thumb touch hit area for easier grabbing
- Fixed missing breath sounds during recovery phase (breath in at start, breath out after 15-second hold)
### Added
- Added external links in settings (Telegram, Website, Monero, Stripe donation)
- Added content-area drag scrolling for mobile (click and drag anywhere to scroll)
## [1.0.2] - 2026-05-26
### Fixed
+8 -2
View File
@@ -1,7 +1,7 @@
CC = gcc
WINDRES = windres
SRC = src/main.c src/app.c ../liblotus/src/theme.c
SRC = src/main.c src/app.c src/ui.c src/theme_meta.c ../liblotus/src/theme.c
INBE_DIR = libinbe
INBE_A = $(INBE_DIR)/libinbe.a
@@ -79,7 +79,7 @@ WEB_RAYLIB_OBJS = \
$(WEB_RAYLIB_BUILD_DIR)/raudio.o
WEB_CFLAGS = -Wall -Wextra -std=gnu99 -Os -DPLATFORM_WEB -DGRAPHICS_API_OPENGL_ES2 -D_DEFAULT_SOURCE -DSUPPORT_MODULE_RAUDIO=1 -DSUPPORT_FILEFORMAT_JPG=1 -DSUPPORT_FILEFORMAT_OGG=1
WEB_SHELL = src/web_shell.html
WEB_LDFLAGS = -sUSE_GLFW=3 -sASYNCIFY -sALLOW_MEMORY_GROWTH=1 --shell-file $(WEB_SHELL) --preload-file [email protected] --preload-file [email protected] --preload-file ../icons/gear.png@icons/gear.png --preload-file ../icons/x.png@icons/x.png --preload-file ../icons/manual.png@icons/manual.png --preload-file ../icons/return.png@icons/return.png --preload-file ../icons/backward.png@icons/backward.png --preload-file ../icons/forward.png@icons/forward.png --preload-file ../icons/play.png@icons/play.png --preload-file ../icons/pause.png@icons/pause.png --preload-file ../icons/stat.png@icons/stat.png --preload-file assets/angel.jpg@assets/angel.jpg --preload-file assets/begin.jpg@assets/begin.jpg --preload-file assets/sounds/breath-in.ogg@assets/sounds/breath-in.ogg --preload-file assets/sounds/breath-out.ogg@assets/sounds/breath-out.ogg --preload-file assets/sounds/bell.ogg@assets/sounds/bell.ogg
WEB_LDFLAGS = -sUSE_GLFW=3 -sASYNCIFY -sALLOW_MEMORY_GROWTH=1 --shell-file $(WEB_SHELL) --preload-file [email protected] --preload-file [email protected] --preload-file themes/sky.ini@themes/sky.ini --preload-file themes/sky_dark.ini@themes/sky_dark.ini --preload-file themes/ocean.ini@themes/ocean.ini --preload-file themes/ocean_dark.ini@themes/ocean_dark.ini --preload-file themes/forest.ini@themes/forest.ini --preload-file themes/forest_dark.ini@themes/forest_dark.ini --preload-file themes/sunset.ini@themes/sunset.ini --preload-file themes/sunset_dark.ini@themes/sunset_dark.ini --preload-file themes/lavender.ini@themes/lavender.ini --preload-file themes/lavender_dark.ini@themes/lavender_dark.ini --preload-file ../icons/gear.png@icons/gear.png --preload-file ../icons/x.png@icons/x.png --preload-file ../icons/manual.png@icons/manual.png --preload-file ../icons/return.png@icons/return.png --preload-file ../icons/backward.png@icons/backward.png --preload-file ../icons/forward.png@icons/forward.png --preload-file ../icons/play.png@icons/play.png --preload-file ../icons/pause.png@icons/pause.png --preload-file ../icons/stat.png@icons/stat.png --preload-file ../icons/home.png@icons/home.png --preload-file ../icons/trash.png@icons/trash.png --preload-file ../icons/telegram.png@icons/telegram.png --preload-file ../icons/globe.png@icons/globe.png --preload-file ../icons/stripe.png@icons/stripe.png --preload-file ../icons/monero.png@icons/monero.png --preload-file assets/angel.jpg@assets/angel.jpg --preload-file assets/begin.jpg@assets/begin.jpg --preload-file assets/sounds/breath-in.ogg@assets/sounds/breath-in.ogg --preload-file assets/sounds/breath-out.ogg@assets/sounds/breath-out.ogg --preload-file assets/sounds/bell.ogg@assets/sounds/bell.ogg
INBE_RAYLIB_CONFIG = $(filter-out -DSUPPORT_MODULE_RAUDIO=0 -DSUPPORT_FILEFORMAT_PNG=0 -DSUPPORT_FILEFORMAT_JPG=0 -DSUPPORT_FILEFORMAT_OGG=0,$(RAY_RAYLIB_CONFIG)) -DSUPPORT_MODULE_RAUDIO=1 -DSUPPORT_FILEFORMAT_JPG=1 -DSUPPORT_FILEFORMAT_OGG=1
CFLAGS = -Wall -Wextra -std=c99 -Os -ffunction-sections -fdata-sections -DSUPPORT_FILEFORMAT_JPG=1
@@ -368,6 +368,8 @@ dist-linux: linux
exit 1; \
fi
@cp inbe.ini theme.ini $(LINUX_BUILD_DIR)/dist/inbe-linux/
@mkdir -p $(LINUX_BUILD_DIR)/dist/inbe-linux/themes
@cp themes/*.ini $(LINUX_BUILD_DIR)/dist/inbe-linux/themes/
@mkdir -p $(LINUX_BUILD_DIR)/dist/inbe-linux/icons
@cp ../icons/gear.png ../icons/x.png ../icons/manual.png ../icons/return.png ../icons/backward.png ../icons/forward.png ../icons/play.png ../icons/pause.png ../icons/stat.png $(LINUX_BUILD_DIR)/dist/inbe-linux/icons/
@mkdir -p $(LINUX_BUILD_DIR)/dist/inbe-linux/assets
@@ -392,6 +394,8 @@ dist-windows:
exit 1; \
fi
@cp inbe.ini theme.ini $(WINDOWS_BUILD_DIR)/dist/inbe-windows/
@mkdir -p $(WINDOWS_BUILD_DIR)/dist/inbe-windows/themes
@cp themes/*.ini $(WINDOWS_BUILD_DIR)/dist/inbe-windows/themes/
@mkdir -p $(WINDOWS_BUILD_DIR)/dist/inbe-windows/icons
@cp ../icons/gear.png ../icons/x.png ../icons/manual.png ../icons/return.png ../icons/backward.png ../icons/forward.png ../icons/play.png ../icons/pause.png ../icons/stat.png $(WINDOWS_BUILD_DIR)/dist/inbe-windows/icons/
@mkdir -p $(WINDOWS_BUILD_DIR)/dist/inbe-windows/assets
@@ -423,6 +427,8 @@ android-copy-assets:
mkdir -p $(ANDROID_DIR)/app/src/main/assets
cp inbe.ini $(ANDROID_DIR)/app/src/main/assets/inbe.ini
cp theme.ini $(ANDROID_DIR)/app/src/main/assets/theme.ini
mkdir -p $(ANDROID_DIR)/app/src/main/assets/themes
cp themes/*.ini $(ANDROID_DIR)/app/src/main/assets/themes/
mkdir -p $(ANDROID_DIR)/app/src/main/assets/icons
@for icon in ../icons/*.png; do \
base=$$(basename "$$icon"); \
+2 -2
View File
@@ -29,8 +29,8 @@ android {
defaultConfig {
minSdk 19
targetSdk 35
versionCode 3
versionName "1.0.2"
versionCode 5
versionName "1.0.4"
}
+8 -4
View File
@@ -1,6 +1,10 @@
speed 6
max_rounds 4
speed 9
max_rounds 6
max_breaths 30
pause_seconds 2
sound_volume 100
pause_seconds 17
sound_volume 36
tutorial_seen 1
theme 1
dark_mode 0
last_bell 0
fullscreen 0
+923 -222
View File
File diff suppressed because it is too large. Load diff
+19
View File
@@ -23,6 +23,11 @@ struct InbeApp {
Texture2D stat_icon;
Texture2D home_icon;
Texture2D trash_icon;
Texture2D telegram_icon;
Texture2D globe_icon;
Texture2D stripe_icon;
Texture2D monero_icon;
Texture2D angel_image;
Texture2D begin_image;
Sound breath_in_sound;
@@ -37,11 +42,25 @@ struct InbeApp {
int settings_scroll;
int settings_drag_slider;
int settings_drag_scrollbar;
int settings_drag_content; /* Drag content area to scroll */
int settings_drag_content_y; /* Initial Y position when drag starts */
int settings_dirty;
int settings_tab;
int settings_dropdown_open;
int last_bell_enabled; /* Play bell on last breath */
int fullscreen_enabled; /* Fullscreen mode */
int manual_scroll;
int manual_drag_scrollbar;
int manual_drag_content;
int manual_drag_content_y;
int tutorial_step;
int tutorial_seen;
int theme_id;
int dark_mode;
int history_scroll;
int history_drag_scrollbar;
int history_drag_content;
int history_drag_content_y;
int history_level;
int history_year;
int history_month;
+7
View File
@@ -56,6 +56,13 @@ int main(int argc, char **argv) {
#endif
inbe_app_init(&inbe_app);
#if !defined(PLATFORM_ANDROID) && !defined(__ANDROID__) && !defined(ANDROID) && !defined(PLATFORM_WEB)
/* Apply fullscreen setting on startup */
if(inbe_app.fullscreen_enabled && !IsWindowFullscreen())
ToggleFullscreen();
#endif
SetTargetFPS(60);
#if defined(PLATFORM_WEB)
+9
View File
@@ -0,0 +1,9 @@
#include "theme_meta.h"
const ThemeMeta g_themes[THEME_COUNT] = {
[ThemeSky] = {"Sky", "sky_light", "sky_dark"},
[ThemeOcean] = {"Ocean", "ocean_light", "ocean_dark"},
[ThemeForest] = {"Forest", "forest_light", "forest_dark"},
[ThemeSunset] = {"Sunset", "sunset_light", "sunset_dark"},
[ThemeLavender] = {"Lavender", "lavender_light", "lavender_dark"}
};
+22
View File
@@ -0,0 +1,22 @@
#ifndef THEME_META_H
#define THEME_META_H
#define THEME_COUNT 5
typedef enum {
ThemeSky = 0,
ThemeOcean = 1,
ThemeForest = 2,
ThemeSunset = 3,
ThemeLavender = 4
} ThemeId;
typedef struct {
const char *name;
const char *light_scope;
const char *dark_scope;
} ThemeMeta;
extern const ThemeMeta g_themes[THEME_COUNT];
#endif
+619
View File
@@ -0,0 +1,619 @@
#include "ui.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Constants */
enum {
ICON_SIZE_SMALL = 22,
ICON_SIZE_MEDIUM = 26,
ICON_SIZE_LARGE = 30,
ICON_SIZE_SMALL_MIN = 20,
ICON_SIZE_SMALL_MAX = 36,
ICON_SIZE_MEDIUM_MIN = 24,
ICON_SIZE_MEDIUM_MAX = 40,
ICON_SIZE_LARGE_MIN = 28,
ICON_SIZE_LARGE_MAX = 44
};
/* Global UI state */
static float dpi_scale = 1.0f;
static int view_width = 320;
static int view_height = 560;
static Color c_text, c_bg, c_circle, c_button, c_button_hover, c_icon;
/* ================================================================
* INITIALIZATION
* ================================================================ */
void
ui_init(int width, int height, float dpi)
{
view_width = width;
view_height = height;
dpi_scale = dpi;
}
void
ui_set_colors(Color text, Color bg, Color circle, Color button, Color button_hover, Color icon)
{
c_text = text;
c_bg = bg;
c_circle = circle;
c_button = button;
c_button_hover = button_hover;
c_icon = icon;
}
/* ================================================================
* DPI SCALING
* ================================================================ */
int
ui_px(int px)
{
return (int)(px * dpi_scale + 0.5f);
}
int
ui_clamp_px(int px, int min_px, int max_px)
{
int value = (int)(px * dpi_scale + 0.5f);
int min_value = (int)(min_px * dpi_scale + 0.5f);
int max_value = (int)(max_px * dpi_scale + 0.5f);
if(value < min_value)
value = min_value;
if(value > max_value)
value = max_value;
return value;
}
/* ================================================================
* COLOR HELPERS
* ================================================================ */
Color
ui_lighten(Color c, int amount)
{
return (Color){
(unsigned char)(c.r + amount > 255 ? 255 : c.r + amount),
(unsigned char)(c.g + amount > 255 ? 255 : c.g + amount),
(unsigned char)(c.b + amount > 255 ? 255 : c.b + amount),
c.a
};
}
Color
ui_darken(Color c, int amount)
{
return (Color){
(unsigned char)(c.r < amount ? 0 : c.r - amount),
(unsigned char)(c.g < amount ? 0 : c.g - amount),
(unsigned char)(c.b < amount ? 0 : c.b - amount),
c.a
};
}
/* ================================================================
* LAYOUT HELPERS
* ================================================================ */
void
ui_centered_column(int max_w, int side_pad, int *x, int *w)
{
max_w = (int)(max_w * dpi_scale + 0.5f);
side_pad = (int)(side_pad * dpi_scale + 0.5f);
int available_w = view_width - side_pad * 2;
if(available_w < 0)
available_w = 0;
if(max_w > available_w)
max_w = available_w;
if(max_w < 0)
max_w = 0;
if(x != NULL)
*x = (view_width - max_w) / 2;
if(w != NULL)
*w = max_w;
}
void
ui_draw_bevel(int x, int y, int w, int h, Color light, Color dark)
{
int border = (int)(dpi_scale + 0.5f);
if(border < 1) border = 1;
DrawRectangle(x, y, w, border, light);
DrawRectangle(x, y, border, h, light);
DrawRectangle(x + w - border, y, border, h, dark);
DrawRectangle(x, y + h - border, w, border, dark);
}
void
ui_draw_text_lines(const char **lines, int count, int x, int *y, int font, int line_h)
{
for(int i = 0; i < count; i++) {
DrawText(lines[i], x, *y, font, c_text);
*y += line_h;
}
}
/* ================================================================
* ICON BUTTONS
* ================================================================ */
int
ui_icon_btn_size(UIIconSize size)
{
switch(size) {
case UI_ICON_SIZE_TINY: return ui_clamp_px(18, 16, 40);
case UI_ICON_SIZE_SMALL: return ui_clamp_px(ICON_SIZE_SMALL, ICON_SIZE_SMALL_MIN, ICON_SIZE_SMALL_MAX);
case UI_ICON_SIZE_MEDIUM: return ui_clamp_px(ICON_SIZE_MEDIUM, ICON_SIZE_MEDIUM_MIN, ICON_SIZE_MEDIUM_MAX);
case UI_ICON_SIZE_LARGE: return ui_clamp_px(ICON_SIZE_LARGE, ICON_SIZE_LARGE_MIN, ICON_SIZE_LARGE_MAX);
default: return ui_clamp_px(ICON_SIZE_SMALL, ICON_SIZE_SMALL_MIN, ICON_SIZE_SMALL_MAX);
}
}
int
ui_icon_btn_padding(UIIconSize size)
{
switch(size) {
case UI_ICON_SIZE_TINY: return ui_px(8);
case UI_ICON_SIZE_SMALL: return ui_px(10);
case UI_ICON_SIZE_MEDIUM: return ui_px(12);
case UI_ICON_SIZE_LARGE: return ui_px(14);
default: return ui_px(10);
}
}
int
ui_draw_icon_btn(InbeApp *app, int x, int y, UIIconSize size, Texture2D icon, int *hover)
{
int btn_size = ui_icon_btn_size(size);
int padding = ui_icon_btn_padding(size);
int w = btn_size + padding * 2;
int h = btn_size + padding * 2;
Vector2 mouse_world = GetScreenToWorld2D(GetMousePosition(), app->camera);
int mx = (int)mouse_world.x;
int my = (int)mouse_world.y;
int mb = IsMouseButtonDown(MOUSE_BUTTON_LEFT);
int released = IsMouseButtonReleased(MOUSE_BUTTON_LEFT);
int pressed = 0;
if(mx > x && mx < x + w && my > y && my < y + h) {
DrawRectangle(x, y, w, h, c_button_hover);
ui_draw_bevel(x, y, w, h, ui_darken(c_button_hover, 40), ui_lighten(c_button_hover, 40));
*hover = 1;
app->cursor_clickable = 1;
if(mb) {
ui_draw_bevel(x, y, w, h, ui_lighten(c_button_hover, 40), ui_darken(c_button_hover, 40));
}
if(released) {
pressed = 1;
}
} else {
DrawRectangle(x, y, w, h, c_button);
ui_draw_bevel(x, y, w, h, ui_lighten(c_button, 40), ui_darken(c_button, 40));
*hover = 0;
}
if(icon.id != 0) {
Rectangle src = {0, 0, icon.width, icon.height};
Rectangle dst = {x + padding, y + padding, (float)btn_size, (float)btn_size};
DrawTexturePro(icon, src, dst, (Vector2){0}, 0, c_icon);
}
return pressed;
}
int
ui_draw_icon_btn_small(InbeApp *app, int x, int y, Texture2D icon, int *hover)
{
return ui_draw_icon_btn(app, x, y, UI_ICON_SIZE_SMALL, icon, hover);
}
int
ui_draw_icon_btn_medium(InbeApp *app, int x, int y, Texture2D icon, int *hover)
{
return ui_draw_icon_btn(app, x, y, UI_ICON_SIZE_MEDIUM, icon, hover);
}
int
ui_draw_icon_btn_large(InbeApp *app, int x, int y, Texture2D icon, int *hover)
{
return ui_draw_icon_btn(app, x, y, UI_ICON_SIZE_LARGE, icon, hover);
}
void
ui_draw_icon_link(InbeApp *app, int x, int y, int icon_size, Texture2D icon, const char *url)
{
Vector2 mouse_world = GetScreenToWorld2D(GetMousePosition(), app->camera);
int mx = (int)mouse_world.x;
int my = (int)mouse_world.y;
int hover = 0;
int padding = ui_px(4);
int btn_w = icon_size + padding * 2;
int btn_h = icon_size + padding * 2;
int btn_x = x - padding;
int btn_y = y - padding;
if(mx > btn_x && mx < btn_x + btn_w && my > btn_y && my < btn_y + btn_h) {
hover = 1;
app->cursor_clickable = 1;
}
if(hover) {
DrawRectangle(btn_x, btn_y, btn_w, btn_h, c_button_hover);
ui_draw_bevel(btn_x, btn_y, btn_w, btn_h, ui_darken(c_button_hover, 40), ui_lighten(c_button_hover, 40));
} else {
DrawRectangle(btn_x, btn_y, btn_w, btn_h, c_button);
ui_draw_bevel(btn_x, btn_y, btn_w, btn_h, ui_lighten(c_button, 40), ui_darken(c_button, 40));
}
if(icon.id != 0) {
Rectangle src = {0, 0, icon.width, icon.height};
Rectangle dst = {x, y, (float)icon_size, (float)icon_size};
DrawTexturePro(icon, src, dst, (Vector2){0}, 0, c_icon);
}
if(hover && IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) {
OpenURL(url);
}
}
/* ================================================================
* CONTROLS
* ================================================================ */
static int
clampi(int value, int min, int max)
{
if(value < min)
return min;
if(value > max)
return max;
return value;
}
int
ui_draw_slider(InbeApp *app, int id, int x, int y, int w, const char *label,
int min, int max, int *value, const char *suffix)
{
Vector2 mouse_world = GetScreenToWorld2D(GetMousePosition(), app->camera);
int mx = (int)mouse_world.x;
int label_font = ui_clamp_px(14, 12, 16);
int value_font = ui_clamp_px(14, 12, 16);
int track_y = y + ui_px(28);
int track_h = ui_px(8);
int knob_w = ui_px(12);
int knob_h = ui_px(22);
int knob_y = track_y - (knob_h - track_h) / 2;
int hit_padding = ui_px(16);
int changed = 0;
char value_text[32];
Rectangle hit = {(float)(x - hit_padding), (float)(knob_y - hit_padding), (float)(w + hit_padding * 2), (float)(knob_h + hit_padding * 2)};
snprintf(value_text, sizeof(value_text), "%d%s", *value, suffix != NULL ? suffix : "");
DrawText(label, x, y, label_font, c_text);
DrawText(value_text, x + w - MeasureText(value_text, value_font), y, value_font, c_text);
DrawRectangle(x, track_y, w, track_h, ui_darken(c_bg, 28));
ui_draw_bevel(x, track_y, w, track_h, ui_darken(c_bg, 55), ui_lighten(c_bg, 35));
if(CheckCollisionPointRec(mouse_world, hit)) {
app->cursor_clickable = 1;
if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
app->settings_drag_slider = id;
}
if(app->settings_drag_slider == id && IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
int old_value = *value;
float t = (float)(mx - x) / (float)w;
if(t < 0.0f)
t = 0.0f;
if(t > 1.0f)
t = 1.0f;
*value = min + (int)(t * (float)(max - min) + 0.5f);
*value = clampi(*value, min, max);
changed = (*value != old_value);
}
float t = (float)(*value - min) / (float)(max - min);
int knob_x = x + (int)(t * (float)w) - knob_w / 2;
DrawRectangle(knob_x, knob_y, knob_w, knob_h, c_button);
ui_draw_bevel(knob_x, knob_y, knob_w, knob_h, ui_lighten(c_button, 40), ui_darken(c_button, 40));
return changed;
}
int
ui_draw_toggle_switch(InbeApp *app, int x, int y, int w, int h, int *value)
{
int hover = 0;
Rectangle bounds = {x, y, w, h};
if(CheckCollisionPointRec(GetMousePosition(), bounds)) {
hover = 1;
app->cursor_clickable = 1;
}
int pressed = hover && IsMouseButtonPressed(MOUSE_BUTTON_LEFT);
if(pressed)
*value = !(*value);
Color bg = ui_darken(c_bg, 8);
DrawRectangle(x, y, w, h, bg);
int track_h = h - 6;
int track_y = y + 3;
DrawRectangleRounded((Rectangle){x + 3, track_y, w - 6, track_h}, 0.5f, 8, ui_darken(c_bg, 20));
int active_w = (w - 6) / 2;
int active_x = *value ? x + w - active_w - 3 : x + 3;
DrawRectangleRounded((Rectangle){active_x, track_y, active_w, track_h}, 0.5f, 8, c_circle);
int circle_size = h - 10;
int circle_x = *value ? x + w - circle_size / 2 - 5 : x + circle_size / 2 + 5;
int circle_y = y + h / 2;
DrawCircle(circle_x, circle_y, circle_size / 2, c_button);
int font = ui_clamp_px(12, 10, 14);
const char *light_label = "Light";
const char *dark_label = "Dark";
int light_w = MeasureText(light_label, font);
int dark_w = MeasureText(dark_label, font);
Color label_color = c_text;
DrawText(light_label, x + 10 + active_w / 2 - light_w / 2, y + h / 2 - font / 2 - 1, font, label_color);
DrawText(dark_label, x + w - 10 - active_w / 2 - dark_w / 2, y + h / 2 - font / 2 - 1, font, label_color);
return pressed;
}
int
ui_draw_checkbox_toggle(InbeApp *app, int x, int y, const char *label, int *value)
{
int font = ui_clamp_px(14, 12, 16);
int box_size = ui_px(22);
int hover = 0;
Rectangle bounds = {x, y, box_size, box_size};
if(CheckCollisionPointRec(GetMousePosition(), bounds)) {
hover = 1;
app->cursor_clickable = 1;
}
int pressed = hover && IsMouseButtonPressed(MOUSE_BUTTON_LEFT);
if(pressed)
*value = !(*value);
DrawRectangle(x, y, box_size, box_size, c_button);
ui_draw_bevel(x, y, box_size, box_size, ui_darken(c_bg, 30), ui_lighten(c_bg, 20));
if(*value) {
int padding = ui_px(4);
DrawLine(x + padding, y + padding, x + box_size / 2, y + box_size - padding, c_text);
DrawLine(x + box_size / 2, y + box_size - padding, x + box_size - padding, y + padding, c_text);
}
DrawText(label, x + box_size + ui_px(10), y + (box_size - font) / 2, font, c_text);
return pressed;
}
void
ui_draw_scrollbar(InbeApp *app, int *scroll, int content_h, int viewport_h,
int *drag_scrollbar, int *drag_content, int *drag_content_y)
{
if(content_h <= viewport_h)
return;
Vector2 mouse_world = GetScreenToWorld2D(GetMousePosition(), app->camera);
int bar_w = ui_px(8);
int bar_x = view_width - bar_w;
int bar_y = 0;
int bar_h = viewport_h;
int thumb_h = (viewport_h * bar_h) / content_h;
int min_thumb_h = ui_px(32);
if(thumb_h < min_thumb_h)
thumb_h = min_thumb_h;
int max_scroll = content_h - viewport_h;
int thumb_y = bar_y + (*scroll * (bar_h - thumb_h)) / max_scroll;
int hit_w = ui_px(16);
Rectangle thumb = {(float)(bar_x - (hit_w - bar_w) / 2), (float)thumb_y, (float)hit_w, (float)thumb_h};
Rectangle content_area = {(float)0, (float)bar_y, (float)bar_x, (float)bar_h};
DrawRectangle(bar_x, bar_y, bar_w, bar_h, ui_darken(c_bg, 18));
DrawRectangle(bar_x, thumb_y, bar_w, thumb_h, c_button_hover);
if(CheckCollisionPointRec(mouse_world, thumb)) {
app->cursor_clickable = 1;
if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
*drag_scrollbar = 1;
}
if(*drag_scrollbar && IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
int usable = bar_h - thumb_h;
int y = (int)mouse_world.y - bar_y - thumb_h / 2;
y = clampi(y, 0, usable);
*scroll = (y * max_scroll) / usable;
return;
}
if(CheckCollisionPointRec(mouse_world, content_area)) {
if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
*drag_content = 1;
*drag_content_y = (int)mouse_world.y;
}
}
if(*drag_content && IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
int delta = *drag_content_y - (int)mouse_world.y;
*scroll += delta;
*scroll = clampi(*scroll, 0, max_scroll);
*drag_content_y = (int)mouse_world.y;
}
if(IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) {
*drag_scrollbar = 0;
*drag_content = 0;
}
}
/* ================================================================
* NAVIGATION
* ================================================================ */
int
ui_nav_button_width(const char *label, int icon_size, int show_label, int font)
{
int padding = ui_px(6);
int width = icon_size + padding * 2;
if(show_label && label != NULL && label[0] != '\0')
width += ui_px(10) + MeasureText(label, font);
return width;
}
int
ui_draw_nav_button(InbeApp *app, int x, int y, int icon_size, Texture2D icon,
const char *label, int show_label, int *hover)
{
Vector2 mouse_world = GetScreenToWorld2D(GetMousePosition(), app->camera);
int mx = (int)mouse_world.x;
int my = (int)mouse_world.y;
int mb = IsMouseButtonDown(MOUSE_BUTTON_LEFT);
int released = IsMouseButtonReleased(MOUSE_BUTTON_LEFT);
int font = ui_clamp_px(14, 12, 16);
int padding = ui_px(6);
int w = ui_nav_button_width(label, icon_size, show_label, font);
int h = icon_size + padding * 2;
int pressed = 0;
if(mx > x && mx < x + w && my > y && my < y + h) {
DrawRectangle(x, y, w, h, c_button_hover);
ui_draw_bevel(x, y, w, h, ui_darken(c_button_hover, 40), ui_lighten(c_button_hover, 40));
*hover = 1;
app->cursor_clickable = 1;
if(mb)
ui_draw_bevel(x, y, w, h, ui_lighten(c_button_hover, 40), ui_darken(c_button_hover, 40));
if(released)
pressed = 1;
} else {
DrawRectangle(x, y, w, h, c_button);
ui_draw_bevel(x, y, w, h, ui_lighten(c_button, 40), ui_darken(c_button, 40));
*hover = 0;
}
if(icon.id != 0) {
Rectangle src = {0, 0, icon.width, icon.height};
Rectangle dst = {x + padding, y + padding, (float)icon_size, (float)icon_size};
DrawTexturePro(icon, src, dst, (Vector2){0}, 0, c_icon);
}
if(show_label && label != NULL && label[0] != '\0') {
int text_x = x + icon_size + padding * 2 + ui_px(10);
int text_y = y + (h - font) / 2;
DrawText(label, text_x, text_y, font, c_text);
}
return pressed;
}
/* ================================================================
* TAB BAR
* ================================================================ */
void
ui_draw_tab_bar(UITab *tabs, int count, InbeApp *app)
{
int bar_h = ui_clamp_px(58, 54, 66);
int bar_y = view_height - bar_h;
int button_size = ui_clamp_px(ICON_SIZE_LARGE, ICON_SIZE_LARGE_MIN, ICON_SIZE_LARGE_MAX);
int button_h = button_size + ui_px(12);
int font = ui_clamp_px(14, 12, 16);
int side_margin = ui_px(16);
int group_gap = ui_px(10);
int available_w = view_width - side_margin * 2;
/* Calculate widths with labels */
int group_w_label = 0;
for(int i = 0; i < count; i++) {
group_w_label += ui_nav_button_width(tabs[i].label, button_size, 1, font);
if(i < count - 1)
group_w_label += group_gap;
}
/* Calculate widths without labels */
int group_w_no_label = 0;
for(int i = 0; i < count; i++) {
group_w_no_label += ui_nav_button_width(tabs[i].label, button_size, 0, font);
if(i < count - 1)
group_w_no_label += group_gap;
}
/* Only show labels if all buttons with labels fit */
int show_labels = group_w_label <= available_w;
int group_x = side_margin + (available_w - (show_labels ? group_w_label : group_w_no_label)) / 2;
int button_y = bar_y + (bar_h - button_h) / 2;
int tab_hover = 0;
DrawRectangle(0, bar_y, view_width, bar_h, ui_darken(c_bg, 10));
DrawLine(0, bar_y, view_width, bar_y, ui_darken(c_bg, 42));
int x = group_x;
for(int i = 0; i < count; i++) {
int w = ui_nav_button_width(tabs[i].label, button_size, show_labels, font);
if(tabs[i].icon.id != 0) {
if(ui_draw_nav_button(app, x, button_y, button_size, tabs[i].icon,
tabs[i].label, show_labels, &tab_hover)) {
if(tabs[i].on_click)
tabs[i].on_click(tabs[i].user_data);
}
}
x += w + group_gap;
}
}
/* ================================================================
* TUTORIAL HELPERS
* ================================================================ */
void
ui_draw_tutorial_image_placeholder(const char *label, int x, int y, int w, int h)
{
DrawRectangle(x, y, w, h, ui_darken(c_bg, 12));
ui_draw_bevel(x, y, w, h, ui_darken(c_bg, 45), ui_lighten(c_bg, 35));
int font = ui_clamp_px(14, 12, 16);
int tw = MeasureText(label, font);
DrawText(label, x + w / 2 - tw / 2, y + h / 2 - ui_px(7), font, c_text);
}
void
ui_draw_tutorial_image(Texture2D texture, const char *fallback, int x, int y, int w, int h)
{
if(texture.id == 0) {
ui_draw_tutorial_image_placeholder(fallback, x, y, w, h);
return;
}
float scale_x = (float)w / (float)texture.width;
float scale_y = (float)h / (float)texture.height;
float scale = scale_x < scale_y ? scale_x : scale_y;
float dst_w = (float)texture.width * scale;
float dst_h = (float)texture.height * scale;
Rectangle src = {0, 0, (float)texture.width, (float)texture.height};
Rectangle dst = {x + ((float)w - dst_w) * 0.5f, y + ((float)h - dst_h) * 0.5f, dst_w, dst_h};
DrawRectangle(x, y, w, h, ui_darken(c_bg, 12));
ui_draw_bevel(x, y, w, h, ui_darken(c_bg, 45), ui_lighten(c_bg, 35));
DrawTexturePro(texture, src, dst, (Vector2){0}, 0, WHITE);
}
+138
View File
@@ -0,0 +1,138 @@
#ifndef INBE_UI_H
#define INBE_UI_H
#include "raylib.h"
#include "app.h"
/* Icon Size Enum */
typedef enum {
UI_ICON_SIZE_TINY,
UI_ICON_SIZE_SMALL,
UI_ICON_SIZE_MEDIUM,
UI_ICON_SIZE_LARGE
} UIIconSize;
/* ================================================================
* INITIALIZATION
* ================================================================ */
/* Initialize UI library with viewport dimensions and DPI scale */
void ui_init(int width, int height, float dpi);
/* Update theme colors used by UI library */
void ui_set_colors(Color text, Color bg, Color circle, Color button, Color button_hover, Color icon);
/* ================================================================
* DPI SCALING
* ================================================================ */
/* Convert logical pixels to physical pixels based on DPI scaling */
int ui_px(int px);
/* Convert logical pixels to physical pixels with min/max clamping */
int ui_clamp_px(int px, int min_px, int max_px);
/* ================================================================
* COLOR HELPERS
* ================================================================ */
/* Lighten a color by a specified amount */
Color ui_lighten(Color c, int amount);
/* Darken a color by a specified amount */
Color ui_darken(Color c, int amount);
/* ================================================================
* LAYOUT HELPERS
* ================================================================ */
/* Calculate centered column position and width */
void ui_centered_column(int max_w, int side_pad, int *x, int *w);
/* Draw a bevel border effect using rectangles */
void ui_draw_bevel(int x, int y, int w, int h, Color light, Color dark);
/* Draw multiple text lines with incremental y position */
void ui_draw_text_lines(const char **lines, int count, int x, int *y, int font, int line_h);
/* ================================================================
* ICON BUTTONS
* ================================================================ */
/* Get icon button size with DPI scaling */
int ui_icon_btn_size(UIIconSize size);
/* Get icon button padding */
int ui_icon_btn_padding(UIIconSize size);
/* Draw a standard icon button with consistent sizing */
int ui_draw_icon_btn(InbeApp *app, int x, int y, UIIconSize size, Texture2D icon, int *hover);
/* Convenience wrapper for small icon buttons */
int ui_draw_icon_btn_small(InbeApp *app, int x, int y, Texture2D icon, int *hover);
/* Convenience wrapper for medium icon buttons */
int ui_draw_icon_btn_medium(InbeApp *app, int x, int y, Texture2D icon, int *hover);
/* Convenience wrapper for large icon buttons */
int ui_draw_icon_btn_large(InbeApp *app, int x, int y, Texture2D icon, int *hover);
/* Draw an icon link button that opens a URL when clicked */
void ui_draw_icon_link(InbeApp *app, int x, int y, int icon_size, Texture2D icon, const char *url);
/* ================================================================
* CONTROLS
* ================================================================ */
/* Draw a slider control with label and value display */
int ui_draw_slider(InbeApp *app, int id, int x, int y, int w, const char *label,
int min, int max, int *value, const char *suffix);
/* Draw a toggle switch (typically for light/dark mode) */
int ui_draw_toggle_switch(InbeApp *app, int x, int y, int w, int h, int *value);
/* Draw a checkbox toggle with label */
int ui_draw_checkbox_toggle(InbeApp *app, int x, int y, const char *label, int *value);
/* Draw a scrollbar with thumb and handle content dragging */
void ui_draw_scrollbar(InbeApp *app, int *scroll, int content_h, int viewport_h,
int *drag_scrollbar, int *drag_content, int *drag_content_y);
/* ================================================================
* NAVIGATION
* ================================================================ */
/* Tab definition for tab bar */
typedef struct UITab {
const char *label;
Texture2D icon;
void (*on_click)(void *user_data);
void *user_data;
} UITab;
typedef struct UITabBar {
UITab *tabs;
int count;
} UITabBar;
/* Calculate width of navigation buttons with optional label */
int ui_nav_button_width(const char *label, int icon_size, int show_label, int font);
/* Draw a navigation button with icon and optional label */
int ui_draw_nav_button(InbeApp *app, int x, int y, int icon_size, Texture2D icon,
const char *label, int show_label, int *hover);
/* Draw the bottom tab bar - automatic, data-driven */
void ui_draw_tab_bar(UITab *tabs, int count, InbeApp *app);
/* ================================================================
* TUTORIAL HELPERS
* ================================================================ */
/* Draw a placeholder for tutorial images */
void ui_draw_tutorial_image_placeholder(const char *label, int x, int y, int w, int h);
/* Draw tutorial images with fallback to placeholder */
void ui_draw_tutorial_image(Texture2D texture, const char *fallback, int x, int y, int w, int h);
#endif
+2 -2
View File
@@ -3,7 +3,7 @@
#define INBE_VERSION_MAJOR 1
#define INBE_VERSION_MINOR 0
#define INBE_VERSION_PATCH 1
#define INBE_VERSION_STRING "1.0.1"
#define INBE_VERSION_PATCH 4
#define INBE_VERSION_STRING "1.0.4"
#endif
+7
View File
@@ -0,0 +1,7 @@
# Lotus theme: forest (light)
background "#E8F5E9FF"
text "#2E5C38FF"
circle "#66BB6AFF"
button "#81C784FF"
button_hover "#4CAF50FF"
icon "#E8F5E9FF"
+7
View File
@@ -0,0 +1,7 @@
# Lotus theme: forest (dark)
background "#1A2F1AFF"
text "#A5D6A7FF"
circle "#43A047FF"
button "#2A3F2AFF"
button_hover "#3A4F3AFF"
icon "#A5D6A7FF"
+7
View File
@@ -0,0 +1,7 @@
# Lotus theme: lavender (light)
background "#F3E5F5FF"
text "#4A235AFF"
circle "#BA68C8FF"
button "#CE93D8FF"
button_hover "#AB47BCFF"
icon "#F3E5F5FF"
+7
View File
@@ -0,0 +1,7 @@
# Lotus theme: lavender (dark)
background "#1A0A2EFF"
text "#E1BEE7FF"
circle "#7B1FA2FF"
button "#3A2A4EFF"
button_hover "#4A3A5EFF"
icon "#E1BEE7FF"
+7
View File
@@ -0,0 +1,7 @@
# Lotus theme: ocean (light)
background "#E0F4F8FF"
text "#1A5276FF"
circle "#48C9B0FF"
button "#76D7C5FF"
button_hover "#38B9A0FF"
icon "#E0F4F8FF"
+7
View File
@@ -0,0 +1,7 @@
# Lotus theme: ocean (dark)
background "#0D1B2AFF"
text "#98D8C8FF"
circle "#2E8B7AFF"
button "#1D3B4AFF"
button_hover "#2D4B5AFF"
icon "#98D8C8FF"
+7
View File
@@ -0,0 +1,7 @@
# Lotus theme: sky (light)
background "#E2EEFCFF"
text "#24487CFF"
circle "#7EB7E6FF"
button "#A6CFF2FF"
button_hover "#689ED7FF"
icon "#E2EEFCFF"
+7
View File
@@ -0,0 +1,7 @@
# Lotus theme: sky (dark)
background "#1A2634FF"
text "#B8D4E6FF"
circle "#4A7BA8FF"
button "#2A4654FF"
button_hover "#3A5664FF"
icon "#B8D4E6FF"
+7
View File
@@ -0,0 +1,7 @@
# Lotus theme: sunset (light)
background "#FFF4E6FF"
text "#8B4513FF"
circle "#FF8C42FF"
button "#FFB37DFF"
button_hover "#FF7022FF"
icon "#FFF4E6FF"
+7
View File
@@ -0,0 +1,7 @@
# Lotus theme: sunset (dark)
background "#2A1A1AFF"
text "#FFD699FF"
circle "#E85D4CFF"
button "#3A2A2AFF"
button_hover "#4A3A3AFF"
icon "#FFD699FF"
+5 -3
View File
@@ -1,4 +1,6 @@
- fix saving sessions in wasm version
- implement export and import data
TODO
- camera hole fix
- rounded corners fix
- don't move setting spage if selecting the sliders
- make a multi page settings panel