瀏覽代碼

Fix wrong offset in Button when alignment is set to left

Michael Alexsander Silva Dias 6 年之前
父節點
當前提交
da5195fc92
共有 2 個文件被更改,包括 6 次插入2 次删除
  1. 1 1
      doc/classes/Button.xml
  2. 5 1
      scene/gui/button.cpp

+ 1 - 1
doc/classes/Button.xml

@@ -15,7 +15,7 @@
 			Text alignment policy for the button's text, use one of the [code]ALIGN_*[/code] constants.
 			Text alignment policy for the button's text, use one of the [code]ALIGN_*[/code] constants.
 		</member>
 		</member>
 		<member name="clip_text" type="bool" setter="set_clip_text" getter="get_clip_text" default="false">
 		<member name="clip_text" type="bool" setter="set_clip_text" getter="get_clip_text" default="false">
-			When this property is enabled, text that is too large to fit the button is clipped, when disabled the Button will always be wide enough to hold the text. This property is disabled by default.
+			When this property is enabled, text that is too large to fit the button is clipped, when disabled the Button will always be wide enough to hold the text.
 		</member>
 		</member>
 		<member name="flat" type="bool" setter="set_flat" getter="is_flat" default="false">
 		<member name="flat" type="bool" setter="set_flat" getter="is_flat" default="false">
 			Flat buttons don't display decoration.
 			Flat buttons don't display decoration.

+ 5 - 1
scene/gui/button.cpp

@@ -159,7 +159,11 @@ void Button::_notification(int p_what) {
 
 
 		switch (align) {
 		switch (align) {
 			case ALIGN_LEFT: {
 			case ALIGN_LEFT: {
-				text_ofs.x = style->get_margin(MARGIN_LEFT) + icon_ofs.x + _internal_margin[MARGIN_LEFT] + get_constant("hseparation");
+				if (_internal_margin[MARGIN_LEFT] > 0) {
+					text_ofs.x = style->get_margin(MARGIN_LEFT) + icon_ofs.x + _internal_margin[MARGIN_LEFT] + get_constant("hseparation");
+				} else {
+					text_ofs.x = style->get_margin(MARGIN_LEFT) + icon_ofs.x;
+				}
 				text_ofs.y += style->get_offset().y;
 				text_ofs.y += style->get_offset().y;
 			} break;
 			} break;
 			case ALIGN_CENTER: {
 			case ALIGN_CENTER: {