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 » Problem with ScrollBar and multiple controls
Problem with ScrollBar and multiple controls [message #52003] Wed, 03 July 2019 01:00 Go to previous message
ultimatecoding is currently offline  ultimatecoding
Messages: 4
Registered: July 2019
Junior Member
Hello,

I'm pretty new to Ultimate++, and I've been fiddling with it on and off for a couple of days now. Everything was going well until I decided to test my concept.

The general idea is that I would like to have something like a panel containing sub-controls in a form of a vertical list. Now, I want to be able to scroll through those controls. Here's a simplified version of what I've come up with so far:

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

struct ButtonPanel : Ctrl
{
    Vector<Button*> buttons;
    const int btnHeight = 100;
    
    ButtonPanel(int n)
    {
        for (int i = 0; i < n; ++i) {
            Button *btn = new Button();
            btn->SetLabel("Button " + AsString(i + 1));
            buttons << btn;
            *this << btn->HSizePos(0, 0).TopPos(i * btnHeight, btnHeight);
        }
    }

    ~ButtonPanel()
    {
        for (Button *btn : buttons) {
            delete btn;
        }
    }

    int getHeight()
    {
        return buttons.size() * btnHeight;
    }

};

struct MainWindow : TopWindow
{
    ButtonPanel btnPanel;
    ScrollBar scrlBar;
    bool isLoaded;

    MainWindow() :
        btnPanel(163), // <-- here
        isLoaded(false)
    {
        CenterScreen().Sizeable().Zoomable();
        Title("ScrollTest");
        AddFrame(scrlBar);
        scrlBar.SetLine(btnPanel.btnHeight);
        scrlBar.SetTotal(btnPanel.buttons.size() * btnPanel.btnHeight);
        scrlBar.WhenScroll = [=] { Refresh(); };
    }

    virtual void Layout()
    {
        scrlBar.SetPage(GetSize().cy);
    }

    void MainWindow::MouseWheel(Point, int zdelta, dword)
    {
        scrlBar.Wheel(zdelta);
    }

    virtual void Paint(Draw& w)
    {
        w.DrawRect(GetSize(), SGray);
        if (!isLoaded) {
            *this << btnPanel.HSizePos(0, 0).TopPos(0, btnPanel.getHeight());
            isLoaded = !isLoaded;
        }
        // moving entire panel based on scroll position
        btnPanel.TopPos(-scrlBar, btnPanel.getHeight());
    }
};

GUI_APP_MAIN
{
    MainWindow mainWin;
    mainWin.Run();
}


It seems that for heights roughly above 16,300 pixels, things start getting out of control. For example, if I change the number of buttons from 163 to 164 in the code above, I'm not able to see any buttons.

Unless there's some internal bug I'm unaware of, I honestly can't see what I'm doing wrong (at least conceptually).

Any help would be greatly appreciated. If there's a better way to accomplish what I'm trying to do, please also let me know.

Thank you.

[Updated on: Wed, 03 July 2019 08:51]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: capture mouse and limit all events to window
Next Topic: Deleting Ctrl from within itself
Goto Forum:
  


Current Time: Sun Oct 20 19:23:29 CEST 2019

Total time taken to generate the page: 0.01041 seconds