Browse Source

enable text-auto-resize for width

Eduardo Bart 9 years ago
parent
commit
1d2f6c7e9f

+ 1
- 0
modules/client_background/background.otui View File

@@ -18,5 +18,6 @@ Panel
18 18
     text-align: center
19 19
     text-auto-resize: true
20 20
     width: 120
21
+    padding: 2
21 22
     color: #ffffff
22 23
     font: verdana-11px-monochrome

+ 2
- 2
src/framework/ui/uiwidget.cpp View File

@@ -1318,8 +1318,6 @@ void UIWidget::onStyleApply(const std::string& styleName, const OTMLNodePtr& sty
1318 1318
 
1319 1319
 void UIWidget::onGeometryChange(const Rect& oldRect, const Rect& newRect)
1320 1320
 {
1321
-    callLuaField("onGeometryChange", oldRect, newRect);
1322
-
1323 1321
     if(m_textWrap && oldRect.size() != newRect.size())
1324 1322
         updateText();
1325 1323
 
@@ -1328,6 +1326,8 @@ void UIWidget::onGeometryChange(const Rect& oldRect, const Rect& newRect)
1328 1326
         if(!child->isAnchored())
1329 1327
             child->bindRectToParent();
1330 1328
     }
1329
+
1330
+    callLuaField("onGeometryChange", oldRect, newRect);
1331 1331
 }
1332 1332
 
1333 1333
 void UIWidget::onLayoutUpdate()

+ 7
- 13
src/framework/ui/uiwidgettext.cpp View File

@@ -41,20 +41,14 @@ void UIWidget::updateText()
41 41
         m_drawText = m_text;
42 42
 
43 43
     // update rect size
44
-    if(!m_rect.isValid()) {
45
-        Size textSize = getTextSize();
46
-        Size newSize = getSize();
47
-        if(newSize.width() <= 0)
48
-            newSize.setWidth(textSize.width());
49
-        if(newSize.height() <= 0)
50
-            newSize.setHeight(textSize.height());
51
-        setSize(newSize);
52
-    } else if(m_textAutoResize) {
53
-        Size textSize = getTextSize();
44
+    if(!m_rect.isValid() || m_textAutoResize) {
45
+        Size textBoxSize = getTextSize();
46
+        textBoxSize += Size(m_padding.left + m_padding.right, m_padding.top + m_padding.left);
54 47
         Size size = getSize();
55
-        if(textSize.width() > size.width())
56
-            size.setWidth(textSize.width());
57
-        size.setHeight(textSize.height());
48
+        if(size.width() <= 0 || (m_textAutoResize && !m_textWrap))
49
+            size.setWidth(textBoxSize.width());
50
+        if(size.height() <= 0 || m_textAutoResize)
51
+            size.setHeight(textBoxSize.height());
58 52
         setSize(size);
59 53
     }
60 54
 

Loading…
Cancel
Save