Hello, I'm using the NiGUI library.
Does anyone know if there is a way to show a second window by clicking on a button in the main window?
Do you have any examples to show me to perform this operation?
In the examples present in the project on Github I don't think there is any of this.
I copied the first example https://github.com/simonkrauter/NiGui/blob/master/examples/example_01_basic_app.nim, then added the code of the second window
I basicly created a second window by copying the code of the first window, then added the command to show the second window in the callback of the button of the first window.
import nigui
app.init()
var window = newWindow("NiGui Example")
window.width = 600.scaleToDpi
window.height = 400.scaleToDpi
var container = newLayoutContainer(Layout_Vertical)
window.add(container)
var button = newButton("Button 1")
container.add(button)
var textArea = newTextArea()
container.add(textArea)
---<new code>---
var window2 = newWindow("Sub Window")
window2.width = 300.scaleToDpi
window2.height = 200.scaleToDpi
var container2 = newLayoutContainer(Layout_Vertical)
window2.add(container2)
var text = newLabel("Sub Window")
container2.add(text)
---</new code>---
button.onClick = proc(event: ClickEvent) =
textArea.addLine("Button 1 clicked, message box opened.")
window.alert("This is a simple message box.")
textArea.addLine("Message box closed.")
window2.show # show the second window
window.show()
app.run()
Here another example:
import nigui
app.init()
var mainWindow = newWindow("Main window")
var container1 = newLayoutContainer(Layout_Vertical)
mainWindow.add(container1)
var button1 = newButton("Open new window")
container1.add(button1)
var index = 0
button1.onClick = proc(event: ClickEvent) =
index.inc()
var additionalWindow = newWindow("Window " & $index)
var container2 = newLayoutContainer(Layout_Vertical)
additionalWindow.add(container2)
var button2 = newButton("Close")
container2.add(button2)
button2.onClick = proc(event: ClickEvent) =
additionalWindow.dispose()
additionalWindow.show()
mainWindow.show()
app.run()