#ifndef PLAYER_SETTINGS_H #define PLAYER_SETTINGS_H // NOTE: every tweakable lives in one plain struct. the ui reads it directly through one pointer // (ui_settings), so a "setting" costs exactly what a constant used to cost: one load. // // the Settings view, editing, h / l adjusting, clamping and saving are all driven by a single // table of SettingDesc (player_settings.cpp). adding a setting = a field here + one table line. //- colors typedef enum UIColor { UI_COLOR_BG, UI_COLOR_PANEL, UI_COLOR_PANEL_EDGE, UI_COLOR_FOCUS_EDGE, UI_COLOR_TAB, UI_COLOR_TAB_ACTIVE, UI_COLOR_HEADER, UI_COLOR_HOVER, UI_COLOR_SELECTED, UI_COLOR_ZEBRA, UI_COLOR_TEXT, UI_COLOR_TEXT_DIM, UI_COLOR_TEXT_FAINT, UI_COLOR_ACCENT, UI_COLOR_TRACK, UI_COLOR_DROP, UI_COLOR_ON_ACCENT, UI_COLOR_MARKED, // multi selected rows UI_COLOR_COUNT, } UIColor; typedef enum UIScheme { UI_SCHEME_MONO_DARK, UI_SCHEME_MONO_LIGHT, UI_SCHEME_AMBER, UI_SCHEME_PHOSPHOR, UI_SCHEME_GRUVBOX, UI_SCHEME_NORD, UI_SCHEME_SOLARIZED, UI_SCHEME_HIGH_CONTRAST, UI_SCHEME_CUSTOM, // any color edited by hand UI_SCHEME_COUNT, } UIScheme; //- fonts // NOTE: one list of known font files, each font setting is an index into it. entries that aren't // installed are skipped when cycling and fall back to the first one that is. typedef struct FontChoice FontChoice; struct FontChoice { const char *name; const char *path; }; #define UI_FONT_CHOICES 20 //- the settings typedef struct Settings Settings; struct Settings { //- appearance f32 zoom; u32 scheme; // UIScheme f32 text_gamma; // glyph coverage curve: < 1 bolder, > 1 thinner u32 font_ui; // FontChoice indices u32 font_bold; u32 font_mono; f32 font_size; f32 font_size_small; u32 colors[UI_COLOR_COUNT]; //- layout f32 row_height; f32 tab_height; f32 column_height; f32 status_height; f32 gap; f32 tree_indent; b32 show_columns; b32 show_scrollbars; b32 zebra; b32 bold_playing; // the playing row's name in the bold font //- playback f32 volume; u32 autoplay; // AutoplayMode u32 seek_seconds; u32 seek_big; // { } multiplier //- downloads u32 jobs; b32 confirm_delete; //- behaviour f32 scroll_speed; // 0 = instant u32 scroll_lines; // per wheel notch u32 double_click_ms; f32 message_seconds; //- performance u32 fps_cap; // 0 = whatever the compositor asks for u32 tick_hz; // redraws per second while only the playback clock moves }; typedef enum SettingKind { SETTING_KIND_SECTION, SETTING_KIND_F32, SETTING_KIND_U32, SETTING_KIND_BOOL, SETTING_KIND_ENUM, // u32 holding an index into names SETTING_KIND_CHOICE, // u32 holding one of `values`, shown as `names` SETTING_KIND_COLOR, SETTING_KIND_FONT, SETTING_KIND_ACTION, SETTING_KIND_INFO, } SettingKind; typedef enum SettingAction { SETTING_ACTION_NONE, SETTING_ACTION_RESET_LAYOUT, SETTING_ACTION_RESET_SETTINGS, SETTING_ACTION_RESET_COLORS, SETTING_INFO_FRAME, SETTING_INFO_ON_DISK, SETTING_INFO_DATA_DIR, SETTING_INFO_RELOADS, } SettingAction; typedef struct SettingDesc SettingDesc; struct SettingDesc { u8 kind; // SettingKind const char *name; // also the key it's saved under u32 offset; // into Settings f32 min, max, step; const char **names; // enum / choice labels const u32 *values; // choice values u32 count; u32 action; // SettingAction for actions and info rows const char *note; }; // NOTE: the pointer every theme lookup goes through. set at the top of each ui frame (the hot // reloaded .so has its own copy of this global) and once by the host. global_variable Settings *ui_settings = 0; // NOTE: a by-value copy taken at the top of every ui frame. the theme macros read this one: a // fixed address, one load instead of pointer then field, and stores through other pointers // during the frame can't make the compiler reload through ui_settings global_variable Settings ui_theme = {}; internal void settings_default(Settings *settings); internal void settings_apply_scheme(Settings *settings, u32 scheme); internal void settings_clamp(Settings *settings); internal u32 settings_desc_count(void); internal SettingDesc *settings_desc(u32 index); internal String8 settings_format(Arena *arena, Settings *settings, SettingDesc *desc); internal void settings_adjust(Settings *settings, SettingDesc *desc, s32 direction); internal b32 settings_parse(Settings *settings, SettingDesc *desc, const char *text); internal b32 settings_set(Settings *settings, const char *assignment); // "name=value" internal String8 settings_serialize(Arena *arena, Settings *settings); internal void settings_deserialize(Settings *settings, String8 data); internal const FontChoice *font_choice(u32 index); #endif // PLAYER_SETTINGS_H