Changing text node value does not change its pick node size? (SOLVED)

Testing with a clean project, clean gui, Windows 10, editor 1.2.142

function on_input(self, action_id, action)
	if action.pressed and gui.pick_node (txtNode, action.x, action.y) then
		if gui.get_text (txtNode) == "A" then
			gui.set_text (txtNode, "LONGER WORD")
		else
			gui.set_text (txtNode, "A")
		end
	end 
end

function init(self)
	txtNode = gui.new_text_node (vmath.vector3 (100, 100, 0), "A")
	gui.set_pivot (txtNode, gui.PIVOT_NW)
	gui.set_size_mode (txtNode, gui.SIZE_MODE_AUTO)
	msg.post (".", "acquire_input_focus")
end

If you click on text node “A” so it changes to “LONGER WORD”, I was expecting pick node to resize so you can now click on the entire width of “LONGER WORD”. Instead you can only click on the letter “L” or likely just the width of the original text “A”.

I tried setting size_mode of the text to auto, but same results. Tried with default font, and importing a different font.

What is the proper way to do this? Currently my workaround is that whenever I change values of text nodes, I compute the metrics of the text and do a set_size again, but isn’t there a simpler way?

Thanks.

Calculating size based on text metrics is the way to solve this. Automatic resizing could perhaps be implemented for single line text.

2 Likes

Ok got it, that’s how I am doing things now, just want to make sure I didn’t miss anything. Thanks!

So gui.set_size_mode currently does nothing for text modes? That should be mentioned in gui reference.

You mean setting it to auto and expecting the size to be set to encompass the width of the text?

Yeah, that was the impression the reference text game me, until I looked up this post.

Ah, good point. I will make a note of it and make sure it gets updated when we do a new API ref release (at same time as new engine release).