]> git.mxchange.org Git - flightgear.git/blobdiff - src/GUI/layout.cxx
Fix typo
[flightgear.git] / src / GUI / layout.cxx
index 7842fcacc9cfed36d85ebecf3f0c2f20f25e3999..f9581b3d5503a957313a340b7ec867960bbbfe40 100644 (file)
@@ -1,5 +1,12 @@
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
 #include "layout.hxx"
 
+#include <simgear/math/SGMath.hxx>
+
 // This file contains the actual layout engine.  It has no dependence
 // on outside libraries; see layout-props.cxx for the glue code.
 
@@ -23,8 +30,11 @@ bool LayoutWidget::eq(const char* a, const char* b)
 // <default-padding> property, or per widget with <padding>.
 int LayoutWidget::padding()
 {
-    int pad = isType("group") ? 0 : 4;
-    if(isType("dialog")) pad = 2;
+    int pad = (isType("group") || isType("frame")) ? 0 : 4;
+    // As comments above note,  this was being set to 2.  For some
+    // reason this causes the dialogs to shrink on subsequent pops
+    // so for now we'll make "dialog" padding 0.
+    if(isType("dialog")) pad = 0;
     if(hasParent() && parent().hasField("default-padding"))
         pad = parent().getNum("default-padding");
     if(hasField("padding"))
@@ -36,10 +46,13 @@ void LayoutWidget::calcPrefSize(int* w, int* h)
 {
     *w = *h = 0; // Ask for nothing by default
 
+    if (!getBool("enabled", true) || isType("nasal"))
+        return;
+
     int legw = stringLength(getStr("legend"));
     int labw = stringLength(getStr("label"));
 
-    if(isType("dialog") || isType("group")) {
+    if(isType("dialog") || isType("group") || isType("frame")) {
         if(!hasField("layout")) {
             // Legacy support for groups without layout managers.
             if(hasField("width")) *w = getNum("width");
@@ -52,7 +65,7 @@ void LayoutWidget::calcPrefSize(int* w, int* h)
         }
     } else if (isType("text")) {
         *w = labw;
-        *h = 4*UNIT; // FIXME: multi line height?
+        *h = 3*UNIT; // FIXME: multi line height?
     } else if (isType("button")) {
         *w = legw + 6*UNIT + (labw ? labw + UNIT : 0);
         *h = 6*UNIT;
@@ -66,8 +79,13 @@ void LayoutWidget::calcPrefSize(int* w, int* h)
         *w = *h = 17*UNIT;
         if(getBool("vertical")) *w = 4*UNIT;
         else                    *h = 4*UNIT;
-    } else if (isType("list") || isType("airport-list") || isType("dial")) {
+    } else if (isType("list") || isType("airport-list")
+            || isType("property-list") || isType("dial")) {
         *w = *h = 12*UNIT;
+    } else if (isType("hrule")) {
+        *h = 1;
+    } else if (isType("vrule")) {
+        *w = 1;
     }
 
     // Throw it all out if the user specified a fixed preference
@@ -87,6 +105,9 @@ void LayoutWidget::calcPrefSize(int* w, int* h)
 // Set up geometry such that the widget lives "inside" the specified 
 void LayoutWidget::layout(int x, int y, int w, int h)
 {
+    if (!getBool("enabled", true) || isType("nasal"))
+        return;
+
     setNum("__bx", x);
     setNum("__by", y);
     setNum("__bw", w);
@@ -108,11 +129,11 @@ void LayoutWidget::layout(int x, int y, int w, int h)
     if(hasField("_psw")) prefw = getNum("_psw");
     if(hasField("_psh")) prefh = getNum("_psh");
 
-    bool isGroup = isType("dialog") || isType("group");
+    bool isGroup = isType("dialog") || isType("group") || isType("frame");
 
     // Correct our box for alignment.  The values above correspond to
     // a "fill" alignment.
-    const char* halign = isGroup ? "fill" : "center";
+    const char* halign = (isGroup || isType("hrule")) ? "fill" : "center";
     if(hasField("halign")) halign = getStr("halign");
     if(eq(halign, "left")) {
         w = prefw;
@@ -123,7 +144,7 @@ void LayoutWidget::layout(int x, int y, int w, int h)
         x += (w - prefw)/2;
         w = prefw;
     }
-    const char* valign = isGroup ? "fill" : "center";
+    const char* valign = (isGroup || isType("vrule")) ? "fill" : "center";
     if(hasField("valign")) valign = getStr("valign");
     if(eq(valign, "bottom")) {
         h = prefh;
@@ -140,7 +161,10 @@ void LayoutWidget::layout(int x, int y, int w, int h)
     // the x/y/w/h box we have calculated.
     if (isType("text")) {
         // puText labels are layed out to the right of the box, so
-        // zero the width.
+        // zero the width. Also subtract PUSTR_RGAP from the x
+        // coordinate to compensate for the added gap between the
+        // label and its empty puObject.
+        x -= 5;
         w = 0;
     } else if (isType("input") || isType("combo") || isType("select")) {
         // Fix the height to a constant
@@ -182,6 +206,9 @@ void LayoutWidget::doHVBox(bool doLayout, bool vertical, int* w, int* h)
     int nEq = 0, eqA = 0, eqB = 0, eqTotalA = 0;
     for(i=0; i<nc; i++) {
         LayoutWidget child = getChild(i);
+        if (!child.getBool("enabled", true))
+            continue;
+
         int a, b;
         child.calcPrefSize(vertical ? &b : &a, vertical ? &a : &b);
         if(doLayout) prefA[i] = a;
@@ -217,6 +244,9 @@ void LayoutWidget::doHVBox(bool doLayout, bool vertical, int* w, int* h)
         // from top to bottom instead of along the cartesian Y axis.
         int idx = vertical ? (nc-i-1) : i;
         LayoutWidget child = getChild(idx);
+        if (!child.getBool("enabled", true))
+            continue;
+
         if(child.getBool("equal")) {
             int pad = child.padding();
             prefA[idx] = eqA + 2*pad;
@@ -293,7 +323,7 @@ void LayoutWidget::doTable(bool doLayout, int* w, int* h)
             int total = 0;
             for(j=0; j<cell->rspan; j++)
                 total += rowSizes[cell->row + j];
-            int extra = total - cell->h;
+            int extra = cell->h - total;
             if(extra > 0) {
                 for(j=0; j<cell->rspan; j++) {
                     int chunk = extra / (cell->rspan - j);
@@ -306,7 +336,7 @@ void LayoutWidget::doTable(bool doLayout, int* w, int* h)
             int total = 0;
             for(j=0; j<cell->cspan; j++)
                 total += colSizes[cell->col + j];
-            int extra = total - cell->w;
+            int extra = cell->w - total;
             if(extra > 0) {
                 for(j=0; j<cell->cspan; j++) {
                     int chunk = extra / (cell->cspan - j);