Update value of UI

Hey there!
So I’m currently working on a progress bar with verse, but having some troubles with it.
I’ve made a bar with color_block that I want to offset on a value that gets changed in the code multiple times, but it don’t change.
This is my float:
var Slider : float = 2000.0
& this is the Widget:

        MyCanvas : canvas = canvas:
            Slots := array:
                canvas_slot:
                    Anchors := anchors{Minimum := vector2{X := 0.5, Y := 0.97}, Maximum := vector2{X := 0.5, Y := 0.97}}
                    Offsets := margin{Top := 0.0, Left := -Slider, Right := 0.0, Bottom := 0.0}
                    Alignment := vector2{X := 0.5, Y := 0.5}
                    SizeToContent := true
                    Widget := color_block{DefaultColor:= color{R:=9.0, G:=226.0, B:=230.0}, DefaultDesiredSize := vector2{X := 2000.0, Y := 70.0}, DefaultOpacity := 1.0}

As you can see I’ve used the Slider float in Offsets := margin{Top := 0.0, Left := -Slider, Right := 0.0, Bottom := 0.0}

How can I consistently update this widget to see the right offset of the Widget?

Greetings!

Rather than updating the offsets, can you instead just shrink/grow the color_block size? With another color_block rendered below it to show as the background of the progress bar?

An example of this in action can be found here (Not my code, Credit to Wahlbeck). He has a full video guide on implementing this (for a custom boss) too which may be more handy.

1 Like

What you could try in your case is to retrieve and store the canvas object, then use RemoveWidget() and AddWidget() to update its content. I’m not sure it will work but you can try.

Also, canvas_slot cannot be updated as it’s a struct, but some widgets have setters functions you can use (e.g. color_block.SetDesiredSize() or text_base.SetText()) I’m pretty sure those one work without having to refresh the entire Canvas.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.