theme API part 1, bug fixes
This commit is contained in:
parent
9bf2a73640
commit
6e1abb4237
|
@ -811,7 +811,7 @@ CUSTOM_COMMAND_SIG(build_search){
|
|||
if (app->file_exists(app, dir.str, dir.size)){
|
||||
dir.size = old_size;
|
||||
|
||||
push_parameter(app, par_flags, 0);
|
||||
push_parameter(app, par_flags, CLI_OverlapWithConflict);
|
||||
push_parameter(app, par_name, literal("*compilation*"));
|
||||
push_parameter(app, par_cli_path, dir.str, dir.size);
|
||||
|
||||
|
@ -840,6 +840,34 @@ CUSTOM_COMMAND_SIG(write_and_auto_tab){
|
|||
exec_command(app, cmdid_auto_tab_line_at_cursor);
|
||||
}
|
||||
|
||||
CUSTOM_COMMAND_SIG(improve_theme){
|
||||
Theme_Color colors[] = {
|
||||
{Stag_Bar, 0xFF0088},
|
||||
{Stag_Margin, 0x880088},
|
||||
{Stag_Margin_Hover, 0xAA0088},
|
||||
{Stag_Margin_Active, 0xDD0088},
|
||||
{Stag_Cursor, 0xFF0000},
|
||||
};
|
||||
|
||||
int count = ArrayCount(colors);
|
||||
|
||||
app->set_theme_colors(app, colors, count);
|
||||
}
|
||||
|
||||
CUSTOM_COMMAND_SIG(ruin_theme){
|
||||
Theme_Color colors[] = {
|
||||
{Stag_Bar, 0x888888},
|
||||
{Stag_Margin, 0x181818},
|
||||
{Stag_Margin_Hover, 0x252525},
|
||||
{Stag_Margin_Active, 0x323232},
|
||||
{Stag_Cursor, 0x00EE00},
|
||||
};
|
||||
|
||||
int count = ArrayCount(colors);
|
||||
|
||||
app->set_theme_colors(app, colors, count);
|
||||
}
|
||||
|
||||
// NOTE(allen|a4.0.0): scroll rule information
|
||||
//
|
||||
// The parameters:
|
||||
|
@ -961,6 +989,8 @@ extern "C" GET_BINDING_DATA(get_bindings){
|
|||
bind(context, 'M', MDFR_ALT | MDFR_CTRL, open_my_files);
|
||||
bind(context, 'M', MDFR_ALT, build_at_launch_location);
|
||||
|
||||
bind(context, '`', MDFR_ALT, improve_theme);
|
||||
bind(context, '~', MDFR_ALT, ruin_theme);
|
||||
|
||||
end_map(context);
|
||||
|
||||
|
|
|
@ -319,6 +319,13 @@ struct Query_Bar{
|
|||
String string;
|
||||
};
|
||||
|
||||
struct Theme_Color{
|
||||
Style_Tag tag;
|
||||
unsigned int color;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#define GET_BINDING_DATA(name) int name(void *data, int size)
|
||||
#define CUSTOM_COMMAND_SIG(name) void name(struct Application_Links *app)
|
||||
#define HOOK_SIG(name) void name(struct Application_Links *app)
|
||||
|
@ -383,6 +390,8 @@ struct Application_Links;
|
|||
#define START_QUERY_BAR_SIG(name) int name(Application_Links *context, Query_Bar *bar, unsigned int flags)
|
||||
#define END_QUERY_BAR_SIG(name) void name(Application_Links *context, Query_Bar *bar, unsigned int flags)
|
||||
|
||||
// Setting colors
|
||||
#define SET_THEME_COLORS_SIG(name) void name(Application_Links *context, Theme_Color *colors, int count)
|
||||
|
||||
|
||||
// Boundry type flags
|
||||
|
@ -457,6 +466,9 @@ extern "C"{
|
|||
// Queries
|
||||
typedef START_QUERY_BAR_SIG(Start_Query_Bar_Function);
|
||||
typedef END_QUERY_BAR_SIG(End_Query_Bar_Function);
|
||||
|
||||
// Set theme colors
|
||||
typedef SET_THEME_COLORS_SIG(Set_Theme_Colors_Function);
|
||||
}
|
||||
|
||||
struct Application_Links{
|
||||
|
@ -514,6 +526,9 @@ struct Application_Links{
|
|||
Start_Query_Bar_Function *start_query_bar;
|
||||
End_Query_Bar_Function *end_query_bar;
|
||||
|
||||
// Theme
|
||||
Set_Theme_Colors_Function *set_theme_colors;
|
||||
|
||||
// Internal
|
||||
void *cmd_context;
|
||||
};
|
||||
|
|
|
@ -214,17 +214,6 @@ push_parameter(Application_Links *app, const char *param, int param_len, const c
|
|||
app->push_parameter(app, dynamic_string(param_copy, param_len), dynamic_string(value_copy, value_len));
|
||||
}
|
||||
|
||||
#if UseInterfacesThatArePhasingOut
|
||||
inline String
|
||||
push_directory(Application_Links *app){
|
||||
String result;
|
||||
result.memory_size = 512;
|
||||
result.str = app->push_memory(app, result.memory_size);
|
||||
result.size = app->directory_get_hot(app, result.str, result.memory_size);
|
||||
return(result);
|
||||
}
|
||||
#endif
|
||||
|
||||
inline Range
|
||||
get_range(View_Summary *view){
|
||||
Range range;
|
||||
|
|
|
@ -260,7 +260,7 @@ table_remove(File_Table *table, String name){
|
|||
|
||||
struct Working_Set{
|
||||
Editing_File *files;
|
||||
i32 file_count, file_max;
|
||||
i32 file_count, file_max;
|
||||
File_Node free_sentinel;
|
||||
File_Node used_sentinel;
|
||||
|
||||
|
@ -443,7 +443,7 @@ working_set_contains(Working_Set *working, String filename){
|
|||
Editing_File *result = 0;
|
||||
i32 id;
|
||||
if (table_find(&working->table, filename, &id)){
|
||||
if (id >= 0 && id < working->file_max){
|
||||
if (id >= 0 && id <= working->file_max){
|
||||
result = working->files + id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1296,6 +1296,10 @@ view_set_file(
|
|||
file->settings.is_initialized = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(allen): Fix this:
|
||||
view->ui_state = {};
|
||||
view->showing_ui = VUI_None;
|
||||
}
|
||||
|
||||
struct Relative_Scrolling{
|
||||
|
@ -2595,7 +2599,7 @@ view_show_theme(View *fview, Command_Map *gui_map){
|
|||
}
|
||||
|
||||
inline void
|
||||
view_show_file(View *view, Command_Map *file_map, Editing_File *file){
|
||||
view_show_file(View *view, Command_Map *file_map){
|
||||
view->ui_state = {};
|
||||
if (file_map){
|
||||
view->map = file_map;
|
||||
|
@ -2603,7 +2607,6 @@ view_show_file(View *view, Command_Map *file_map, Editing_File *file){
|
|||
else{
|
||||
view->map = view->map_for_file;
|
||||
}
|
||||
view->file = file;
|
||||
view->showing_ui = VUI_None;
|
||||
}
|
||||
|
||||
|
@ -2652,7 +2655,8 @@ interactive_view_complete(View *view){
|
|||
}
|
||||
break;
|
||||
}
|
||||
view_show_file(view, 0, 0);
|
||||
view_show_file(view, 0);
|
||||
view->file = 0;
|
||||
}
|
||||
|
||||
internal void
|
||||
|
|
110
4ed_metagen.cpp
110
4ed_metagen.cpp
|
@ -19,10 +19,38 @@ struct Struct_Field{
|
|||
|
||||
void to_lower(char *src, char *dst){
|
||||
char *c, ch;
|
||||
for (c = src; *c != 0; ++c){
|
||||
ch = char_to_lower(*c);
|
||||
*dst++ = ch;
|
||||
}
|
||||
*dst = 0;
|
||||
}
|
||||
|
||||
void to_upper(char *src, char *dst){
|
||||
char *c, ch;
|
||||
for (c = src; *c != 0; ++c){
|
||||
ch = char_to_upper(*c);
|
||||
*dst++ = ch;
|
||||
}
|
||||
*dst = 0;
|
||||
}
|
||||
|
||||
void to_camel(char *src, char *dst){
|
||||
char *c, ch;
|
||||
int is_first = 1;
|
||||
for (c = src; *c != 0; ++c){
|
||||
ch = *c;
|
||||
if (ch >= 'A' && ch <= 'Z'){
|
||||
ch += ('a' - 'A');
|
||||
if (char_is_alpha_numeric_true(ch)){
|
||||
if (is_first){
|
||||
is_first = 0;
|
||||
ch = char_to_upper(ch);
|
||||
}
|
||||
else{
|
||||
ch = char_to_lower(ch);
|
||||
}
|
||||
}
|
||||
else{
|
||||
is_first = 1;
|
||||
}
|
||||
*dst++ = ch;
|
||||
}
|
||||
|
@ -361,42 +389,39 @@ char* main_style_fields[] = {
|
|||
"next_undo",
|
||||
};
|
||||
|
||||
static void
|
||||
do_style_tag(FILE *file, char *tag){
|
||||
int j, is_first;
|
||||
char *str_, c;
|
||||
String str;
|
||||
static char*
|
||||
make_style_tag(char *tag){
|
||||
char *str;
|
||||
int len;
|
||||
|
||||
str.memory_size = (int)strlen(tag);
|
||||
str_ = (char*)malloc(str.memory_size + 1);
|
||||
str = make_string(str_, 0, str.memory_size + 1);
|
||||
copy(&str, make_string(tag, str.memory_size));
|
||||
terminate_with_null(&str);
|
||||
len = (int)strlen(tag);
|
||||
str = (char*)malloc(len + 1);
|
||||
to_camel(tag, str);
|
||||
str[len] = 0;
|
||||
|
||||
is_first = 1;
|
||||
for (j = 0; j < str.size; ++j){
|
||||
c = str.str[j];
|
||||
if (char_is_alpha_numeric_true(c)){
|
||||
if (is_first){
|
||||
is_first = 0;
|
||||
str.str[j] = char_to_upper(c);
|
||||
}
|
||||
}
|
||||
else{
|
||||
is_first = 1;
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(file, "Stag_%s,\n", str.str);
|
||||
|
||||
free(str.str);
|
||||
return(str);
|
||||
}
|
||||
|
||||
char style_index_function_start[] =
|
||||
"inline u32*\n"
|
||||
"style_index_by_tag(Style_Main_Data *s, u32 tag){\n"
|
||||
" u32 *result = 0;\n"
|
||||
" switch (tag){\n";
|
||||
|
||||
char style_index_function_end[] =
|
||||
" }\n"
|
||||
" return(result);\n"
|
||||
"}\n\n";
|
||||
|
||||
char style_case[] = " case Stag_%s: result = &s->%s_color; break;\n";
|
||||
char style_info_case[] = " case Stag_%s: result = &s->file_info_style.%s_color; break;\n";
|
||||
|
||||
char* generate_style(){
|
||||
char *filename = "4coder_style.h & 4ed_style.h";
|
||||
char filename_4coder[] = "4coder_style.h";
|
||||
char filename_4ed[] = "4ed_style.h";
|
||||
FILE *file;
|
||||
char *tag;
|
||||
int count, i;
|
||||
|
||||
file = fopen(filename_4coder, "wb");
|
||||
|
@ -404,12 +429,16 @@ char* generate_style(){
|
|||
{
|
||||
count = ArrayCount(bar_style_fields);
|
||||
for (i = 0; i < count; ++i){
|
||||
do_style_tag(file, bar_style_fields[i]);
|
||||
tag = make_style_tag(bar_style_fields[i]);
|
||||
fprintf(file, "Stag_%s,\n", tag);
|
||||
free(tag);
|
||||
}
|
||||
|
||||
count = ArrayCount(main_style_fields);
|
||||
for (i = 0; i < count; ++i){
|
||||
do_style_tag(file, main_style_fields[i]);
|
||||
tag = make_style_tag(main_style_fields[i]);
|
||||
fprintf(file, "Stag_%s,\n", tag);
|
||||
free(tag);
|
||||
}
|
||||
}
|
||||
struct_end(file);
|
||||
|
@ -434,6 +463,25 @@ char* generate_style(){
|
|||
fprintf(file, "Interactive_Style file_info_style;\n");
|
||||
}
|
||||
struct_end(file);
|
||||
|
||||
{
|
||||
fprintf(file, "%s", style_index_function_start);
|
||||
count = ArrayCount(bar_style_fields);
|
||||
for (i = 0; i < count; ++i){
|
||||
tag = make_style_tag(bar_style_fields[i]);
|
||||
fprintf(file, style_info_case, tag, bar_style_fields[i]);
|
||||
free(tag);
|
||||
}
|
||||
|
||||
count = ArrayCount(main_style_fields);
|
||||
for (i = 0; i < count; ++i){
|
||||
tag = make_style_tag(main_style_fields[i]);
|
||||
fprintf(file, style_case, tag, main_style_fields[i]);
|
||||
free(tag);
|
||||
}
|
||||
fprintf(file, "%s", style_index_function_end);
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
||||
return(filename);
|
||||
|
|
|
@ -38,50 +38,6 @@ style_set_name(Style *style, String name){
|
|||
terminate_with_null(&style->name);
|
||||
}
|
||||
|
||||
inline u32*
|
||||
style_index_by_tag(Style *s, u32 tag){
|
||||
u32 *result = 0;
|
||||
switch (tag){
|
||||
case Stag_Bar: result = &s->main.file_info_style.bar_color; break;
|
||||
case Stag_Bar_Active: result = &s->main.file_info_style.bar_active_color; break;
|
||||
case Stag_Base: result = &s->main.file_info_style.base_color; break;
|
||||
case Stag_Pop1: result = &s->main.file_info_style.pop1_color; break;
|
||||
case Stag_Pop2: result = &s->main.file_info_style.pop2_color; break;
|
||||
|
||||
case Stag_Back: result = &s->main.back_color; break;
|
||||
case Stag_Margin: result = &s->main.margin_color; break;
|
||||
case Stag_Margin_Hover: result = &s->main.margin_hover_color; break;
|
||||
case Stag_Margin_Active: result = &s->main.margin_active_color; break;
|
||||
|
||||
case Stag_Cursor: result = &s->main.cursor_color; break;
|
||||
case Stag_At_Cursor: result = &s->main.at_cursor_color; break;
|
||||
case Stag_Highlight: result = &s->main.highlight_color; break;
|
||||
case Stag_At_Highlight: result = &s->main.at_highlight_color; break;
|
||||
case Stag_Mark: result = &s->main.mark_color; break;
|
||||
|
||||
case Stag_Default: result = &s->main.default_color; break;
|
||||
case Stag_Comment: result = &s->main.comment_color; break;
|
||||
case Stag_Keyword: result = &s->main.keyword_color; break;
|
||||
case Stag_Str_Constant: result = &s->main.str_constant_color; break;
|
||||
case Stag_Char_Constant: result = &s->main.char_constant_color; break;
|
||||
case Stag_Int_Constant: result = &s->main.int_constant_color; break;
|
||||
case Stag_Float_Constant: result = &s->main.float_constant_color; break;
|
||||
case Stag_Bool_Constant: result = &s->main.bool_constant_color; break;
|
||||
|
||||
case Stag_Preproc: result = &s->main.preproc_color; break;
|
||||
case Stag_Include: result = &s->main.include_color; break;
|
||||
|
||||
case Stag_Special_Character: result = &s->main.special_character_color; break;
|
||||
|
||||
case Stag_Highlight_Junk: result = &s->main.highlight_junk_color; break;
|
||||
case Stag_Highlight_White: result = &s->main.highlight_white_color; break;
|
||||
|
||||
case Stag_Paste: result = &s->main.paste_color; break;
|
||||
case Stag_Undo: result = &s->main.undo_color; break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
struct Style_Library{
|
||||
Style styles[64];
|
||||
i32 count, max;
|
||||
|
|
38
4ed_style.h
38
4ed_style.h
|
@ -35,3 +35,41 @@ u32 next_undo_color;
|
|||
Interactive_Style file_info_style;
|
||||
};
|
||||
|
||||
inline u32*
|
||||
style_index_by_tag(Style_Main_Data *s, u32 tag){
|
||||
u32 *result = 0;
|
||||
switch (tag){
|
||||
case Stag_Bar: result = &s->file_info_style.bar_color; break;
|
||||
case Stag_Bar_Active: result = &s->file_info_style.bar_active_color; break;
|
||||
case Stag_Base: result = &s->file_info_style.base_color; break;
|
||||
case Stag_Pop1: result = &s->file_info_style.pop1_color; break;
|
||||
case Stag_Pop2: result = &s->file_info_style.pop2_color; break;
|
||||
case Stag_Back: result = &s->back_color; break;
|
||||
case Stag_Margin: result = &s->margin_color; break;
|
||||
case Stag_Margin_Hover: result = &s->margin_hover_color; break;
|
||||
case Stag_Margin_Active: result = &s->margin_active_color; break;
|
||||
case Stag_Cursor: result = &s->cursor_color; break;
|
||||
case Stag_At_Cursor: result = &s->at_cursor_color; break;
|
||||
case Stag_Highlight: result = &s->highlight_color; break;
|
||||
case Stag_At_Highlight: result = &s->at_highlight_color; break;
|
||||
case Stag_Mark: result = &s->mark_color; break;
|
||||
case Stag_Default: result = &s->default_color; break;
|
||||
case Stag_Comment: result = &s->comment_color; break;
|
||||
case Stag_Keyword: result = &s->keyword_color; break;
|
||||
case Stag_Str_Constant: result = &s->str_constant_color; break;
|
||||
case Stag_Char_Constant: result = &s->char_constant_color; break;
|
||||
case Stag_Int_Constant: result = &s->int_constant_color; break;
|
||||
case Stag_Float_Constant: result = &s->float_constant_color; break;
|
||||
case Stag_Bool_Constant: result = &s->bool_constant_color; break;
|
||||
case Stag_Preproc: result = &s->preproc_color; break;
|
||||
case Stag_Include: result = &s->include_color; break;
|
||||
case Stag_Special_Character: result = &s->special_character_color; break;
|
||||
case Stag_Highlight_Junk: result = &s->highlight_junk_color; break;
|
||||
case Stag_Highlight_White: result = &s->highlight_white_color; break;
|
||||
case Stag_Paste: result = &s->paste_color; break;
|
||||
case Stag_Undo: result = &s->undo_color; break;
|
||||
case Stag_Next_Undo: result = &s->next_undo_color; break;
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue