Repository: kivy/kivy

Issue:
TextInput hint_text disappears after window resize on Windows
If we set the hint_text property again after window resize the text will reappear, but doing the same after the second window resize will have no effect, the property will be changed but the text will not be displayed. The bug was observed on Windows 8, needs testing on Windows 7/XP.



Discussion:
After further testing I have observed that the bug will appear only when 'size_hint: None, None' for the TextInput or for any of its parent widgets in the same tree, reproducible in the portable kivy 1.7.2 package and the current master too, here is an example code:

```
# The bug will appear only when 'size_hint: None, None' for the TextInput
# or for any of its parent widgets in the same tree.

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout

Builder.load_string("""
<Test>:
    BoxLayout:
        size_hint: None, None
        TextInput:
            hint_text: 'HINT'
            #size_hint: None, None
""")


class Test(BoxLayout):
    pass


class TestApp(App):
    def build(self):
        return Test()


if __name__ == '__main__':
    TestApp().run()
```

This happen for me even if only size_hint_x is None, but size_hint_y is still 1, on win7.


Resolving patch:
diff --git a/kivy/uix/codeinput.py b/kivy/uix/codeinput.py
--- a/kivy/uix/codeinput.py
+++ b/kivy/uix/codeinput.py
@@ -94,7 +94,7 @@ def _create_line_label(self, text, hint=False):
         cid = '%s\0%s' % (ntext, str(kw))
         texture = Cache_get('textinput.label', cid)
 
-        if not texture:
+        if texture is None:
             # FIXME right now, we can't render very long line...
             # if we move on "VBO" version as fallback, we won't need to
             # do this.
@@ -104,10 +104,7 @@ def _create_line_label(self, text, hint=False):
                 label.text = u''
             else:
                 label.text = ntext
-            try:
-                label.refresh()
-            except ValueError:
-                return
+            label.refresh()
 
             # ok, we found it.
             texture = label.texture
@@ -129,7 +126,7 @@ def _get_text_width(self, text, tab_width, _label_cached):
         if width:
             return width
         lbl = self._create_line_label(text)
-        width = lbl.width if lbl else 0
+        width = lbl.width
         Cache_append(
             'textinput.width',
             text + u'_' + repr(self._get_line_options()), width)
diff --git a/kivy/uix/textinput.py b/kivy/uix/textinput.py
--- a/kivy/uix/textinput.py
+++ b/kivy/uix/textinput.py
@@ -201,6 +201,7 @@ def _textinput_clear_cache(*l):
                 _textinput_list.remove(wr)
             else:
                 textinput._trigger_refresh_text()
+                textinput._refresh_hint_text()
 
     from kivy.graphics.context import get_context
     get_context().add_reload_observer(_textinput_clear_cache, True)
@@ -1507,9 +1508,7 @@ def _refresh_text(self, text, *largs):
         for x in _lines:
             lbl = _create_label(x)
             _lines_labels.append(lbl)
-            _line_rects.append(
-                Rectangle(size=(lbl.size if lbl else (0, 0))))
-            lbl = None
+            _line_rects.append(Rectangle(size=lbl.size))
 
         if mode == 'all':
             self._lines_labels = _lines_labels
@@ -1529,13 +1528,9 @@ def _refresh_text(self, text, *largs):
                 len_lines, _lines_flags, _lines, _lines_labels,
                 _line_rects)
 
-        line_label = _lines_labels[0]
         min_line_ht = self._label_cached.get_extents('_')[1]
-        if line_label is None:
-            self.line_height = max(1, min_line_ht)
-        else:
-            # with markup texture can be of height `1`
-            self.line_height = max(line_label.height, min_line_ht)
+        # with markup texture can be of height `1`
+        self.line_height = max(_lines_labels[0].height, min_line_ht)
         #self.line_spacing = 2
         # now, if the text change, maybe the cursor is not at the same place as
         # before. so, try to set the cursor on the good place
@@ -1627,9 +1622,6 @@ def _update_graphics(self, *largs):
         for line_num, value in enumerate(lines):
             if miny <= y <= maxy + dy:
                 texture = labels[line_num]
-                if not texture:
-                    y -= dy
-                    continue
                 size = list(texture.size)
                 texc = texture.tex_coords[:]
 
@@ -1814,7 +1806,7 @@ def _create_line_label(self, text, hint=False):
         cid = '%s\0%s' % (ntext, str(kw))
         texture = Cache_get('textinput.label', cid)
 
-        if not texture:
+        if texture is None:
             # FIXME right now, we can't render very long line...
             # if we move on "VBO" version as fallback, we won't need to
             # do this.  try to found the maximum text we can handle
@@ -2038,9 +2030,7 @@ def _refresh_hint_text(self):
         for x in _lines:
             lbl = _create_label(x, hint=True)
             _hint_text_labels.append(lbl)
-            _hint_text_rects.append(
-                Rectangle(size=(lbl.size if lbl else (0, 0))))
-            lbl = None
+            _hint_text_rects.append(Rectangle(size=lbl.size))
 
         self._hint_text_lines = _lines
         self._hint_text_labels = _hint_text_labels


Test patch: