Selaa lähdekoodia

MarginContainer: Add top, right and bottom margins

Ignacio Etcheverry 9 vuotta sitten
vanhempi
commit
d38454b967
2 muutettua tiedostoa jossa 18 lisäystä ja 11 poistoa
  1. 14 10
      scene/gui/margin_container.cpp
  2. 4 1
      scene/resources/default_theme/default_theme.cpp

+ 14 - 10
scene/gui/margin_container.cpp

@@ -31,7 +31,10 @@
 
 Size2 MarginContainer::get_minimum_size() const {
 
-	int margin = get_constant("margin");
+	int margin_left = get_constant("margin_left");
+	int margin_top = get_constant("margin_top");
+	int margin_right = get_constant("margin_right");
+	int margin_bottom = get_constant("margin_bottom");
 
 	Size2 max;
 
@@ -52,9 +55,10 @@ Size2 MarginContainer::get_minimum_size() const {
 			max.height = s.height;
 	}
 
-	max.width += margin;
-	return max;
+	max.width += (margin_left + margin_right);
+	max.height += (margin_top + margin_bottom);
 
+	return max;
 
 }
 
@@ -62,7 +66,10 @@ void MarginContainer::_notification(int p_what) {
 
 	if (p_what==NOTIFICATION_SORT_CHILDREN) {
 
-		int margin = get_constant("margin");
+		int margin_left = get_constant("margin_left");
+		int margin_top = get_constant("margin_top");
+		int margin_right = get_constant("margin_right");
+		int margin_bottom = get_constant("margin_bottom");
 
 		Size2 s = get_size();
 
@@ -73,13 +80,10 @@ void MarginContainer::_notification(int p_what) {
 				continue;
 			if (c->is_set_as_toplevel())
 				continue;
-			int w;
-			if (c->get_h_size_flags() & Control::SIZE_EXPAND)
-				w=s.width-margin;
-			else
-				w=c->get_combined_minimum_size().width;
 
-			fit_child_in_rect(c,Rect2(margin,0,s.width-margin,s.height));
+			int w=s.width-margin_left-margin_right;
+			int h=s.height-margin_top-margin_bottom;
+			fit_child_in_rect(c,Rect2(margin_left,margin_top,w,h));
 		}
 
 	}

+ 4 - 1
scene/resources/default_theme/default_theme.cpp

@@ -836,7 +836,10 @@ void make_default_theme() {
 
 	t->set_constant("separation","HBoxContainer",4);
 	t->set_constant("separation","VBoxContainer",4);
-	t->set_constant("margin","MarginContainer",8);
+	t->set_constant("margin_left","MarginContainer",8);
+	t->set_constant("margin_top","MarginContainer",0);
+	t->set_constant("margin_right","MarginContainer",0);
+	t->set_constant("margin_bottom","MarginContainer",0);
 	t->set_constant("hseparation","GridContainer",4);
 	t->set_constant("vseparation","GridContainer",4);
 	t->set_constant("separation","HSplitContainer",12);