Files
armorpaint/paint/sources/tab_scripts.c
T
2026-03-06 12:56:38 +01:00

92 lines
2.7 KiB
C

void tab_scripts_draw(ui_handle_t *htab) {
if (ui_tab(htab, tr("Scripts", null), false, -1, false)) {
ui_begin_sticky();
f32_array_t *row = f32_array_create_from_raw(
(f32[]){
-70,
-70,
-140,
},
3);
ui_row(row);
if (ui_icon_button(tr("Run", null), ICON_PLAY, UI_ALIGN_CENTER)) {
js_eval(tab_scripts_hscript->text);
}
if (ui_icon_button(tr("Edit", null), ICON_EDIT, UI_ALIGN_CENTER)) {
ui_menu_draw(&tab_scripts_draw_80816, -1, -1);
}
string_t_array_t *ar = any_array_create_from_raw(
(any[]){
"script.js",
},
1);
ui_handle_t *file_handle = ui_handle(__ID__);
ui_combo(file_handle, ar, tr("File", null), false, UI_ALIGN_LEFT, true);
ui_end_sticky();
draw_font_t *_font = ui->ops->font;
i32 _font_size = ui->font_size;
draw_font_t *f = data_get_font("font_mono.ttf");
ui_set_font(ui, f);
ui->font_size = math_floor(15 * UI_SCALE());
ui_text_area_line_numbers = true;
ui_text_area_scroll_past_end = true;
gc_unroot(ui_text_area_coloring);
ui_text_area_coloring = tab_scripts_get_text_coloring();
gc_root(ui_text_area_coloring);
ui_text_area(tab_scripts_hscript, UI_ALIGN_LEFT, true, "", false);
ui_text_area_line_numbers = false;
ui_text_area_scroll_past_end = false;
gc_unroot(ui_text_area_coloring);
ui_text_area_coloring = null;
ui_set_font(ui, _font);
ui->font_size = _font_size;
}
}
void tab_scripts_draw_80919(string_t *path) {
string_t *str = tab_scripts_hscript->text;
string_t *f = ui_files_filename;
if (string_equals(f, "")) {
f = string_copy(tr("untitled", null));
}
path = string_join(string_join(path, PATH_SEP), f);
if (!ends_with(path, ".js")) {
path = string_join(path, ".js");
}
iron_file_save_bytes(path, sys_string_to_buffer(str), 0);
}
void tab_scripts_draw_80863(string_t *path) {
buffer_t *b = data_get_blob(path);
tab_scripts_hscript->text = string_copy(sys_buffer_to_string(b));
data_delete_blob(path);
}
void tab_scripts_draw_80816() {
if (ui_menu_button(tr("Clear", null), "", ICON_ERASE)) {
tab_scripts_hscript->text = "";
}
if (ui_menu_button(tr("Import", null), "", ICON_IMPORT)) {
ui_files_show("js", false, false, &tab_scripts_draw_80863);
}
if (ui_menu_button(tr("Export", null), "", ICON_EXPORT)) {
ui_files_show("js", true, false, &tab_scripts_draw_80919);
}
}
ui_text_coloring_t *tab_scripts_get_text_coloring() {
if (tab_scripts_text_coloring == null) {
buffer_t *blob = data_get_blob("text_coloring.json");
gc_unroot(tab_scripts_text_coloring);
tab_scripts_text_coloring = json_parse(sys_buffer_to_string(blob));
gc_root(tab_scripts_text_coloring);
}
return tab_scripts_text_coloring;
}