Skip to content

Commit

Permalink
- make possible to get max text width among the items of Listbox base…
Browse files Browse the repository at this point in the history
…d lists (an provide it in python)
  • Loading branch information
DimitarCC authored and Huevos committed Oct 11, 2023
1 parent 1cbbce3 commit a99b67a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/gui/elistbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class iListboxContent: public iObject
virtual int getItemHeight()=0;
virtual int getItemWidth() { return -1; }
virtual int getOrientation() { return 1; }
virtual int getMaxItemTextWidth() { return 1; }

eListbox *m_listbox;
#endif
Expand Down Expand Up @@ -184,6 +185,7 @@ class eListbox: public eWidget

int getScrollbarWidth() { return m_scrollbar_width; }
int getScrollbarHeight() { return m_scrollbar_height; }
int getMaxItemTextWidth() { return m_content->getMaxItemTextWidth(); }

#ifndef SWIG
struct eListboxStyle *getLocalStyle(void);
Expand Down
12 changes: 11 additions & 1 deletion lib/gui/elistboxcontent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int iListboxContent::currentCursorSelectable()
DEFINE_REF(eListboxPythonStringContent);

eListboxPythonStringContent::eListboxPythonStringContent()
:m_cursor(0), m_saved_cursor(0), m_itemheight(25), m_itemwidth(25), m_orientation(1)
:m_cursor(0), m_saved_cursor(0), m_itemheight(25), m_itemwidth(25), m_max_text_width(0), m_orientation(1)
{
}

Expand Down Expand Up @@ -275,6 +275,16 @@ void eListboxPythonStringContent::paint(gPainter &painter, eWindowStyle &style,
flags |= gPainter::RT_HALIGN_BLOCK;
}

eRect textRect = eRect(text_offset, m_itemsize);

ePtr<eTextPara> para = new eTextPara(textRect);
para->setFont(fnt);
para->renderString(string);
int textWidth = para->getBoundBox().width();
if (textWidth > m_max_text_width) {
m_max_text_width = textWidth;
}

painter.renderText(eRect(text_offset, m_itemsize),
string, flags, border_color, border_size);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/gui/elistboxcontent.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class eListboxPythonStringContent: public virtual iListboxContent
void invalidateEntry(int index);
void invalidate();
eSize getItemSize() { return m_itemsize; }
int getMaxItemTextWidth() { return m_max_text_width; }
#ifndef SWIG
protected:
void cursorHome();
Expand Down Expand Up @@ -53,6 +54,7 @@ class eListboxPythonStringContent: public virtual iListboxContent
ePtr<gFont> m_font;
int m_itemheight;
int m_itemwidth;
int m_max_text_width;
int m_orientation;
#endif
};
Expand Down
3 changes: 3 additions & 0 deletions lib/python/Screens/MessageBox.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,6 @@ def move(self, direction):

def __repr__(self):
return "%s(%s)" % (str(type(self)), self.text)

def getListWidth(self):
return self["list"].instance.getMaxItemTextWidth()

0 comments on commit a99b67a

Please sign in to comment.