SpinBoxes calculate correctly their width before first redraw.

This commit is contained in:
Ovnuniarchos 2018-02-05 22:42:30 +01:00
parent 5c9ecc174b
commit fe1ca3c6e6
2 changed files with 13 additions and 5 deletions

View file

@ -185,17 +185,22 @@ void SpinBox::_line_edit_focus_exit() {
_text_entered(line_edit->get_text()); _text_entered(line_edit->get_text());
} }
inline void SpinBox::_adjust_width_for_icon(const Ref<Texture> icon) {
int w = icon->get_width();
if (w != last_w) {
line_edit->set_margin(MARGIN_RIGHT, -w);
last_w = w;
}
}
void SpinBox::_notification(int p_what) { void SpinBox::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) { if (p_what == NOTIFICATION_DRAW) {
Ref<Texture> updown = get_icon("updown"); Ref<Texture> updown = get_icon("updown");
int w = updown->get_width(); _adjust_width_for_icon(updown);
if (w != last_w) {
line_edit->set_margin(MARGIN_RIGHT, -w);
last_w = w;
}
RID ci = get_canvas_item(); RID ci = get_canvas_item();
Size2i size = get_size(); Size2i size = get_size();
@ -207,6 +212,7 @@ void SpinBox::_notification(int p_what) {
//_value_changed(0); //_value_changed(0);
} else if (p_what == NOTIFICATION_ENTER_TREE) { } else if (p_what == NOTIFICATION_ENTER_TREE) {
_adjust_width_for_icon(get_icon("updown"));
_value_changed(0); _value_changed(0);
} }
} }

View file

@ -62,6 +62,8 @@ class SpinBox : public Range {
void _line_edit_focus_exit(); void _line_edit_focus_exit();
inline void _adjust_width_for_icon(const Ref<Texture> icon);
protected: protected:
void _gui_input(const Ref<InputEvent> &p_event); void _gui_input(const Ref<InputEvent> &p_event);