How do I make a Label not draw over itself when modified?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Payotz
:warning: Old Version Published before Godot 3 was released.

So basically, I’ve been getting my input from a LineEdit, setting it to a Label and adding the Label to a Panel. It’s working for the first run, like so:

First run is working
The problem is, if I change the value, it doesn’t really “redraw” itself, rather it “draws over itself”, like so:

And it all goes down

I have the Labels inside a Dictionary, so I can track it, and I have an if-check to prevent me from creating new Labels, so I think it’s not an issue of me creating new Labels each time.

I’ve also tried Panel.update(), but it doesn’t do anything.
I’ve also tried removing the Label at the start, and adding it again after I set the text, but again it doesn’t do anything.

Any ideas?

Are you sure there is only one label per line? (check the remote inspector)


More code showing your data structures and ways you set the text could be useful.
Scene structure too.

eons | 2017-03-23 17:54

So I checked the remote inspector and it really did have more than one label per line.
It turns out that there are more Labels per line, so I did a check that will make sure that a Label is a single line only, it worked:

enter image description here

Now I think the problem is not the Label drawing over itself, but it’s drawing two labels at the same line. Hence here:

enter image description here

Which doesn’t really make sense, since I often remove the label before adding it again. Unless, Panel.remove_child() doesn’t remove the child, or I haven’t been tracking the original Label at all.

This is my code:
enter image description here

button_list is where I track the buttons (water,gold,lumber,food) in the original question.
label_proposal_player is what I use to track the labels in question
button_quantity_list is where I track my line edits.
player_pressed is just to make sure that a single button click doesn’t make 8 Labels.

My scene tree is here:
enter image description here

The Panels are populated by the _ready function, and the _fixed_process(delta) function.
The _fixed_process() function calls on check_player_proposal_buttons() (because of the Label check thing)

add_item and want_item contains my lineEdit and buttons in the original question.

_ready():

enter image description here

Payotz | 2017-03-23 21:47

I think you could simplify a lot that process dividing the problem into scenes and using signals to change values, also using labels for visual representation only (but, as I use to say, depends on the design).


Back to the issue, it is possible that you lost the reference to the labels in some way, try storing the label path after adding them to the tree instead of the node itself (I know it fails in some arrays, maybe dictionary too).

To see where you lost the variables you can try to print the paths and the instance ID on the output when changing values and removing labels, before doing anything else.

eons | 2017-03-23 23:17

:bust_in_silhouette: Reply From: Omicron

Disclaimer : I am not using Godot yet, so this is not legal advice :stuck_out_tongue:

I think you spotted the right thing here : parent background needs to be redrawn.

According to doc, Panel.update() is a lazy function, I suggest to try to use myPanel.draw() (if it is the one intended for that) to force redraw.

or something like myPanel.propagate_notification(CanvasItem.NOTIFICATION_DRAW)

Between, are your object names same as class names o_O ?

Later !

:bust_in_silhouette: Reply From: Payotz

So, yeah this is embarassing. The problem was that my condition at the beginning that checks if the label is a member of a list, is wrong:

if(!(add_item_keys in label_proposal_player)): # check add_item_keys 

It should be :

if(label_proposal_player.has(add_item_keys)): # check add_item_keys

Hence, my final check_player_proposal_buttons() function:
enter image description here

  1. If add_item_keys[i] is not in label_proposal_player, make a Label.
  2. If add_item_keys[i] is not in label_path, add it and set it to null
  3. If add_item_keys[i] is in label_path, remove it from the Panel

Thank you for the time folks, and thanks for helping!