]> Dogcows Code - chaz/openbox/blobdiff - src/labelwidget.cc
draw only when needed
[chaz/openbox] / src / labelwidget.cc
index 491deadccdf75120f0c938b664acb3b7f4e1d94a..f00f738b71d14eab909c01a5dd656f6c62a805d3 100644 (file)
@@ -72,38 +72,42 @@ void OBLabelWidget::unfocus()
 
 void OBLabelWidget::update()
 {
-  OtkWidget::update();
+  bool draw = _dirty;
 
-  std::string t = _text;
-  int x = _sidemargin;    // x coord for the text
+  OtkWidget::update();
 
-  // find a string that will fit inside the area for text
-  int max_length = width() - _sidemargin * 2;
-  if (max_length <= 0) {
-    t = ""; // can't fit anything
-  } else {
-    size_t text_len = t.size();
-    int length;
+  if (draw) {
+    std::string t = _text;
+    int x = _sidemargin;    // x coord for the text
+
+    // find a string that will fit inside the area for text
+    int max_length = width() - _sidemargin * 2;
+    if (max_length <= 0) {
+      t = ""; // can't fit anything
+    } else {
+      size_t text_len = t.size();
+      int length;
       
-    do {
-      t.resize(text_len);
-      length = _font->measureString(t);
-    } while (length > max_length && text_len-- > 0);
-
-    // justify the text
-    switch (_justify) {
-    case otk::Style::RightJustify:
-      x += max_length - length;
-      break;
-    case otk::Style::CenterJustify:
-      x += (max_length - length) / 2;
-      break;
-    case otk::Style::LeftJustify:
-      break;
+      do {
+        t.resize(text_len);
+        length = _font->measureString(t);
+      } while (length > max_length && text_len-- > 0);
+
+      // justify the text
+      switch (_justify) {
+      case otk::Style::RightJustify:
+        x += max_length - length;
+        break;
+      case otk::Style::CenterJustify:
+        x += (max_length - length) / 2;
+        break;
+      case otk::Style::LeftJustify:
+        break;
+      }
     }
-  }
 
-  _font->drawString(_xftdraw, x, 0, *_text_color, t);
+    _font->drawString(_xftdraw, x, 0, *_text_color, t);
+  }
 }
 
 
This page took 0.024825 seconds and 4 git commands to generate.