CPU-Heavy Scrolling

Started by Danetta, 03 January 2017, 15:18:04


I am not sure how to copy it, it seems like there are also Borders and Clipping classes used.

UPD: Huh, I am kinda stupid, forgot about namespace for Borders. But I don't see anything related to Clipping in tgui space.


The Borders class should be available because you indirectly include Panel, for the Clipping class you have to add the following on top of your source file:
Code (css) Select
#include <TGUI/Clipping.hpp>


Yes, realized that just one second before you answered. Sorry for these questions.


I have another question. It is more about me trying to learn and not some specific problem (because I found a workaround).

Here is my current code for initialization of panel and scrollbar for it:
Code (cpp) Select
CustomPanel pan;

tgui::Scrollbar::Ptr scroll = std::make_shared <tgui::Scrollbar>();
main_window.get_Gui()->add(scroll, "scroll_friends");
scroll->setPosition(1060, 100);
scroll->setSize(20, 620);

CustomPanel::Ptr panel = std::make_shared<CustomPanel>(pan);

panel->setSize(1060, 620);
panel->setPosition(0, 100);
//panel->setBackgroundColor(tgui::Color(0, 0, 0, 0));
panel->getRenderer()->setBackgroundColor(tgui::Color(70, 130, 180, 255));
main_window.get_Gui()->add(panel, "panel_friends");

As you can see, I use my "set_scroll" function (which I use to store pointer of scrollbar inside CutomPanel class) of custom panel via panel object itself. I think it's a wrong way to do so, because we use shared pointers to widgets anyway, right? However, once I do "CustomPanel::Ptr panel = std::make_shared<CustomPanel>(pan);" or something like that (just declaring new panel for example and not sharing existing one) I have'nt access to "set_scroll" anymore, so anything like "panel->set_scroll" is not possible. Where is my mistake?

CustomPanel.h code:
Code (cpp) Select
class CustomPanel : public tgui::Panel {
void set_scroll(tgui::Gui& gui);
void draw(sf::RenderTarget& target, sf::RenderStates states) const;
tgui::Scrollbar::Ptr scrollbar;


I really need to write a tutorial about how to write custom widgets some day, I didn't even understood why this went wrong until I saw the exact error.

You have to add the following in the declaration of your CustomPanelClass:
Code (cpp) Select
typedef std::shared_ptr<CustomPanel> Ptr;


QuoteAlso, I noticed CPU-usage spikes even in idle
I've made a large internal change in 0.8-dev, hopefully what I changed is related to this and will have fixed it.

I can't reproduce the cpu lag though, not even with calling setPosition on every widget every time the scrollbar moves.
The scrollbar generates up to 30-50 events per seconds here when being moved and each of my 50 labels is moved when this happens.
The 570 fps I have during idle only goes down to 530 fps while scrolling.

But having a CustomPanelClass that doesn't call setPosition the whole time will of course perform better in any case.