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

Messages - Nafffen

#51
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
#52
Help requests / Re: RAM and CPU time consumption
20 December 2022, 09:39:15
QuoteI'm talking about tgui::Text and tgui::Sprite. You mention that Sprite stores a reference, so maybe you are looking at sf::Sprite instead of tgui::Sprite then?
My bad I was confusing sf::Sprite and tgui::Sprite, same with Text. Yes I was talking about sf::Sprite which stores a reference to a texture. My game load all textures in a specific time, and then I can access it via a shared_ptr. Is there a way to pass sf::Texture to tgui::Picture without copying the data? What if I pass multiple time the same sf::Texture to different tgui::Picture, will it be copied everytime ?

 
QuoteWhile it could be done, I would not recommend bringing SFML rendering into this. You would have to render the sf::Sprite and sf::Text to a tgui::CanvasSFML widget, which internally uses an sf::RenderTexture as buffer.
Ok it seems a bit tricky for me.

QuoteThe alternative would be to copy multiple parts of the ScrollablePanel widget into your own custom widget
I think I will go that way, if I understand it well, according to your tutorial, InventoryWidget will be subclass of tgui::Widget. I redefined functions I need and in draw function I can reuse (I mean copy appropriate parts of code) the draw function of ScrollPanel, drawing my custom parts inside directly with the BackendRenderTarget reference.

Tell me if I am wrong, either way thank you for your helpful answers.
#53
Help requests / Re: RAM and CPU time consumption
19 December 2022, 22:45:02
Thank you for your answer,

Basically I am making a UI to show an inventory in a ScrollPanel. I thought I could use ItemOnUIWidget and add them in the ScrollPanel. (which is perfect without ram and time to set up layout issues)

I just tried to replace the Picture in my ItemOnUIWidget and use a simple Sprite instead. Indeed, Sprite store a reference to a texture but Picture copies the texture, that why the RAM went up, because I copied the texture for each item. However the time to set up the layout is still to high for me with this way.

I really want to have ScrollPanel features so I made a class InventoryWidget, subclass of ScrollPanel but now I am struggling to find the right way to handle item inside. If I add as member of this class sf::Sprite and sf::Text, how will I manage drawing my items in the ScrollPanel with the offset of scrollbar and without going over the edge ? Is sf::RenderTexture a good idea ?
#54
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