2024-03-14 15:31:22 +01:00
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
let tab_script_hscript: ui_handle_t = ui_handle_create();
|
|
|
|
|
let tab_script_text_coloring: ui_text_coloring_t = null;
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
function tab_script_draw(htab: ui_handle_t) {
|
|
|
|
|
let ui: ui_t = ui_base_ui;
|
2024-03-14 15:31:22 +01:00
|
|
|
let statush: i32 = config_raw.layout[layout_size_t.STATUS_H];
|
2024-09-03 15:52:05 +02:00
|
|
|
if (ui_tab(htab, tr("Script")) && statush > ui_status_default_status_h * ui_SCALE(ui)) {
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
ui_begin_sticky();
|
2024-03-14 15:31:22 +01:00
|
|
|
if (config_raw.touch_ui) {
|
2024-11-08 23:46:39 +01:00
|
|
|
ui_row4();
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2024-04-25 22:04:43 +02:00
|
|
|
let row: f32[] = [1 / 14, 1 / 14, 1 / 14, 1 / 14];
|
2024-09-03 15:52:05 +02:00
|
|
|
ui_row(row);
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
2024-09-03 15:52:05 +02:00
|
|
|
if (ui_button(tr("Run"))) {
|
2024-07-22 23:39:09 +02:00
|
|
|
js_eval(tab_script_hscript.text);
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
2024-09-03 15:52:05 +02:00
|
|
|
if (ui_button(tr("Clear"))) {
|
2024-03-14 15:31:22 +01:00
|
|
|
tab_script_hscript.text = "";
|
|
|
|
|
}
|
2024-09-03 15:52:05 +02:00
|
|
|
if (ui_button(tr("Import"))) {
|
2024-03-20 16:13:54 +01:00
|
|
|
ui_files_show("js", false, false, function (path: string) {
|
|
|
|
|
let b: buffer_t = data_get_blob(path);
|
2024-03-14 15:31:22 +01:00
|
|
|
tab_script_hscript.text = sys_buffer_to_string(b);
|
|
|
|
|
data_delete_blob(path);
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-09-03 15:52:05 +02:00
|
|
|
if (ui_button(tr("Export"))) {
|
2024-03-20 16:13:54 +01:00
|
|
|
ui_files_show("js", true, false, function (path: string) {
|
2024-04-07 09:52:45 +02:00
|
|
|
let str: string = tab_script_hscript.text;
|
2024-03-14 15:31:22 +01:00
|
|
|
let f: string = ui_files_filename;
|
2024-03-20 16:13:54 +01:00
|
|
|
if (f == "") {
|
|
|
|
|
f = tr("untitled");
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
path = path + path_sep + f;
|
2024-03-20 16:13:54 +01:00
|
|
|
if (!ends_with(path, ".js")) {
|
|
|
|
|
path += ".js";
|
|
|
|
|
}
|
2024-09-03 16:39:16 +02:00
|
|
|
iron_file_save_bytes(path, sys_string_to_buffer(str), 0);
|
2024-03-14 15:31:22 +01:00
|
|
|
});
|
|
|
|
|
}
|
2024-09-03 15:52:05 +02:00
|
|
|
ui_end_sticky();
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-04-10 19:39:17 +02:00
|
|
|
let _font: g2_font_t = ui.ops.font;
|
2024-03-14 15:31:22 +01:00
|
|
|
let _font_size: i32 = ui.font_size;
|
|
|
|
|
let f: g2_font_t = data_get_font("font_mono.ttf");
|
2024-09-03 15:52:05 +02:00
|
|
|
ui_set_font(ui, f);
|
|
|
|
|
ui.font_size = math_floor(15 * ui_SCALE(ui));
|
|
|
|
|
ui_text_area_line_numbers = true;
|
|
|
|
|
ui_text_area_scroll_past_end = true;
|
|
|
|
|
ui_text_area_coloring = tab_script_get_text_coloring();
|
|
|
|
|
ui_text_area(tab_script_hscript);
|
|
|
|
|
ui_text_area_line_numbers = false;
|
|
|
|
|
ui_text_area_scroll_past_end = false;
|
|
|
|
|
ui_text_area_coloring = null;
|
|
|
|
|
ui_set_font(ui, _font);
|
2024-03-14 15:31:22 +01:00
|
|
|
ui.font_size = _font_size;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
function tab_script_get_text_coloring(): ui_text_coloring_t {
|
2024-03-14 15:31:22 +01:00
|
|
|
if (tab_script_text_coloring == null) {
|
2024-03-20 16:13:54 +01:00
|
|
|
let blob: buffer_t = data_get_blob("text_coloring.json");
|
2024-03-14 15:31:22 +01:00
|
|
|
tab_script_text_coloring = json_parse(sys_buffer_to_string(blob));
|
|
|
|
|
}
|
|
|
|
|
return tab_script_text_coloring;
|
|
|
|
|
}
|