Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Widgets - General questions or Mixed problems » How would I virtualize a scrollable view to dynamically load Ctrls?
How would I virtualize a scrollable view to dynamically load Ctrls? [message #58431] Thu, 19 May 2022 19:07 Go to previous message
jjacksonRIAB is currently offline  jjacksonRIAB
Messages: 184
Registered: June 2011
Experienced Member
Quick example:

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

struct App : TopWindow {
    ScrollBar   sb;
    Array<RichTextCtrl> items;
    
    int GetLineHeight() {
        return 25;
    }

    void Sync() {
        int startY = 10;
        Rect pr = GetRect();
        auto sz = GetSize();
        
        for(RichTextCtrl& item : items) {
            Rect r = item.GetRect();

            item.SetRect(r.left, startY - sb, pr.GetWidth(), item.GetHeight(sz.cx));
            startY += r.GetHeight() + 5;
        }
        
        sb.SetTotal(startY);
    }

    void Paint(Draw& w) override {
        Size sz = GetSize();
        w.DrawRect(sz, SWhite());
        Sync();
    }

    void Layout() override {
        sb.SetPage(GetSize().cy);
    }

    void MouseWheel(Point, int zdelta, dword) override {
        sb.Wheel(zdelta);
    }

    bool Key(dword key, int) override {
        return sb.VertKey(key);
    }

    App() {
        Sizeable().Zoomable();
        
        for(int i = 0; i < 1000; i++) {
            RichTextCtrl& item = items.Create<RichTextCtrl>();
            
            item.SetData(
                Format(
                "[@(%d.%d.%d) Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et "
                "dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip "
                "ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu "
                "fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
                "mollit anim id est laborum.]",
                (int)Random(255), (int)Random(255), (int)Random(255))
                );
            
            item.SetZoom(Zoom(1, 1));
            item.HSizePos(0, 0).VSizePos(0, 0);
            item.SetRect(0, 0, 0, item.GetHeight(250));
            item.IgnoreMouse();
            
            Add(item);
        }
        
        Sync();
        
        sb.Enable();
        sb.WhenScroll = [this] { Sync(); };
        sb.SetLine(GetLineHeight());
        AddFrame(sb);
    }
};

GUI_APP_MAIN {
    App app;
    app.SetRect(0, 0, 250, 500);
    app.Run();
}


I don't know if there is any facility built into U++ for this already but I'd like to dynamically load and unload a bunch of Ctrls as I scroll (web equivalent a virtual scroller) so that I don't have a bunch of redraws of Ctrls that aren't visible in the view. As you can see from the example it can get quite expensive to resize the window if it has thousands of controls.

How would I accomplish this?
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Proper SplitterFrame removal++
Next Topic: What happened to the caret methods?
Goto Forum:
  


Current Time: Sun Sep 25 16:48:23 CEST 2022

Total time taken to generate the page: 0.01051 seconds