Jump to content

[Resolved Question] Update label dynamically


infal

Recommended Posts

I'm trying to get a label to update it's value dynamically when the selected item in a listbox is changed. It updates the first time but not after that.

 

I've used printlog to see that the selected index is in fact changing each time I click a different item in the listbox, but the label only updates once.

 

Any UI gurus able to tell me what I'm doing wrong?

 

function initUI()
    ... usual window init and registration stuff

    myLabel = window:createlabel(vec2(10, 10), "", 20)
end

function updateUI()
    ... check if selected index has changed

    --selected index has changed so update text label
    myLabel.caption = "Some string derived from the selected index"
end

 

 

EDIT: Never mind, I figured it out. The update was working correctly. I was getting the listbox entry incorrectly, so it was defaulting to 0  ???  ::)

Link to comment
Share on other sites

The logical steps are

initialization:

-remember your created Label (myLabel) globally

-remember the parental UIcontainer(window) globally

 

when you update:

-myLabel.visible = false

-myLabel = nil

-myLabel = window:createlabel(vec2(10, 10), "new Text", 20)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...