kopia lustrzana https://github.com/peterhinch/micropython-micro-gui
Label widget: dynamic justify option.
rodzic
9dd7368244
commit
a248c4277b
|
@ -1009,7 +1009,9 @@ Method:
|
||||||
* `bgcolor=None` Background color, as per foreground.
|
* `bgcolor=None` Background color, as per foreground.
|
||||||
* `bdcolor=None` Border color. As per above except that if `False` is
|
* `bdcolor=None` Border color. As per above except that if `False` is
|
||||||
passed, no border is displayed. This clears a previously drawn border.
|
passed, no border is displayed. This clears a previously drawn border.
|
||||||
Returns the current text string.
|
Returns the current text string.
|
||||||
|
* `justify=None` By default justify using the constructor default. Override
|
||||||
|
with `Label.LEFT`, `Label.RIGHT` or `Label.CENTRE`.
|
||||||
|
|
||||||
If the `value` method is called with a text string too long for the `Label` the
|
If the `value` method is called with a text string too long for the `Label` the
|
||||||
text will be clipped to fit the width. In this case `value()` will return the
|
text will be clipped to fit the width. In this case `value()` will return the
|
||||||
|
|
|
@ -27,8 +27,10 @@ class Label(Widget):
|
||||||
if text is not None:
|
if text is not None:
|
||||||
self.value(text, invert)
|
self.value(text, invert)
|
||||||
|
|
||||||
def value(self, text=None, invert=False, fgcolor=None, bgcolor=None, bdcolor=None):
|
def value(self, text=None, invert=False, fgcolor=None, bgcolor=None, bdcolor=None, justify=None):
|
||||||
sl = self.writer.stringlen(text)
|
sl = self.writer.stringlen(text)
|
||||||
|
if justify is None:
|
||||||
|
justify = self.justify
|
||||||
self.tcol = self.col # Default is left justify
|
self.tcol = self.col # Default is left justify
|
||||||
if sl > self.width: # Clip
|
if sl > self.width: # Clip
|
||||||
font = self.writer.font
|
font = self.writer.font
|
||||||
|
@ -40,9 +42,9 @@ class Label(Widget):
|
||||||
break
|
break
|
||||||
n += 1
|
n += 1
|
||||||
text = text[: n]
|
text = text[: n]
|
||||||
elif self.justify == 1:
|
elif justify == 1: # Centre
|
||||||
self.tcol = self.col + (self.width - sl) // 2
|
self.tcol = self.col + (self.width - sl) // 2
|
||||||
elif self.justify == 2:
|
elif justify == 2: # Right
|
||||||
self.tcol = self.col + self.width - sl
|
self.tcol = self.col + self.width - sl
|
||||||
|
|
||||||
txt = super().value(text) # Sets .draw ensuring refresh
|
txt = super().value(text) # Sets .draw ensuring refresh
|
||||||
|
|
Ładowanie…
Reference in New Issue