wNim icon indicating copy to clipboard operation
wNim copied to clipboard

Accessing wClass members in VFL

Open sonicsmooth opened this issue 11 months ago • 0 comments

How do I access class members in VFL? I didn't see any example how to do this. The VFL parser and layout DSL don't like dots. I have resorted to using variables for Button which are local to the init proc.

Example below does not stack the two buttons; only the second button shows, but the first button appears when I hover over. I dug into this a little and the parser throws an exception. I tried using refs to do a local alias in the layout proc but I'm new enough to Nim that I couldn't get that to work. I resorted to creating the buttons locally in the init proc, and defining layout() also locally in the init proc.

import wNim/[wApp, wMacros, wFrame, wPanel, wEvent, wButton]

type wButtonPanel = ref object of wPanel
    mB1: wButton
    mB2: wButton

wClass(wButtonPanel of wPanel):
  proc layout(self: wButtonPanel) =
      self.autolayout  """
      V:|-[self.mB1][self.mB2]
      """

  proc init(self: wButtonPanel, parent: wWindow) =
    wPanel(self).init(parent)
    self.mB1 = Button(self, label="Randomize")
    self.mB2 = Button(self, label="Compact X←")
    self.layout()
    self.wEvent_Size do():
      self.layout()

let app = App(wSystemDpiAware)
let frame = Frame(title="Button Frame", size=(600,400))
let bp = ButtonPanel(frame)
discard bp

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

There should be two buttons shown, but one overdraws the other. image

sonicsmooth avatar Jan 06 '25 21:01 sonicsmooth