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();
|
2022-12-29 22:26:51 +00:00
|
|
|
#m.vbox.setContentsMargin(10);
|
2023-01-03 18:45:28 +00:00
|
|
|
m.window.setLayout(m.vbox);
|
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);
|
2022-12-29 22:26:51 +00:00
|
|
|
m.checkbox_left = gui.widgets.CheckBox.new(m.tabsContent, style, {"label-position": "right"})
|
|
|
|
.setText("Wanna check something ?");
|
2022-12-29 06:27:04 +00:00
|
|
|
m.tab_1.addItem(m.checkbox_left);
|
2022-12-29 22:26:51 +00:00
|
|
|
m.checkbox_right = gui.widgets.CheckBox.new(m.tabsContent, style, {"label-position": "right"})
|
|
|
|
.setText("Checkbox with text on the right 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);
|
|
|
|
|
|
|
|
m.tab_2 = VBoxLayout.new();
|
|
|
|
m.tabs.addTab("tab-2", "Tab 2", m.tab_2);
|
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
|
|
|
});
|
|
|
|
m.tab_2.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
|
|
|
|
2022-12-29 06:27:04 +00:00
|
|
|
m.tab_2.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));
|
|
|
|
});
|
2022-12-29 22:26:51 +00:00
|
|
|
m.tab_2.addItem(m.checkable_button);
|
2023-01-03 18:45:28 +00:00
|
|
|
m.resize_button = gui.widgets.Button.new(m.tabsContent, style, {})
|
|
|
|
.setText("Resize this 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-04 11:35:34 +00:00
|
|
|
m.tab_2.addItem(m.resize_button, 5);
|
2022-12-29 06:27:04 +00:00
|
|
|
|
|
|
|
return m;
|
|
|
|
},
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
};
|
|
|
|
|