Merge pull request #463 from tobyp/scrollable-auto-size

Support disabling scrollable by setting width=-1 on the module
This commit is contained in:
tobi-wan-kenobi 2019-11-12 13:40:58 +01:00 committed by GitHub
commit 00e3ba9e2d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,14 +12,17 @@ import bumblebee.util
def scrollable(func): def scrollable(func):
def wrapper(module, widget): def wrapper(module, widget):
text = func(module, widget) text = func(module, widget)
if not text: return text if not text:
width = widget.get("theme.width", module.parameter("width", 30)) return text
width = widget.get("theme.width", int(module.parameter("width", 30)))
if bumblebee.util.asbool(module.parameter("scrolling.makewide", "true")): if bumblebee.util.asbool(module.parameter("scrolling.makewide", "true")):
widget.set("theme.minwidth", "A"*width) widget.set("theme.minwidth", "A"*width)
if width < 0:
return text
if len(text) <= width: if len(text) <= width:
return text return text
# we need to shorten # we need to shorten
try: try:
bounce = int(module.parameter("scrolling.bounce", 1)) bounce = int(module.parameter("scrolling.bounce", 1))
except ValueError: except ValueError:
@ -31,7 +34,7 @@ def scrollable(func):
start = widget.get("scrolling.start", -1) start = widget.get("scrolling.start", -1)
direction = widget.get("scrolling.direction", "right") direction = widget.get("scrolling.direction", "right")
start += scroll_speed if direction == "right" else -(scroll_speed) start += scroll_speed if direction == "right" else -(scroll_speed)
if width + start > len(text) + (scroll_speed -1): if width + start > len(text) + (scroll_speed -1):
if bounce: if bounce:
widget.set("scrolling.direction", "left") widget.set("scrolling.direction", "left")