khchen / wNim

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

cannot use layout dsl in wrapper object (Invalid node kind nnkDotExpr for macros.`$`) #104

Closed enthus1ast closed 2 years ago

enthus1ast commented 3 years ago
import wnim

type
  MainWin = object
    app: wApp
    frame: wFrame
    but: wButton

proc newMain(): MainWin =
  result = MainWin()
  result.app = App()
  result.frame = Frame(title="Hello World", size=(400, 300))
  result.but = Button(result.frame, label = "foo")
  result.frame.show()
  result.frame.layout:
    result.but:
      height = 10
      width = 20

var mm = newMain()
mm.app.mainLoop()

Error:

PS C:\Users\david> nim c -r "c:\Users\david\projects\nimPlayground\bugWnim.nim"
Hint: used config file 'C:\Users\david\.choosenim\toolchains\nim-1.4.8\config\nim.cfg' [Conf]
Hint: used config file 'C:\Users\david\.choosenim\toolchains\nim-1.4.8\config\config.nims' [Conf]
...........................................................................................................................................................
stack trace: (most recent call last)
C:\Users\david\.nimble\pkgs\wnim-#head\wNim\private\wResizable.nim(217, 25) layoutRealize
C:\Users\david\.nimble\pkgs\wnim-#head\wNim\private\wResizable.nim(213, 7) layoutParser
C:\Users\david\.nimble\pkgs\wnim-#head\wNim\private\wResizable.nim(210, 13) addConstraint
C:\Users\david\.nimble\pkgs\wnim-#head\wNim\private\wResizable.nim(198, 12) addConstraint
C:\Users\david\.choosenim\toolchains\nim-1.4.8\lib\core\macros.nim(1281, 5) $
c:\Users\david\projects\nimPlayground\bugWnim.nim(15, 15) template/generic instantiation of `layout` from here
C:\Users\david\.nimble\pkgs\wnim-#head\wNim\private\wResizable.nim(232, 20) template/generic instantiation of `layoutRealize` from here
c:\Users\david\projects\nimPlayground\bugWnim.nim(16, 11) Error: Invalid node kind nnkDotExpr for macros.`$`
PS C:\Users\david> 

the workaround i found (which is tedious):

import wnim

type
  MainWin = object
    app: wApp
    frame: wFrame
    but: wButton

proc newMain(): MainWin =
  result = MainWin()
  result.app = App()
  result.frame = Frame(title="Hello World", size=(400, 300))
  result.but = Button(result.frame, label = "foo")
  result.frame.show()
  block:
    var frame = result.frame
    var but = result.but
    frame.layout:
      but:
        height = 10
        width = 20

var mm = newMain()
mm.app.mainLoop()

a little PS: wNim is awesome, well designed, well documented! Thank you for working on this!

khchen commented 2 years ago

This bug should be fixed already in last version.