Align text inside ListBox

Started by guatto, 23 January 2022, 11:59:51

guatto

Hi, i'm new in this forum and also new to TGUI, as the title suggests, i'm looking for a way to align my text inside the `ListBox`, as an example, with `Label` we can find :


    auto label = tgui::Label::create("Test");
    label->setHorizontalAlignment(tgui::Label::HorizontalAlignment::Center);
    label->setVerticalAlignment(tgui::Label::VerticalAlignment::Center);


Is there any function or hack to replicate this behavior with the ListBox's ?

texus

It's currently not possible, but it doesn't seem that difficult to implement.
Text is always centered vertically and I can't think of a case where it shouldn't be. For horizontal alignment I can understand that you might want it centered instead of left aligned. So I'll try to have a look later today if I can add a setTextAlignment function for that.

texus

Actually you can already do it, but you have to use ListView instead of ListBox.

You can do something like this to emulate the list box and center the text:
Code (cpp) Select
listView->addColumn("", 0, tgui::ColumnAlignment::Center);
listView->setHeaderVisible(false);
listView->setExpandLastColumn(true);
listView->setHorizontalScrollbarPolicy(tgui::Scrollbar::Policy::Never);

guatto

It works like a charm. Thank you sir !