khchen / wNim

Nim's Windows GUI Framework
MIT License
326 stars 17 forks source link

Second panel makes layout fixed #31

Closed f-carraro closed 5 years ago

f-carraro commented 5 years ago

Consider the code:

import wNim

let app = App()
let frame = Frame(title="Test",size=(800, 600))
let panel1 = Panel(frame)
#let panel2 = Panel(frame)

let b1 = StaticBox(panel1,label="Test")

proc layout()=
    panel1.autolayout """
        spacing: 30
        HV:|-[b1]-|
    """

panel1.wEvent_Size do (): 
    layout()

layout()
frame.center()
frame.show()
app.mainLoop()

Compiling this code creates a panel that is resized automatically when the window changes size. I don't understand why creating a second unused panel (uncommenting line 6) makes panel1 to become fixed when resizing the window.

khchen commented 5 years ago

https://khchen.github.io/wNim/wFrame.html

If a frame has exactly one child window, not counting the status and toolbar, this child is resized to take the entire frame client area. If two or more windows are present, they should be laid out explicitly by manually

Try this:

import wNim

let app = App()
let frame = Frame(title="Test", size=(800, 600))
let panel1 = Panel(frame)
let panel2 = Panel(frame)

panel2.backgroundColor = wWheat

let b1 = StaticBox(panel1, label="Test")

proc layout()=
  frame.autolayout """
    H:|[panel1][panel2(panel1)]|
    V:|[panel1..2]|
  """

  panel1.autolayout """
    spacing: 30
    HV:|-[b1]-|
  """

frame.wEvent_Size do ():
  layout()

layout()
frame.center()
frame.show()
app.mainLoop()
f-carraro commented 5 years ago

Thank you!