[core/theme] Fix padding

Missing prefix/suffix broke padding.

see #23
This commit is contained in:
Tobi-wan Kenobi 2016-12-09 13:06:08 +01:00
parent c1f1e1a939
commit 88b36417f8
3 changed files with 19 additions and 11 deletions

View file

@ -42,8 +42,9 @@ class I3BarOutput(object):
def draw(self, widget, engine=None): def draw(self, widget, engine=None):
"""Draw a single widget""" """Draw a single widget"""
full_text = widget.full_text() full_text = widget.full_text()
prefix = self._theme.prefix(widget) padding = self._theme.padding(widget)
suffix = self._theme.suffix(widget) prefix = self._theme.prefix(widget, padding)
suffix = self._theme.suffix(widget, padding)
if prefix: if prefix:
full_text = u"{}{}".format(prefix, full_text) full_text = u"{}{}".format(prefix, full_text)
if suffix: if suffix:

View file

@ -38,17 +38,21 @@ class Theme(object):
self._widget = None self._widget = None
self._prevbg = None self._prevbg = None
def prefix(self, widget): def padding(self, widget):
"""Return the theme prefix for a widget's full text""" """Return padding for widget"""
padding = self._get(widget, "padding", "") return self._get(widget, "padding", "")
pre = self._get(widget, "prefix", None)
return u"{}{}{}".format(padding, pre, padding) if pre else None
def suffix(self, widget): def prefix(self, widget, default=None):
"""Return the theme prefix for a widget's full text"""
padding = self.padding(widget)
pre = self._get(widget, "prefix", None)
return u"{}{}{}".format(padding, pre, padding) if pre else default
def suffix(self, widget, default=None):
"""Return the theme suffix for a widget's full text""" """Return the theme suffix for a widget's full text"""
padding = self._get(widget, "padding", "") padding = self._get(widget, "padding", "")
suf = self._get(widget, "suffix", None) suf = self._get(widget, "suffix", None)
return u"{}{}{}".format(padding, suf, padding) if suf else None return u"{}{}{}".format(padding, suf, padding) if suf else default
def fg(self, widget): def fg(self, widget):
"""Return the foreground color for this widget""" """Return the foreground color for this widget"""

View file

@ -48,6 +48,9 @@ class MockTheme(object):
self.attr_separator = None self.attr_separator = None
self.attr_separator_block_width = 0 self.attr_separator_block_width = 0
def padding(self, widget):
return ""
def reset(self): def reset(self):
pass pass
@ -57,10 +60,10 @@ class MockTheme(object):
def separator(self, widget): def separator(self, widget):
return self.attr_separator return self.attr_separator
def prefix(self, widget): def prefix(self, widget, default=None):
return self.attr_prefix return self.attr_prefix
def suffix(self, widget): def suffix(self, widget, default=None):
return self.attr_suffix return self.attr_suffix
def fg(self, widget): def fg(self, widget):