setting the size of a Texture Button doesnt work

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

when i create a control (c++)
then some of the properties are ignored.

in my case its a texture button, and set_scale():

            TextureButton* tbut1 = memnew(TextureButton()); 
            newHBox->add_child(tbut1);
            //tbut1->set_expand(false); 
            //tbut1->set_stretch_mode(TextureButton::STRETCH_SCALE);
            //tbut1->set_clip_contents(true);
           
            // also sets size to size of texture (1024x1024 in my case) 
            // ignoring STRETCH_SCALE
            tbut1->set_normal_texture(testTex1); 

            // not needed, since sizeof texture much bigger (in this example)
            //tbut1->set_custom_minimum_size(Size2(20, 20)); 

            //for some reason texButton completely ignores size, 
            //even with STRETCH_SCALE
            tbut1->set_size(Size2(20, 20)); 
            tbut1->update(); //ignored since (pending_update = true;)
            tbut1->set_scale(Vector2(0.02, 0.02)); // it is ignored...
            tbut1->update(); //ignored since (pending_update = true;)

tbut1->set_scale(Vector2(0.02, 0.02)); is ignored at “creation time”

but when i call it (for test purpose) in the onClicked Handler, its gets scaled.
maybe has something todo with the (pending_update = true;)

what am i missing?

EDIT: changed header description to a better meaning

I think you should create instance by TextureButton* tbut1 = memnew(TextureButton);
not TextureButton* tbut1 = memnew(TextureButton());

volzhs | 2017-03-19 10:57

ofc thats true, tnx for hint :slight_smile:

Charles Woodhill | 2017-03-21 11:59

:bust_in_silhouette: Reply From: Charles Woodhill

ok got it:

	tbut1->set_expand(true); 
	tbut1->set_stretch_mode(TextureButton::STRETCH_SCALE);
	tbut1->set_normal_texture(testTex1);
	tbut1->set_custom_minimum_size(Size2(20, 20));
	//tbut1->set_size(Size2(20, 20)); // not needed since min size is 20/20

maybe one should consider changing the property expand to allow/enable_stretching,
although its a bit confusing for this use case.

i think the different behavior (when one change properties anywhere else then directly after create)
may be a effect that the size is determined when the control gets drawn, so there is diffrent behaviour of a control once its drawn.