PrevNextUpHome SophiaFramework UNIVERSE 5.3

9.11. Container(Applied)

Cooperation between container and scroll bar control is described here.

9.11.1. Cooperation between Container and Scroll Bar Control

A container can scroll in cooperation with a scroll bar control.

Figure 9.31. Execution Result(Left: before scrolling, Right: after scrolling)

Execution Result(Left: before scrolling, Right: after scrolling)

Example 9.52. Declaration

SFMTYPEDEFRESPONDER(USRWindow)
class USRWindow: public SFZWindow {
    SFMSEALRESPONDER(USRWindow)
    SFMRESPONDERINSTANTIATEFOUR(USRWindow, SFZWindow, SFYContainer, SFYWidget, SFYResponder)
private:
    SFZContainerSmp _container;
    SFZContainerScrollBarControlSmp _bar;

    // ...
private:
    SFCError Make(Void);
};

Example 9.53. Implementation

SFCError USRWindow::Make(Void)
{
    SFXRectangle rectangle;
    SFCError error(SFERR_NO_ERROR);

    // make container
    if ((_container = SFZContainer::NewInstance(&error)) != null) {

        // set USRWindow to container's parent responder
        error = _container->SetParent(GetThis());
        if (error == SFERR_NO_ERROR) {

            // set container's background color to light red color
            // * container's background is automatically drawn by SFYWidget
            _container->SetBackgroundColor(SFXRGBColor(0xFF, 0xCC, 0xCC, 0x00));

            // set container's real region(narrow right side by scroll bar's width)
            rectangle.Set(GetLocalBound().Deflate(10, 10));
            rectangle.SubWidth(9);
            _container->SetRealBound(rectangle);

            // set container's virtual region to region obtained by expanding container's virtual region down by 100 pixels
            _container->SetVirtualBound(SFXRectangle(_container->GetVirtualBound()).AddBottom(100));

            // set container's state to "visible" + "active" + "enable" + "focus" together
            _container->SetState(true, true, true, true);

            // make scroll bar control for container
            if ((_bar = SFZContainerScrollBarControl::NewInstance(&error)) != null) {

                // set scroll bar control's parent responder to USRWindow
                error = _bar->SetParent(GetThis());
                if (error == SFERR_NO_ERROR) {

                    _bar->SetState(true, true, false, false);

                    // set scroll bar control's real region
                    rectangle.Set(_container->GetRealBound());
                    rectangle.SetLeft(rectangle.GetRight());
                    rectangle.SetWidth(9);
                    _bar->SetRealBound(rectangle);

                    // bind scroll bar control with container
                    _bar->Bind(_container);
                }
            }
        }
    }

    return error;
}