[haiku-commits] r35418 - in haiku/trunk: headers/os/interface src/kits/interface

  • From: superstippi@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 6 Feb 2010 10:48:37 +0100 (CET)

Author: stippi
Date: 2010-02-06 10:48:37 +0100 (Sat, 06 Feb 2010)
New Revision: 35418
Changeset: http://dev.haiku-os.org/changeset/35418/haiku

Modified:
   haiku/trunk/headers/os/interface/StatusBar.h
   haiku/trunk/src/kits/interface/StatusBar.cpp
Log:
* Make a BStatusBar comfortable to use without any text labels.
* In SetBarHeight(), use InvalidateLayout() when used with layout management.


Modified: haiku/trunk/headers/os/interface/StatusBar.h
===================================================================
--- haiku/trunk/headers/os/interface/StatusBar.h        2010-02-06 02:48:19 UTC 
(rev 35417)
+++ haiku/trunk/headers/os/interface/StatusBar.h        2010-02-06 09:48:37 UTC 
(rev 35418)
@@ -98,6 +98,7 @@
                        BRect                           _BarFrame(const 
font_height* fontHeight
                                                                        = NULL) 
const;
                        float                           _BarPosition(const 
BRect& barFrame) const;
+                       bool                            _HasText() const;
 
                        BString                         fLabel;
                        BString                         fTrailingLabel;

Modified: haiku/trunk/src/kits/interface/StatusBar.cpp
===================================================================
--- haiku/trunk/src/kits/interface/StatusBar.cpp        2010-02-06 02:48:19 UTC 
(rev 35417)
+++ haiku/trunk/src/kits/interface/StatusBar.cpp        2010-02-06 09:48:37 UTC 
(rev 35418)
@@ -207,11 +207,14 @@
        }
 
        if (_height) {
-               font_height fontHeight;
-               GetFontHeight(&fontHeight);
+               float labelHeight = 0;
+               if (_HasText()) {
+                       font_height fontHeight;
+                       GetFontHeight(&fontHeight);
+                       labelHeight = ceilf(fontHeight.ascent + 
fontHeight.descent) + 6;
+               }
 
-               *_height = ceilf(fontHeight.ascent + fontHeight.descent) + 6
-                       + BarHeight();
+               *_height = labelHeight + BarHeight();
        }
 }
 
@@ -475,9 +478,13 @@
                return;
 
        // resize so that the height fits
-       float width, height;
-       GetPreferredSize(&width, &height);
-       ResizeTo(Bounds().Width(), height);
+       if ((Flags() & B_SUPPORTS_LAYOUT) != 0) {
+               InvalidateLayout();
+       } else {
+               float width, height;
+               GetPreferredSize(&width, &height);
+               ResizeTo(Bounds().Width(), height);
+       }
 }
 
 
@@ -813,13 +820,15 @@
 BRect
 BStatusBar::_BarFrame(const font_height* fontHeight) const
 {
-       float top;
-       if (fontHeight == NULL) {
-               font_height height;
-               GetFontHeight(&height);
-               top = ceilf(height.ascent + height.descent) + 6;
-       } else
-               top = ceilf(fontHeight->ascent + fontHeight->descent) + 6;
+       float top = 2;
+       if (_HasText()) {
+               if (fontHeight == NULL) {
+                       font_height height;
+                       GetFontHeight(&height);
+                       top = ceilf(height.ascent + height.descent) + 6;
+               } else
+                       top = ceilf(fontHeight->ascent + fontHeight->descent) + 
6;
+       }
 
        return BRect(2, top, Bounds().right - 2, top + BarHeight() - 4);
 }
@@ -835,3 +844,10 @@
                + (fCurrent * (barFrame.Width() + 3) / fMax));
 }
 
+
+bool
+BStatusBar::_HasText() const
+{
+       return fLabel.Length() > 0 || fTrailingLabel.Length() > 0
+               || fTrailingText.Length() > 0 || fText.Length() > 0;
+}


Other related posts:

  • » [haiku-commits] r35418 - in haiku/trunk: headers/os/interface src/kits/interface - superstippi