Skip to content

Commit

Permalink
Use getMaxItemTextWidth method in ChoiceBox autoResize
Browse files Browse the repository at this point in the history
Therefore remove the label autoresize, which was previously used to calculate the width of the text.
  • Loading branch information
Taapat committed Oct 21, 2023
1 parent 9e3b83f commit 5d1efba
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions lib/python/Screens/ChoiceBox.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def __init__(self, session, title="", list=[], keys=None, selection=0, skin_name
self.skinName = skin_name + ["ChoiceBox"]

self.reorder_config = reorderConfig
self["autoresize"] = Label("") # do not remove, used for autoResize()
self["description"] = Label()
self["text"] = Label(title)
self.list = []
Expand Down Expand Up @@ -99,12 +98,6 @@ def autoResize(self):
def x_offset():
return max([line[1][1] for line in self.list])

def x_width(textsize):
def getListLineTextWidth(text):
self["autoresize"].text = text
return self["autoresize"].instance.calculateSize().width()
return max(max([getListLineTextWidth(line[0][0]) for line in self.list]), textsize)

def getMaxDescriptionHeight():
def getDescrLineHeight(text):
if len(text) > 2 and isinstance(text[2], str):
Expand All @@ -117,7 +110,7 @@ def getDescrLineHeight(text):
count = len(self.list)
count, scrollbar = (10, self["list"].instance.getScrollbarWidth() + 5) if count > 10 else (count, 0)
offset = self["list"].l.getItemSize().height() * count
wsizex = x_width(textsize[0]) + x_offset() + 10 + scrollbar
wsizex = max(textsize[0], self["list"].instance.getMaxItemTextWidth()) + x_offset() + 10 + scrollbar
# precount description size
descry = self["description"].instance.calculateSize().width()
self["description"].resize(wsizex - 20, descry if descry > 0 else 0)
Expand Down

0 comments on commit 5d1efba

Please sign in to comment.