diff --git a/kivy/core/text/markup.py b/kivy/core/text/markup.py index fabdc922d..3e9cc2199 100644 --- a/kivy/core/text/markup.py +++ b/kivy/core/text/markup.py @@ -38,7 +38,7 @@ If you need to escape the markup from the current text, use __all__ = ('MarkupLabel', ) from kivy.graphics.texture import Texture -from kivy.utils import platform +from kivy.properties import dpi2px from kivy.parser import parse_color from kivy.logger import Logger import re @@ -138,9 +138,14 @@ class MarkupLabel(MarkupLabelBase): spop('italic') self.resolve_font_name() elif item[:6] == '[size=': + item = item[6:-1] try: - size = int(item[6:-1]) + if item[-2:] in ('px', 'pt', 'in', 'cm', 'mm'): + size = dpi2px(item[:-2], item[-2:]) + else: + size = int(item) except ValueError: + raise size = options['font_size'] spush('font_size') options['font_size'] = size diff --git a/kivy/data/style.kv b/kivy/data/style.kv index 2d4d773b4..4364aa9d8 100644 --- a/kivy/data/style.kv +++ b/kivy/data/style.kv @@ -499,7 +499,8 @@ size: self.width, 1 : - size_hint_x: .25 + size_hint: .25, None + height: max(50, labellayout.height) content: content canvas: Color: @@ -516,25 +517,13 @@ BoxLayout: pos: root.pos - FloatLayout: + Label: + size_hint: .5, None id: labellayout - orientation: 'vertical' - size_hint_x: .5 - - Label: - pos_hint: {'y': .5, 'x': 0} - text: root.title - text_size: self.width - 32, None - size_hint_y: None - height: self.texture_size[1] - Label: - pos_hint: {'top': .5, 'x': 0} - text: root.desc if root.desc else '' - text_size: self.width - 32, None - size_hint_y: None - height: self.texture_size[1] - font_size: 10 - color: (.7, .7, .7, 1) if root.selected_alpha < 0.5 else (.3, .3, .3, 1) + markup: True + text: '{0}\n[size=10pt]{1}[/size]{2}'.format(root.title or '', root.desc or '', self.height) + text_size: self.width - 32, None + height: self.texture_size[1] + 10 BoxLayout: id: content @@ -565,6 +554,8 @@ : text_size: self.width - 32, None + size_hint_y: None + height: max(50, self.texture_size[1] + 20) color: (.9, .9, .9, 1) canvas: Color: @@ -592,14 +583,16 @@ : spacing: 5 padding: 5 - row_default_height: 48 - row_force_default: True + #row_default_height: 48 + #row_force_default: True size_hint_y: None height: self.minimum_height Label: + size_hint_y: None text: root.title text_size: self.width - 32, None + height: max(50, self.texture_size[1] + 20) color: (.5, .5, .5, 1) canvas.after: @@ -766,7 +759,7 @@ do_translation: False do_rotation: False do_scale: False - auto_bring_to_front: False + auto_bring_to_front: False # ============================================================================= @@ -774,16 +767,16 @@ # ============================================================================= : - canvas.before: - StencilPush - Rectangle: - pos: self.pos - size: self.size - StencilUse - canvas.after: - StencilUnUse - Rectangle: - pos: self.pos - size: self.size - StencilPop + canvas.before: + StencilPush + Rectangle: + pos: self.pos + size: self.size + StencilUse + canvas.after: + StencilUnUse + Rectangle: + pos: self.pos + size: self.size + StencilPop diff --git a/kivy/properties.pyx b/kivy/properties.pyx index 43df1ab5b..bc36916b8 100644 --- a/kivy/properties.pyx +++ b/kivy/properties.pyx @@ -175,6 +175,24 @@ from weakref import ref EventLoop = None +cpdef float dpi2px(value, ext): + # 1in = 2.54cm = 25.4mm = 72pt = 12pc + global EventLoop + if EventLoop is None: + from kivy.base import EventLoop + cdef float rv = float(value) + cdef float dpi = EventLoop.dpi + if ext == 'in': + return rv * dpi + elif ext == 'px': + return rv + elif ext == 'pt': + return rv * dpi / 72. + elif ext == 'cm': + return rv * dpi / 2.54 + elif ext == 'mm': + return rv * dpi / 25.4 + cdef class Property: '''Base class for building more complex properties. @@ -439,23 +457,8 @@ cdef class NumericProperty(Property): return self.parse_list(obj, value[:-2], value[-2:]) cdef float parse_list(self, EventDispatcher obj, value, str ext): - # 1in = 2.54cm = 25.4mm = 72pt = 12pc - global EventLoop - if EventLoop is None: - from kivy.base import EventLoop - cdef float rv = float(value) - cdef float dpi = EventLoop.dpi obj.__storage[self.name]['format'] = ext - if ext == 'in': - return rv * dpi - elif ext == 'px': - return rv - elif ext == 'pt': - return rv * dpi / 72. - elif ext == 'cm': - return rv * dpi / 2.54 - elif ext == 'mm': - return rv * dpi / 25.4 + return dpi2px(value, ext) def get_format(self, EventDispatcher obj): '''