2022-12-29 06:27:04 +00:00
|
|
|
var WidgetsFactoryDialog = {
|
|
|
|
new: func {
|
|
|
|
var m = {
|
2023-01-03 18:45:28 +00:00
|
|
|
parents: [WidgetsFactoryDialog],
|
|
|
|
window: canvas.Window.new([500, 500], "dialog")
|
2022-12-29 06:27:04 +00:00
|
|
|
};
|
|
|
|
|
2023-01-03 18:45:28 +00:00
|
|
|
m.window.setBool("resize", 1);
|
2022-12-29 06:27:04 +00:00
|
|
|
|
2023-01-04 11:35:34 +00:00
|
|
|
m.root = m.window.getCanvas(1)
|
2022-12-29 06:27:04 +00:00
|
|
|
.set("background", style.getColor("bg_color"))
|
|
|
|
.createGroup();
|
|
|
|
m.vbox = VBoxLayout.new();
|
2023-01-03 18:45:28 +00:00
|
|
|
m.window.setLayout(m.vbox);
|
2022-12-29 06:27:04 +00:00
|
|
|
|
2023-01-18 14:25:28 +00:00
|
|
|
m.menubar = canvas.gui.widgets.MenuBar.new(m.root, canvas.style, {});
|
|
|
|
m.menubar.setCanvasItem(m.root);
|
|
|
|
m.menubar.createMenu("File")
|
|
|
|
.createItem(text: "Quit", cb: func m.del(), shortcut: "<Ctrl>+Q");
|
2023-01-24 13:13:05 +00:00
|
|
|
var tabsMenu = m.menubar.createMenu("Tabs");
|
|
|
|
tabsMenu.createItem(text: "Select first tab", cb: func m.tabs.setCurrentTab("tab-1"));
|
|
|
|
tabsMenu.createItem(text: "Select second tab", cb: func m.tabs.setCurrentTab("tab-2"));
|
|
|
|
|
2023-01-21 22:48:44 +00:00
|
|
|
var widgetsMenu = m.menubar.createMenu("Widgets");
|
|
|
|
widgetsMenu.createItem(text: "Benchmark label", cb: func {
|
|
|
|
m.benchmark_widget(canvas.gui.widgets.Label, func(w, i) {
|
|
|
|
w.setText("Label " ~ i);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
widgetsMenu.createItem(text: "Benchmark radio button", cb: func {
|
|
|
|
m.benchmark_radio_button(func(w, i) {
|
|
|
|
w.setText("Radio button " ~ i);
|
|
|
|
});
|
|
|
|
});
|
2023-01-18 14:25:28 +00:00
|
|
|
m.vbox.addItem(m.menubar);
|
|
|
|
|
2022-12-29 06:27:04 +00:00
|
|
|
m.tabs = gui.widgets.TabWidget.new(m.root, style, {});
|
2022-12-29 22:26:51 +00:00
|
|
|
m.tabsContent = m.tabs.getContent();
|
2022-12-29 06:27:04 +00:00
|
|
|
m.vbox.addItem(m.tabs);
|
|
|
|
|
|
|
|
m.tab_1 = VBoxLayout.new();
|
|
|
|
m.tabs.addTab("tab-1", "Tab 1", m.tab_1);
|
2022-12-29 22:26:51 +00:00
|
|
|
m.label = gui.widgets.Label.new(m.tabsContent, style, {})
|
2022-12-29 06:27:04 +00:00
|
|
|
.setText("A label")
|
2022-12-29 22:26:51 +00:00
|
|
|
.setBackground("#ffaaaa");
|
2022-12-29 06:27:04 +00:00
|
|
|
m.tab_1.addItem(m.label);
|
2023-01-10 14:19:54 +00:00
|
|
|
|
|
|
|
var r = gui.widgets.HorizontalRule.new(m.tabsContent, style, {});
|
|
|
|
r.setText("Checkboxes!");
|
|
|
|
m.tab_1.addItem(r);
|
|
|
|
|
2023-01-21 22:48:44 +00:00
|
|
|
m.checkbox_left = gui.widgets.CheckBox.new(m.tabsContent, style, {})
|
2022-12-29 22:26:51 +00:00
|
|
|
.setText("Wanna check something ?");
|
2022-12-29 06:27:04 +00:00
|
|
|
m.tab_1.addItem(m.checkbox_left);
|
2023-01-21 22:48:44 +00:00
|
|
|
m.checkbox_right = gui.widgets.CheckBox.new(m.tabsContent, style, {"label-position": "left"})
|
|
|
|
.setText("Checkbox with text on the left side");
|
2022-12-29 06:27:04 +00:00
|
|
|
m.tab_1.addItem(m.checkbox_right);
|
2022-12-29 22:26:51 +00:00
|
|
|
m.property_checkbox = gui.widgets.PropertyCheckBox.new(props.globals.getNode("/controls/lighting/nav-lights"), m.tabsContent, style, {})
|
2022-12-29 06:27:04 +00:00
|
|
|
.setText("Nav lights");
|
|
|
|
m.tab_1.addItem(m.property_checkbox);
|
|
|
|
|
2023-01-10 14:19:54 +00:00
|
|
|
var r2 = gui.widgets.HorizontalRule.new(m.tabsContent, style, {});
|
|
|
|
m.tab_1.addItem(r2);
|
2023-01-21 22:48:44 +00:00
|
|
|
|
|
|
|
m.radio1 = gui.widgets.RadioButton.new(m.tabsContent)
|
|
|
|
.setText("Radio button 1");
|
|
|
|
m.tab_1.addItem(m.radio1);
|
|
|
|
m.radio2 = gui.widgets.RadioButton.new(parent: m.tabsContent, cfg: {parentRadio: m.radio1})
|
|
|
|
.setText("Radio button 2");
|
|
|
|
m.tab_1.addItem(m.radio2);
|
|
|
|
m.radio3 = gui.widgets.RadioButton.new(parent: m.tabsContent, cfg: {parentRadio: m.radio1})
|
|
|
|
.setText("Radio button 3");
|
|
|
|
m.tab_1.addItem(m.radio3);
|
|
|
|
m.radio4 = gui.widgets.RadioButton.new(parent: m.tabsContent, cfg: {parentRadio: m.radio1})
|
|
|
|
.setText("Radio button 4");
|
|
|
|
m.tab_1.addItem(m.radio4);
|
2023-01-10 14:19:54 +00:00
|
|
|
|
2023-01-19 18:12:18 +00:00
|
|
|
m.tab_2 = HBoxLayout.new();
|
2022-12-29 06:27:04 +00:00
|
|
|
m.tabs.addTab("tab-2", "Tab 2", m.tab_2);
|
2023-01-19 18:12:18 +00:00
|
|
|
|
|
|
|
m.button_box = VBoxLayout.new();
|
|
|
|
m.tab_2.addItem(m.button_box);
|
|
|
|
|
2022-12-29 22:26:51 +00:00
|
|
|
m.button = gui.widgets.Button.new(m.tabsContent, style, {})
|
2022-12-29 06:27:04 +00:00
|
|
|
.setText("A button")
|
2023-01-03 18:45:28 +00:00
|
|
|
.setFixedSize(60, 30)
|
2022-12-29 06:27:04 +00:00
|
|
|
.listen("clicked", func {
|
2022-12-29 22:26:51 +00:00
|
|
|
InputDialog.getText("You clicked the button …", "Enter some text:", func (button, text) {
|
|
|
|
MessageBox.information("You clicked the button …", "… and entered '" ~ (text != nil ? text : "nothing") ~ "' !");
|
|
|
|
});
|
2022-12-29 06:27:04 +00:00
|
|
|
});
|
2023-01-19 18:12:18 +00:00
|
|
|
m.button_box.addItem(m.button);
|
2022-12-29 22:26:51 +00:00
|
|
|
m.image = gui.widgets.Label.new(m.tabsContent, style, {})
|
|
|
|
.setImage("Textures/Splash1.png")
|
2023-01-04 15:32:26 +00:00
|
|
|
.setVisible(0)
|
2022-12-29 22:26:51 +00:00
|
|
|
.setFixedSize(128, 128);
|
2023-01-04 15:32:26 +00:00
|
|
|
|
2023-01-19 18:12:18 +00:00
|
|
|
m.button_box.addItem(m.image);
|
2023-01-05 14:28:20 +00:00
|
|
|
m.image._view._root.addEventListener("mousedown", func (e) {
|
|
|
|
logprint(LOG_INFO, "Image was clicked at:" ~ e.localX ~ "," ~ e.localY);
|
|
|
|
logprint(LOG_INFO, "Client pos:" ~ e.clientX ~ "," ~ e.clientY);
|
|
|
|
logprint(LOG_INFO, "Screen pos:" ~ e.screenX ~ "," ~ e.screenY);
|
|
|
|
|
|
|
|
var img = m.image._view._root;
|
|
|
|
var localPos = [e.localX, e.localY];
|
|
|
|
var canvasPos = img.localToCanvas(localPos);
|
|
|
|
|
|
|
|
logprint(LOG_INFO, "computed canvasPos pos:" ~ canvasPos[0] ~ "," ~ canvasPos[1]);
|
|
|
|
|
|
|
|
var screenPos = m.window.toScreenPosition(canvasPos);
|
|
|
|
logprint(LOG_INFO, "computed screen pos:" ~ screenPos[0] ~ "," ~ screenPos[1]);
|
|
|
|
});
|
2023-01-04 15:32:26 +00:00
|
|
|
|
2022-12-29 22:26:51 +00:00
|
|
|
m.checkable_button = gui.widgets.Button.new(m.tabsContent, style, {})
|
2022-12-29 06:27:04 +00:00
|
|
|
.setCheckable(1)
|
|
|
|
.setChecked(0)
|
|
|
|
.setText("Checkable button")
|
2023-01-04 11:35:34 +00:00
|
|
|
.setFixedSize(120, 30)
|
2022-12-29 06:27:04 +00:00
|
|
|
.listen("toggled", func (e) {
|
|
|
|
m.image.setVisible(int(e.detail.checked));
|
|
|
|
});
|
2023-01-19 18:12:18 +00:00
|
|
|
m.button_box.addItem(m.checkable_button);
|
2023-01-07 04:06:19 +00:00
|
|
|
|
|
|
|
m.upsize_button = gui.widgets.Button.new(m.tabsContent, style, {})
|
|
|
|
.setText("Upsize window")
|
2023-01-04 11:35:34 +00:00
|
|
|
.setFixedSize(130, 30)
|
2023-01-03 18:45:28 +00:00
|
|
|
.listen("clicked", func {
|
2023-01-04 11:35:34 +00:00
|
|
|
var s = m.window.getSize();
|
|
|
|
m.window.setSize(s[0] + 100, s[1] + 100);
|
2023-01-03 18:45:28 +00:00
|
|
|
});
|
2023-01-19 18:12:18 +00:00
|
|
|
m.button_box.addItem(m.upsize_button);
|
2022-12-29 06:27:04 +00:00
|
|
|
|
2023-01-07 04:06:19 +00:00
|
|
|
m.downsize_button = gui.widgets.Button.new(m.tabsContent, style, {})
|
|
|
|
.setText("Downsize window")
|
|
|
|
.setFixedSize(130, 30)
|
|
|
|
.listen("clicked", func {
|
|
|
|
var s = m.window.getSize();
|
|
|
|
m.window.setSize(s[0] - 100, s[1] - 100);
|
|
|
|
});
|
2023-01-19 18:12:18 +00:00
|
|
|
m.button_box.addItem(m.downsize_button);
|
|
|
|
|
|
|
|
m.list_box = VBoxLayout.new();
|
|
|
|
m.tab_2.addItem(m.list_box);
|
|
|
|
|
|
|
|
m.list = gui.widgets.List.new(m.tabsContent);
|
|
|
|
for (var i = 0; i < 30; i += 1) {
|
|
|
|
m.list.createItem("Item " ~ i);
|
|
|
|
}
|
|
|
|
m.list.listen("selection-changed", func {
|
|
|
|
m.list_selection_label.setText("Selected items: " ~ (string.join(", ", map(func(item) item._text, m.list.getSelectedItems())) or "none"));
|
|
|
|
});
|
|
|
|
m.list.setSizeHint([m.list._MAX_SIZE, m.list._MAX_SIZE]);
|
|
|
|
m.list_box.addItem(m.list);
|
|
|
|
|
|
|
|
m.list_selection_label = gui.widgets.Label.new(m.tabsContent, canvas.style, {})
|
|
|
|
.setText("Selected items: none");
|
|
|
|
m.list_selection_label.setAlignment(canvas.AlignBottom);
|
|
|
|
m.list_box.addItem(m.list_selection_label);
|
2023-01-18 14:25:28 +00:00
|
|
|
|
|
|
|
m.benchmark_tab = VBoxLayout.new();
|
|
|
|
m.tabs.addTab("benchmark", "Benchmark", m.benchmark_tab);
|
|
|
|
m.benchmark_tab_scroll = canvas.gui.widgets.ScrollArea.new(m.tabsContent, canvas.style, {});
|
2023-01-19 18:12:18 +00:00
|
|
|
m.benchmark_tab_scroll.setSizeHint([m.list._MAX_SIZE, m.list._MAX_SIZE]);
|
2023-01-18 14:25:28 +00:00
|
|
|
m.benchmark_tab_scroll_layout = VBoxLayout.new();
|
2023-01-21 22:48:44 +00:00
|
|
|
m.benchmark_tab_scroll_layout.setSpacing(0);
|
2023-01-18 14:25:28 +00:00
|
|
|
m.benchmark_tab_scroll.setLayout(m.benchmark_tab_scroll_layout);
|
|
|
|
m.benchmark_tab.addItem(m.benchmark_tab_scroll);
|
|
|
|
m.benchmark_statistics = canvas.gui.widgets.Label.new(m.tabsContent, canvas.style, {});
|
|
|
|
m.benchmark_statistics.setAlignment(canvas.AlignBottom);
|
|
|
|
m.benchmark_tab.addItem(m.benchmark_statistics);
|
2023-01-07 04:06:19 +00:00
|
|
|
|
2023-01-10 13:30:39 +00:00
|
|
|
m.numericControlsTab = VBoxLayout.new();
|
|
|
|
m.tabs.addTab("ncTab", "Numeric Controls", m.numericControlsTab);
|
|
|
|
m.slider = gui.widgets.Slider.new(m.tabsContent, style,
|
|
|
|
{"max-value" : 100,
|
|
|
|
"page-step" : 20,
|
|
|
|
"tick-count" : 10})
|
|
|
|
.setValue(42);
|
|
|
|
m.numericControlsTab.addItem(m.slider);
|
2023-01-20 16:11:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
m.combo1 = gui.widgets.ComboBox.new(m.tabsContent, style, {});
|
|
|
|
m.combo1.addMenuItem("Apples", 0);
|
|
|
|
m.combo1.addMenuItem("Pears", 1);
|
|
|
|
m.combo1.addMenuItem("Lemons", 2);
|
|
|
|
m.combo1.addMenuItem("Oranges", 3);
|
|
|
|
|
|
|
|
m.numericControlsTab.addItem(m.combo1);
|
2022-12-29 06:27:04 +00:00
|
|
|
return m;
|
|
|
|
},
|
|
|
|
|
2023-01-18 14:25:28 +00:00
|
|
|
benchmark_widget: func(widget, proc_func=nil, amount=50) {
|
|
|
|
var start = systime();
|
|
|
|
me.benchmark_tab_scroll_layout.clear();
|
|
|
|
for (var i = 0; i < amount; i += 1) {
|
|
|
|
var w = widget.new(me.benchmark_tab_scroll.getContent(), canvas.style, {});
|
|
|
|
if (proc_func != nil) {
|
|
|
|
proc_func(w, i);
|
|
|
|
}
|
|
|
|
me.benchmark_tab_scroll_layout.addItem(w);
|
|
|
|
}
|
|
|
|
var time = systime() - start;
|
|
|
|
me.benchmark_statistics.setText("Took " ~ time ~ " seconds to add " ~ amount ~ " widgets.");
|
|
|
|
},
|
|
|
|
|
2023-01-21 22:48:44 +00:00
|
|
|
benchmark_radio_button: func(proc_func=nil, amount=50) {
|
|
|
|
var start = systime();
|
|
|
|
me.benchmark_tab_scroll_layout.clear();
|
|
|
|
var r = canvas.gui.widgets.RadioButton.new(me.benchmark_tab_scroll.getContent());
|
|
|
|
for (var i = 1; i < amount; i += 1) {
|
|
|
|
var w = canvas.gui.widgets.RadioButton.new(me.benchmark_tab_scroll.getContent(), canvas.style, {parentRadio: r});
|
|
|
|
if (proc_func != nil) {
|
|
|
|
proc_func(w, i);
|
|
|
|
}
|
|
|
|
me.benchmark_tab_scroll_layout.addItem(w);
|
|
|
|
}
|
|
|
|
var time = systime() - start;
|
|
|
|
me.benchmark_statistics.setText("Took " ~ time ~ " seconds to add " ~ amount ~ " widgets.");
|
|
|
|
},
|
|
|
|
|
2022-12-29 06:27:04 +00:00
|
|
|
del: func {
|
|
|
|
me.property_checkbox.del();
|
2023-01-03 18:45:28 +00:00
|
|
|
me.window.del();
|
2022-12-29 06:27:04 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|