Skip to content

AScrollArea#

A scrollable container with vertical and horizontal scrollbars.

Header:#include <AUI/View/AScrollArea.h>
CMake:aui_link(my_target PUBLIC aui::views)

Detailed Description#

AScrollArea should have expanding, or fixed size, or max size to be set in order to define it's sizing rules, as it's size cannot be defined by it's contents for obvious reasons.

FixedSize and Expanding stylesheet properties would work as expected. If neither of them is set, AScrollArea would occupy size by minimum size of it's contents, as a AViewContainer would do. In such case, you may restrict maximum size of AScrollArea with MaxSize property. AScrollArea will not exceed MaxSize, but also become actual scroll area, involving displaying scroll bars and handling scroll events. This behaviour is similar to Text.

Expanding is enabled by default. It can be disabled with ass::Expanding(0) property.

Behaviour of vertical and horizontal axes are independent from each other. This behaviour is similar to Text.

Expanding contents fill the viewport#

A child of AScrollArea that has ass::Expanding set will always occupy at least the full viewport size on the expanding axis, even when the scrollable surface is smaller than the viewport. This matches the intuitive expectation: an expanding widget "fills" the scroll area rather than collapsing to its minimum size.

AScrollArea::Builder()
    .withContents(
        _new<AView>() AUI_OVERRIDE_STYLE { Expanding {}, BackgroundSolid { AColor::GREEN } }
    ).build();
// The green view will always cover the entire visible area of the scroll area.

Non-expanding children are sized to their measured preferred size as usual (and may be smaller than the viewport).

Examples#

examples/7guis/cells/src/main.cpp

7GUIs Cells — Spreadsheet processor (Excel).

class CellsWindow : public AWindow {
public:
    CellsWindow() : AWindow("AUI - 7GUIs - Cells", 500_dp, 400_dp) {
        setContents(Centered {
          AScrollArea::Builder()
                  .withContents(Horizontal { _new<CellsView>(_new<State>()) })
                  .build() AUI_OVERRIDE_STYLE {
                Expanding(),
                ScrollbarAppearance(ScrollbarAppearance::ALWAYS, ScrollbarAppearance::ALWAYS),
              },
examples/app/notes/src/main.cpp

Notes App — Note taking app that demonstrates usage of AListModel, AProperty, user data saving and loading.

_<AView> noteEditor(const _<Note>& note) {
    if (note == nullptr) {
        return Centered { Label { "No note selected" } };
    }
    return AScrollArea::Builder().withContents(
        Vertical {
          _new<TitleTextArea>("Untitled") AUI_LET {
                  it->setCustomStyle({ FontSize { 14_pt }, Expanding { 1, 0 } });
                  AObject::biConnect(note->title, it->text());
                  if (note->content.raw.empty()) {
examples/ui/contacts/src/main.cpp

AUI Contacts — Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.

public:
    ContactsWindow() : AWindow("AUI Contacts", 600_dp, 300_dp) {
        setContents(
            Horizontal {
              AScrollArea::Builder()
                      .withContents(
                          Vertical {
                            SpacerFixed(8_dp),
                            _new<ATextField>() && mSearchQuery,
                            SpacerFixed(8_dp),
examples/ui/backdrop/src/main.cpp

Backdrop — Backdrop effects demo.

using namespace ass;

static auto headerWithContents(_<AView> content) {
    auto result = Stacked {
        AScrollArea::Builder().withContents(content).build() AUI_OVERRIDE_STYLE {
              Expanding(),
              Padding { 80_dp, 0, 0 },
            } AUI_LET { it->setExtraStylesheet(
                     AStylesheet {
                         {
examples/ui/views/src/ExampleWindow.cpp

Views Example — All-in-one views building example.

class AllViewsWindow : public AWindow {
public:
    AllViewsWindow() : AWindow("All views", 300_dp, 500_dp, nullptr, WindowStyle::MODAL) {
        setContents(Centered {
          AScrollArea::Builder()
              .withContents(
                  Vertical {
                    Centered { _new<ALabel>("ALabel") },
                    Centered { _new<AButton>("AButton") },
                    Centered { _new<ATextField>() AUI_LET { it->setText("ATextField"); } },
examples/ui/infinite_lazy_list/src/main.cpp

Infinite Lazy List — Usage of AUI_DECLARATIVE_FOR to make an infinite lazy list.

}

AUI_ENTRY {
    auto window = _new<AWindow>("Infinite Lazy List", 200_dp, 300_dp);
    window->setContents(Stacked { AScrollArea::Builder().withContents(myLazyList(_new<State>())) });
    window->show();

    return 0;
}
examples/7guis/crud/src/main.cpp

7GUIs CRUD — Create/Read/Update/Delete example.

              Horizontal {
                Label { "Filter prefix:" },
                _new<ATextField>() AUI_OVERRIDE_STYLE { Expanding(1, 0) } && mFilterPrefix,
              } AUI_OVERRIDE_STYLE { LayoutSpacing { 4_dp } },
              AScrollArea::Builder().withExpanding().withContents(
                  AUI_DECLARATIVE_FOR(i, *mUsers | FILTER_VIEW, AVerticalLayout) {
                    auto view = _new<ALabel>();
                    view & i->displayName;
                    connect(mSelectedUser, view, [this, &view = *view, i] {
                        view.setAssName("selected", mSelectedUser == i);
examples/ui/contacts/src/view/ContactDetailsView.cpp

AUI Contacts — Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.

      },
    });
    connect(mEditorMode, [this] {
        setContents(Vertical::Expanding {
          AScrollArea::Builder().withContents(Centered {
            Vertical::Expanding {
              Horizontal {
                profilePhoto(mContact),
                Centered::Expanding {
                  presentation(mContact->displayName) AUI_OVERRIDE_STYLE { FontSize { 12_pt } },

Public Types#


Builder#

class AScrollArea::Builder

Examples:

Empty structure.


Builder#

class AScrollArea::Builder

Examples:

Empty structure.

Public Methods#

scrollTo#


void AScrollArea::scrollTo(const _<AView>& target, bool nearestBorder = true)

Scrolls to the specified target view.

Arguments
target
target view to scroll to. Must be direct or indirect child.
nearestBorder
if true, the scroll is performed up to the nearest border of scroll area, and if the target is already fully visible, then scrollTo does not take effect. If false, the scroll is performed up to the top border of the target view.

void AScrollArea::scrollTo(ARect<int> target, bool nearestBorder = true)

Scrolls to the specified rectangle area.

Arguments
target
target rectangle area in coordinate space of the window.
nearestBorder
if true, the scroll is performed up to the nearest border of scroll area, and if the target is already fully visible, then scrollTo does not take effect. If false, the scroll is performed up to the top border of the target view.

setStickToEnd#


void AScrollArea::setStickToEnd(bool stickToEnd)

Set stick to end.

setWheelScrollable#


void AScrollArea::setWheelScrollable(bool value)