ecere/gui/Button: Fixed auto-sizing to caption with minClientSize set
authorJerome St-Louis <jerome@ecere.com>
Mon, 17 Mar 2014 02:50:37 +0000 (22:50 -0400)
committerJerome St-Louis <jerome@ecere.com>
Mon, 17 Mar 2014 02:50:37 +0000 (22:50 -0400)
- Now auto-sizing when initSize is set to 0
- Had to fix ScrollBar thumb code to call SetInitSize() since it was using Move() which did not set initSize

ecere/src/gui/controls/Button.ec
ecere/src/gui/controls/ScrollBar.ec

index 56d5862..dd871c7 100644 (file)
@@ -676,11 +676,16 @@ public class Button : CommonControl
 
    bool OnResizing(int *width, int *height)
    {
+      // Checking *width/*height for zero does not work with minClientSize being set
+      Size initSize = this.initSize;
+      if(this.anchor.left.type != none && this.anchor.right.type != none) initSize.w = 1;
+      if(this.anchor.top.type != none && this.anchor.bottom.type != none) initSize.h = 1;
+
       if(buttonStyle.checkBox || buttonStyle.radio || buttonStyle.bevelOver)
       {
          Bitmap bitmap0 = bitmaps[0] ? bitmaps[0].bitmap : null;
-         if(!*width && bitmap0) *width = bitmap0.width;
-         if(!*height && bitmap0) *height = bitmap0.height;
+         if(!initSize.w /**width*/ && bitmap0) *width = Max(*width, bitmap0.width);
+         if(!initSize.h /**height*/ && bitmap0) *height = Max(*height, bitmap0.height);
 
          *height = Max(*height, captionHeight + 2);
          if(text)
@@ -701,23 +706,23 @@ public class Button : CommonControl
       {
          if(!caption && bitmap && bitmap.bitmap)
          {
-            if(!*width)
-               *width = bitmap.bitmap.width;
-            if(!*height)
-               *height = bitmap.bitmap.height;
+            if(!initSize.w /**width*/)
+               *width = Max(*width, bitmap.bitmap.width);
+            if(!initSize.h /**height*/)
+               *height = Max(*height, bitmap.bitmap.height);
          }
          else if(guiApp.textMode && buttonStyle.bevel)
          {
-            if(!*width)
+            if(!initSize.w /**width*/)
                *width = Max(*width, captionWidth + 8);
-            if(!*height)
+            if(!initSize.h /**height*/)
                *height = Max(*height, captionHeight + 16);
          }
          else
          {
-            if(!*width)
+            if(!initSize.w /**width*/)
                *width = Max(*width, captionWidth + /*4*/12);
-            if(!*height)
+            if(!initSize.h /**height*/)
                *height = Max(*height, captionHeight + /*6*/ 8);
          }
       }
index 4c897b0..66cfd71 100644 (file)
@@ -384,6 +384,7 @@ private:
                SNAPUP(thumbPos, textCellH);
             }
 
+            thumb.SetInitSize({ size.w,thumbSize });
             thumb.Move(0,thumbPos, size.w,thumbSize);
          }
          else
@@ -399,6 +400,7 @@ private:
                SNAPUP(thumbPos, textCellW);
             }
 
+            thumb.SetInitSize({ thumbSize, size.h });
             thumb.Move(thumbPos, 0, thumbSize, size.h);
          }
       }
@@ -431,6 +433,7 @@ private:
          upBtn.size.h = SB_HEIGHT;
          upBtn.anchor = Anchor { left = 0, right = 0, top = 0 };
 
+         thumb.SetInitSize({ Max(clientSize.w, sbWidth), thumbSize });
          thumb.Move(0,0, Max(clientSize.w, sbWidth), thumbSize);
       }
       else
@@ -441,6 +444,7 @@ private:
          upBtn.size.w = SB_HEIGHT;
          upBtn.anchor = Anchor { left = 0, top = 0, bottom = 0 };
 
+         thumb.SetInitSize({ thumbSize, Max(clientSize.h, SB_HEIGHT) });
          thumb.Move(0,0, thumbSize, Max(clientSize.h, SB_HEIGHT));
       }