C++ Slate Scrollbox Widget Limitations & Lag

You shouldn’t have to do the click detection and all that, the widget should do that for you. You just need to make some method that takes in a float, and then pass that into the OnUserScrolled as a delegate (function pointer).

Let’s assume all this code is in some object called MyObject. Then, if I wanted to add a callback for when the user scrolls, you’d do something like:

In your header file.



// ...

public:
void MyOnUserScrolledCallback(float scrollValue);


In your Source file



// Where you are setting up the scroll bar widget.
 TSharedRef<SScrollBar> MyScrollBar = SNew(SScrollBar).OnUserScrolled(this, &MyObject::MyOnUserScrolledCallback);  

// Define the method
void MyObject::MyOnUserScrolledCallback(float scrollValue)
{    
// scrollValue is a value between 0 - 1. Figure out where that ratio lies in comparison to your data set and repopulate your widget those items.
}



How exactly would you recommend comparing the 0-1 ratio of scrollValue to a data set of say 5,000,000 items? (All of my numbers are basically just me attempting to create something almost infinite if not entirely) I’ve tried converting floats to double and using the decimal as a number but I’m failing pretty hard. Here’s another post related. Issues with float mathematics (Can't add 0.000000000000000001 + storedfloat); - C++ Gameplay Programming - Unreal Engine Forums

Just multiply the ratio value (e.g. 0 - 1) times your total items, so scrollValue * MaxItems = Your new offset for data. The post you linked doesn’t matter in this case. A standard float should have enough precision, even if your max number of items is huge (which will cause memory and other issues ) - it should still be fine.

1 Like