airstruck / luigi

Lovely User Interfaces for Game Inventors
MIT License
113 stars 23 forks source link

Updating text component of a panel doesn't update the text #36

Closed tcfunk closed 8 years ago

tcfunk commented 8 years ago

I have a panel that I'm using for a a dialog box, but I seem to be unable to get the text component of it to update correctly.

Here's the panel I create:

local dialogOpts = {
  type       = 'panel',
  text       = 'Node information dialog box\nShould have a line break in it, but who knows?',
  width      = 350,
  height     = 150,
  wrap       = true,
  background = {200, 200, 200, 240},
  outline    = {255, 255, 255, 255},
}

local panel = Layout(dialogOpts)

Once I've caled panel:show(), however, I can't seem to update the text. Even if I call panel:hide(), then change the text, and call show() again.

Edit: To be more specific, I'm attempting to update the text as follows:

panel:hide()
panel.text = "new text"
panel:show()
airstruck commented 8 years ago

What you want is panel.root.text = "new text".

Layouts contain a tree of widgets; that "text" property and the others are really properties of the root widget, not properties of the layout. It's just a bit confusing in this case because you only have a root widget with nothing under it, so it doesn't look like a tree.

A layout's root widget is stored in layout.root.

tcfunk commented 8 years ago

Ah yep that worked wonderfully, thank you @airstruck