tab_console.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. function tab_console_draw(htab: ui_handle_t) {
  2. let title: string = console_message_timer > 0 ? console_message + " " : tr("Console");
  3. let color: i32 = console_message_timer > 0 ? console_message_color : -1;
  4. if (ui_tab(htab, title, false, color) && ui._window_h > ui_statusbar_default_h * UI_SCALE()) {
  5. ui_begin_sticky();
  6. /// if (arm_windows || arm_linux || arm_macos) // Copy
  7. let row: f32[] = [ -100, -100, -100 ];
  8. /// else
  9. let row: f32[] = [ -100, -100 ];
  10. /// end
  11. ui_row(row);
  12. if (ui_button(tr("Clear"))) {
  13. console_last_traces = [];
  14. }
  15. if (ui_button(tr("Export"))) {
  16. ui_files_show("txt", true, false, function(path: string) {
  17. let str: string = string_array_join(console_last_traces, "\n");
  18. let f: string = ui_files_filename;
  19. if (f == "") {
  20. f = tr("untitled");
  21. }
  22. path = path + path_sep + f;
  23. if (!ends_with(path, ".txt")) {
  24. path += ".txt";
  25. }
  26. iron_file_save_bytes(path, sys_string_to_buffer(str), 0);
  27. });
  28. }
  29. /// if (arm_windows || arm_linux || arm_macos)
  30. if (ui_button(tr("Copy"))) {
  31. let str: string = string_array_join(console_last_traces, "\n");
  32. iron_copy_to_clipboard(str);
  33. }
  34. /// end
  35. ui_end_sticky();
  36. let _font: draw_font_t = ui.ops.font;
  37. let _font_size: i32 = ui.font_size;
  38. let f: draw_font_t = data_get_font("font_mono.ttf");
  39. ui_set_font(ui, f);
  40. ui.font_size = math_floor(15 * UI_SCALE());
  41. for (let i: i32 = 0; i < console_last_traces.length; ++i) {
  42. let t: string = console_last_traces[i];
  43. ui_text(t);
  44. }
  45. ui_set_font(ui, _font);
  46. ui.font_size = _font_size;
  47. }
  48. }