瀏覽代碼

Make OptionButton itself take into account the arrow margin instead of relying on the theme

Michael Alexsander 5 年之前
父節點
當前提交
c4cd2c44c8
共有 1 個文件被更改,包括 12 次插入2 次删除
  1. 12 2
      scene/gui/option_button.cpp

+ 12 - 2
scene/gui/option_button.cpp

@@ -35,8 +35,9 @@ Size2 OptionButton::get_minimum_size() const {
 
 
 	Size2 minsize = Button::get_minimum_size();
 	Size2 minsize = Button::get_minimum_size();
 
 
-	if (has_icon("arrow"))
+	if (has_icon("arrow")) {
 		minsize.width += Control::get_icon("arrow")->get_width() + get_constant("hseparation");
 		minsize.width += Control::get_icon("arrow")->get_width() + get_constant("hseparation");
+	}
 
 
 	return minsize;
 	return minsize;
 }
 }
@@ -73,6 +74,12 @@ void OptionButton::_notification(int p_what) {
 			Point2 ofs(size.width - arrow->get_width() - get_constant("arrow_margin"), int(Math::abs((size.height - arrow->get_height()) / 2)));
 			Point2 ofs(size.width - arrow->get_width() - get_constant("arrow_margin"), int(Math::abs((size.height - arrow->get_height()) / 2)));
 			arrow->draw(ci, ofs, clr);
 			arrow->draw(ci, ofs, clr);
 		} break;
 		} break;
+		case NOTIFICATION_THEME_CHANGED: {
+
+			if (has_icon("arrow")) {
+				_set_internal_margin(MARGIN_RIGHT, Control::get_icon("arrow")->get_width());
+			}
+		} break;
 		case NOTIFICATION_VISIBILITY_CHANGED: {
 		case NOTIFICATION_VISIBILITY_CHANGED: {
 
 
 			if (!is_visible_in_tree()) {
 			if (!is_visible_in_tree()) {
@@ -327,7 +334,7 @@ void OptionButton::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("_get_items"), &OptionButton::_get_items);
 	ClassDB::bind_method(D_METHOD("_get_items"), &OptionButton::_get_items);
 
 
 	ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_items", "_get_items");
 	ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_items", "_get_items");
-	// "selected" property must come after "items", otherwise GH-10213 occurs
+	// "selected" property must come after "items", otherwise GH-10213 occurs.
 	ADD_PROPERTY(PropertyInfo(Variant::INT, "selected"), "_select_int", "get_selected");
 	ADD_PROPERTY(PropertyInfo(Variant::INT, "selected"), "_select_int", "get_selected");
 	ADD_SIGNAL(MethodInfo("item_selected", PropertyInfo(Variant::INT, "id")));
 	ADD_SIGNAL(MethodInfo("item_selected", PropertyInfo(Variant::INT, "id")));
 	ADD_SIGNAL(MethodInfo("item_focused", PropertyInfo(Variant::INT, "id")));
 	ADD_SIGNAL(MethodInfo("item_focused", PropertyInfo(Variant::INT, "id")));
@@ -339,6 +346,9 @@ OptionButton::OptionButton() {
 	set_toggle_mode(true);
 	set_toggle_mode(true);
 	set_text_align(ALIGN_LEFT);
 	set_text_align(ALIGN_LEFT);
 	set_action_mode(ACTION_MODE_BUTTON_PRESS);
 	set_action_mode(ACTION_MODE_BUTTON_PRESS);
+	if (has_icon("arrow")) {
+		_set_internal_margin(MARGIN_RIGHT, Control::get_icon("arrow")->get_width());
+	}
 
 
 	popup = memnew(PopupMenu);
 	popup = memnew(PopupMenu);
 	popup->hide();
 	popup->hide();