theme_editor.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. let plugin = new arm.Plugin();
  2. let hpanel = new zui.Handle();
  3. let hlist = new zui.Handle();
  4. function stringToBytes(str) {
  5. let ab = new ArrayBuffer(str.length);
  6. let u8 = new Uint8Array(ab);
  7. for (let i = 0; i < str.length; ++i) {
  8. u8[i] = str.charCodeAt(i);
  9. }
  10. return ab;
  11. }
  12. plugin.drawUI = function(ui) {
  13. if (ui.panel(hpanel, "Theme Editor")) {
  14. ui.row([1 / 4]);
  15. if (ui.button("Export")) {
  16. arm.UIFiles.show("json", true, function(path) {
  17. path += arm.Path.sep + arm.UIFiles.filename;
  18. if (!path.endsWith(".json")) path += ".json";
  19. Krom.fileSaveBytes(path, stringToBytes(JSON.stringify(arm.App.theme)));
  20. });
  21. }
  22. let i = 0;
  23. let theme = arm.App.theme;
  24. for (let key in theme) {
  25. let h = hlist.nest(i);
  26. let val = theme[key];
  27. let isHex = key.endsWith("_COL");
  28. if (isHex && val < 0) val += 4294967295;
  29. if (isHex) {
  30. ui.row([1 / 8, 7 / 8]);
  31. ui.text("", 0, val);
  32. if (ui.isHovered && ui.inputReleased) {
  33. arm.UIMenu.draw(function(ui) {
  34. ui.fill(0, 0, ui._w / ui.ops.scaleFactor, ui.t.ELEMENT_H * 6, ui.t.SEPARATOR_COL);
  35. ui.changed = false;
  36. h.color = theme[key];
  37. theme[key] = zui.Ext.colorWheel(ui, h, false, null, false, false);
  38. if (ui.changed) arm.UIMenu.keepOpen = true;
  39. });
  40. }
  41. }
  42. h.text = isHex ? val.toString(16) : val.toString();
  43. let res = ui.textInput(h, key);
  44. if (res === "true") theme[key] = true;
  45. else if (res === "false") theme[key] = false;
  46. else if (isHex) theme[key] = parseInt(h.text, 16);
  47. else theme[key] = parseInt(h.text);
  48. i++;
  49. }
  50. }
  51. }