in the case of unspecified colors in cfg, default fill them from the preset theme with the most similar background; this will mean that even with totally custom themes, as new color codes are added to the frontend, people will get sensible defaults. if they are just using a preset, then they will get the default new values by default

This commit is contained in:
Ryan Fleury
2024-01-29 16:24:41 -08:00
parent 0ce5239404
commit d2bdf512cf
2 changed files with 88 additions and 55 deletions
+33
View File
@@ -11476,6 +11476,7 @@ df_gfx_begin_frame(Arena *arena, DF_CmdList *cmds)
}
//- rjf: apply theme colors
B8 theme_color_hit[DF_ThemeColor_COUNT] = {0};
MemoryCopy(df_gfx_state->cfg_theme_target.colors, df_g_theme_preset_colors__default_dark, sizeof(df_g_theme_preset_colors__default_dark));
MemoryCopy(df_gfx_state->cfg_theme.colors, df_g_theme_preset_colors__default_dark, sizeof(df_g_theme_preset_colors__default_dark));
DF_CfgVal *colors = df_cfg_val_from_string(table, str8_lit("colors"));
@@ -11499,6 +11500,7 @@ df_gfx_begin_frame(Arena *arena, DF_CmdList *cmds)
}
if(color_code != DF_ThemeColor_Null)
{
theme_color_hit[color_code] = 1;
DF_CfgNode *hex_cfg = color->first;
String8 hex_string = hex_cfg->string;
U64 hex_val = 0;
@@ -11515,6 +11517,7 @@ df_gfx_begin_frame(Arena *arena, DF_CmdList *cmds)
//- rjf: apply theme presets
DF_CfgVal *color_preset = df_cfg_val_from_string(table, str8_lit("color_preset"));
B32 preset_applied = 0;
if(color_preset != &df_g_nil_cfg_val)
{
String8 color_preset_name = color_preset->last->first->string;
@@ -11531,11 +11534,41 @@ df_gfx_begin_frame(Arena *arena, DF_CmdList *cmds)
}
if(found_preset)
{
preset_applied = 1;
MemoryCopy(df_gfx_state->cfg_theme_target.colors, df_g_theme_preset_colors_table[preset], sizeof(df_g_theme_preset_colors__default_dark));
MemoryCopy(df_gfx_state->cfg_theme.colors, df_g_theme_preset_colors_table[preset], sizeof(df_g_theme_preset_colors__default_dark));
}
}
//- rjf: no preset -> autofill all missing colors from the preset with the most similar background
if(!preset_applied)
{
DF_ThemePreset closest_preset = DF_ThemePreset_DefaultDark;
F32 closest_preset_bg_distance = 100000000;
for(DF_ThemePreset p = (DF_ThemePreset)0; p < DF_ThemePreset_COUNT; p = (DF_ThemePreset)(p+1))
{
Vec4F32 cfg_bg = df_gfx_state->cfg_theme_target.colors[DF_ThemeColor_PlainBackground];
Vec4F32 pre_bg = df_g_theme_preset_colors_table[p][DF_ThemeColor_PlainBackground];
Vec4F32 diff = sub_4f32(cfg_bg, pre_bg);
Vec3F32 diff3 = diff.xyz;
F32 distance = length_3f32(diff3);
if(distance < closest_preset_bg_distance)
{
closest_preset = p;
closest_preset_bg_distance = distance;
}
}
for(DF_ThemeColor c = (DF_ThemeColor)(DF_ThemeColor_Null+1);
c < DF_ThemeColor_COUNT;
c = (DF_ThemeColor)(c+1))
{
if(!theme_color_hit[c])
{
df_gfx_state->cfg_theme_target.colors[c] = df_gfx_state->cfg_theme.colors[c] = df_g_theme_preset_colors_table[closest_preset][c];
}
}
}
//- rjf: if theme colors are all zeroes, then set to default - config appears busted
{
B32 all_colors_are_zero = 1;
+55 -55
View File
@@ -308,62 +308,62 @@ DF_GfxViewRuleTable:
////////////////////////////////
//~ rjf: Theme Color Codes
@table(name display_name name_lower allow_zero_on_load)
@table(name display_name name_lower)
DF_ThemeTable:
{
{Null "Null" null 0}
{PlainText "Plain Text" plain_text 0}
{PlainBackground "Plain Background" plain_background 0}
{PlainBorder "Plain Border" plain_border 0}
{PlainOverlay "Plain Overlay" plain_overlay 0}
{CodeDefault "Code (Default)" code_default 0}
{CodeFunction "Code (Function)" code_function 0}
{CodeType "Code (Type)" code_type 0}
{CodeLocal "Code (Local)" code_local 0}
{CodeKeyword "Code (Keyword)" code_keyword 0}
{CodeSymbol "Code (Symbol)" code_symbol 0}
{CodeNumeric "Code (Numeric)" code_numeric 0}
{CodeString "Code (String)" code_string 0}
{CodeMeta "Code (Meta)" code_meta 0}
{CodeComment "Code (Comment)" code_comment 0}
{LineInfo0 "Line Info (0)" line_info_0 0}
{LineInfo1 "Line Info (1)" line_info_1 0}
{LineInfo2 "Line Info (2)" line_info_2 0}
{LineInfo3 "Line Info (3)" line_info_3 0}
{AltText "Alt Text" alt_text 0}
{AltBackground "Alt Background" alt_background 0}
{AltBorder "Alt Border" alt_border 0}
{AltOverlay "Alt Overlay" alt_overlay 0}
{TabInactive "Inactive Tab" tab_inactive 0}
{TabActive "Active Tab" tab_active 0}
{EntityBackground "Entity Background" entity_background 0}
{QueryBar "Query Bar" query_bar 0}
{WeakText "Weak Text" weak_text 0}
{TextSelection "Text Selection" text_selection 0}
{Cursor "Cursor" cursor 0}
{Highlight0 "Highlight (0)" highlight_0 0}
{Highlight1 "Highlight (1)" highlight_1 0}
{SuccessText "Success Text" success_text 0}
{SuccessBackground "Success Background" success_background 0}
{SuccessBorder "Success Border" success_border 0}
{FailureText "Failure Text" failure_text 0}
{FailureBackground "Failure Background" failure_background 0}
{FailureBorder "Failure Border" failure_border 0}
{ActionText "Action Text" action_text 0}
{ActionBackground "Action Background" action_background 0}
{ActionBorder "Action Border" action_border 0}
{DropSiteOverlay "Drop Site Overlay" drop_site_overlay 0}
{Thread0 "Thread (0)" thread_0 0}
{Thread1 "Thread (1)" thread_1 0}
{Thread2 "Thread (2)" thread_2 0}
{Thread3 "Thread (3)" thread_3 0}
{Thread4 "Thread (4)" thread_4 0}
{Thread5 "Thread (5)" thread_5 0}
{Thread6 "Thread (6)" thread_6 0}
{Thread7 "Thread (7)" thread_7 0}
{ThreadUnwound "Thread (Unwound)" thread_unwound 0}
{InactivePanelOverlay "Inactive Panel Overlay" inactive_panel_overlay 1}
{DropShadow "Drop Shadow" drop_shadow 1}
{Null "Null" null }
{PlainText "Plain Text" plain_text }
{PlainBackground "Plain Background" plain_background }
{PlainBorder "Plain Border" plain_border }
{PlainOverlay "Plain Overlay" plain_overlay }
{CodeDefault "Code (Default)" code_default }
{CodeFunction "Code (Function)" code_function }
{CodeType "Code (Type)" code_type }
{CodeLocal "Code (Local)" code_local }
{CodeKeyword "Code (Keyword)" code_keyword }
{CodeSymbol "Code (Symbol)" code_symbol }
{CodeNumeric "Code (Numeric)" code_numeric }
{CodeString "Code (String)" code_string }
{CodeMeta "Code (Meta)" code_meta }
{CodeComment "Code (Comment)" code_comment }
{LineInfo0 "Line Info (0)" line_info_0 }
{LineInfo1 "Line Info (1)" line_info_1 }
{LineInfo2 "Line Info (2)" line_info_2 }
{LineInfo3 "Line Info (3)" line_info_3 }
{AltText "Alt Text" alt_text }
{AltBackground "Alt Background" alt_background }
{AltBorder "Alt Border" alt_border }
{AltOverlay "Alt Overlay" alt_overlay }
{TabInactive "Inactive Tab" tab_inactive }
{TabActive "Active Tab" tab_active }
{EntityBackground "Entity Background" entity_background }
{QueryBar "Query Bar" query_bar }
{WeakText "Weak Text" weak_text }
{TextSelection "Text Selection" text_selection }
{Cursor "Cursor" cursor }
{Highlight0 "Highlight (0)" highlight_0 }
{Highlight1 "Highlight (1)" highlight_1 }
{SuccessText "Success Text" success_text }
{SuccessBackground "Success Background" success_background }
{SuccessBorder "Success Border" success_border }
{FailureText "Failure Text" failure_text }
{FailureBackground "Failure Background" failure_background }
{FailureBorder "Failure Border" failure_border }
{ActionText "Action Text" action_text }
{ActionBackground "Action Background" action_background }
{ActionBorder "Action Border" action_border }
{DropSiteOverlay "Drop Site Overlay" drop_site_overlay }
{Thread0 "Thread (0)" thread_0 }
{Thread1 "Thread (1)" thread_1 }
{Thread2 "Thread (2)" thread_2 }
{Thread3 "Thread (3)" thread_3 }
{Thread4 "Thread (4)" thread_4 }
{Thread5 "Thread (5)" thread_5 }
{Thread6 "Thread (6)" thread_6 }
{Thread7 "Thread (7)" thread_7 }
{ThreadUnwound "Thread (Unwound)" thread_unwound }
{InactivePanelOverlay "Inactive Panel Overlay" inactive_panel_overlay }
{DropShadow "Drop Shadow" drop_shadow }
}
////////////////////////////////
@@ -645,7 +645,7 @@ df_g_gfx_view_kind_spec_info_table:
@expand(DF_GfxViewTable a) ```{(0|$(a.parameterized_by_entity)*DF_ViewSpecFlag_ParameterizedByEntity|$(a.can_serialize)*DF_ViewSpecFlag_CanSerialize|$(a.can_serialize_entity_path)*DF_ViewSpecFlag_CanSerializeEntityPath), str8_lit_comp("$(a.name_lower)"), str8_lit_comp("$(a.display_string)"), DF_NameKind_$(a.name_kind), DF_IconKind_$(a.icon), DF_VIEW_SETUP_FUNCTION_NAME($(a.name)), DF_VIEW_STRING_FROM_STATE_FUNCTION_NAME($(a.name)), DF_VIEW_CMD_FUNCTION_NAME($(a.name)), DF_VIEW_UI_FUNCTION_NAME($(a.name))},```;
}
//- rjf: theme color string tables
//- rjf: theme color tables
@table_gen_data(type: String8, fallback: `str8_lit_comp("")`)
df_g_theme_color_display_string_table: