Skip to content

Commit

Permalink
Fix a weird length calculation issue on textboxes
Browse files Browse the repository at this point in the history
I thought it was smart to only assign the text to the layout when it's
drawn (see https://github.com/qtile/qtile/pull/1367/files#r300469727),
but it seems that it's used for the calculation of the widget's length
beforehand and result in buggy behaviors that way (either there is a delay
before the widget is drawn at the proper size, or it is just drawn with a wrong
length and stays that way). So let's revert to a property setter method; plus
it will give a better output for info().
  • Loading branch information
ramnes committed Jul 20, 2019
1 parent b4eeba0 commit 77b47b0
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions libqtile/widget/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,19 @@ class _TextBox(_Widget):
def __init__(self, text=" ", width=bar.CALCULATED, **config):
self.layout = None
_Widget.__init__(self, width, **config)
self.text = text
self._text = text
self.add_defaults(_TextBox.defaults)

@property
def text(self):
return self.fmt.format(self._text)

@text.setter
def text(self, value):
self._text = value
if self.layout:
self.layout.text = self.text

@property
def foreground(self):
return self._foreground
Expand Down Expand Up @@ -353,7 +363,7 @@ def _configure(self, qtile, bar):
)

def calculate_length(self):
if self.text:
if self._text:
return min(
self.layout.width,
self.bar.width
Expand All @@ -366,7 +376,6 @@ def draw(self):
if self.offsetx is None:
return
self.drawer.clear(self.background or self.bar.background)
self.layout.text = self.fmt.format(self.text)
self.layout.draw(
self.actual_padding or 0,
int(self.bar.height / 2.0 - self.layout.height / 2.0) + 1
Expand Down

0 comments on commit 77b47b0

Please sign in to comment.