Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - Nafffen

#21
Hello,
I have a custom Widget:
class ItemContainerWidget : public tgui::WidgetI want to have this widget auto resize one of its edge when the user call setSize.
For example:
auto itemContainerW = ItemContainerWidget::create(ItemContainerWidget::AlignmentSide::VERTICAL, 2, m_listItemStack);
itemContainerW->setSize(800, tgui::bindHeight(m_scrollPanel)-m_scrollPanel->getScrollbarWidth());
800 here is no relevant as I want the x size to be auto detect in setSize method of ItemContainerWidget

That's the beginning of the method
void ItemContainerWidget::setSize(const tgui::Layout2d& size){

    cout << "before" << endl;
    cout << "size.getValue(): " << size.getValue() << endl;

    if(m_alignmentSide == AlignmentSide::HORIZONTAL){
        m_sizeItemRect = size.getValue().x/m_nbItemPerAlignmentSide;
    }else if(m_alignmentSide == AlignmentSide::VERTICAL){
        m_sizeItemRect = size.getValue().y/m_nbItemPerAlignmentSide;
    }
    cout << "m_sizeItemRect: " << m_sizeItemRect << endl;

    unsigned nbItemPerNonAlignmentSide = std::ceil(m_listIS.size()/(float)m_nbItemPerAlignmentSide);
    cout << "nbItemPerNonAlignmentSide: " << nbItemPerNonAlignmentSide << endl;

    //update size accordingly to m_nbItemPerAlignmentSide
    tgui::Layout2d newSize = size;
    if(m_alignmentSide == AlignmentSide::HORIZONTAL){
        newSize.y = nbItemPerNonAlignmentSide*m_sizeItemRect;
    }else if(m_alignmentSide == AlignmentSide::VERTICAL){
        newSize.x = nbItemPerNonAlignmentSide*m_sizeItemRect;
    }
    cout << "newSize: " << newSize.toString() << endl;
    Widget::setSize(newSize);

    .... change pos and size of some stuff ....

So it's seems to be ok, but my application crashes sometimes when I resize window, sometimes the behavior is what I expect it to be.
Even my VScode debug mode can't find the function that's crashing.
I didn't find any crash pattern, it seems to be totally random for me.

In the above example, I want the height of itemContainerW  to be proportional to another widget's height, so I use bindHeight, and the width auto set by setSide.
Then setSide just change the size according to AlignementSide variable before send it to parent Widget.

Did I miss somehting with this layout utilisation ?

update: It seems to crash more often if I resize the window smaller at first
If I resize it larger, it seems to be working as long as I do not go with a window too small...

Thank you
#22
Help requests / RAM and CPU time consumption
19 December 2022, 19:38:55
Hello, first of all thank you for developping TGUI !

I have an object "ItemOnUIWidget" which is a subclass of SubwidgetContainer. There is a Panel, Picture and a Label within.
sizeof(ItemOnUIWidget) returns ~1000
I create around 250 of it but my RAM goes from 50Mo to 110Mo, I was wondering if there is a way to limit this RAM consumption ? I assume one of the component of ItemOnUIWidget allocate some memory to do stuff inside. Does this RAM allocation is linear ? What if I'm creating 10 000 of it ? Will my RAM go to stars ?

Secondly, when adding those ItemOnUIWidget in a ScrollPanel, with some size and position binded, it is very time consumming, around 500 000 microsec, same questions, is there a way to limit that ? Is it linear with number of widget ?

Thank you