Skip to content

AUI_LET#

Performs multiple operations on a single object without repeating its name (in place) This function can be used as an operator on object.

Header:#include <AUI/Util/kAUI.h>
CMake:aui_link(my_target PUBLIC aui::core)

Definition#

#define AUI_LET ^[&](const auto& it)

Detailed Description#

Analogue to with, apply in Kotlin.

AUI_LET allows to call methods of newly created objects right in place. For example:

without with
auto tf = _new<ATextField>();
tf->setText("Hello!");
auto tf = _new<ATextField>() AUI_LET { it->setText("Hello!"); };

It's especially useful when building user interfaces:

without with
auto tf1 = _new<ATextField>();
tf1->setText("Hello!");
auto tf2 = _new<ATextField>();
tf2->setText("World!");
...
setContents(Vertical { // confusing
    tf1,
    tf2,
});
// clean, less code and easy to understand
setContents(Vertical {
    _new<ATextField>() AUI_LET { it->setText("Hello!") },
    _new<ATextField>() AUI_LET { it->setText("World!") },
});

Examples#

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

7GUIs Cells — Spreadsheet processor (Excel).

            _new<ATextField>() AUI_OVERRIDE_STYLE {
                  MinSize { 0 },
                  Margin { 0 },
                  BorderRadius { 0 },
                } AUI_LET {
                    it && mState->currentExpression;
                    it->focus();
                    connect(it->focusLost, me::commitExpression);
                });
    }
examples/7guis/flight_booker/src/main.cpp

7GUIs Flight Booker — Flight Booker.

};

/// [date_field]
auto dateTextField(_<DateTextFieldState> state) {
    return _new<ATextField>() AUI_LET {
        AObject::connect(
            state->parsed, it, [&it = *it, &state = *state](const AOptional<system_clock::time_point>& value) {
                if (!value) {
                    return;
                }
examples/7guis/circle_drawer/src/main.cpp

7GUIs Circle Drawer — Undo, redo, dialog control.

        setContents(
            Vertical {
              Centered {
                Horizontal {
                  Button { Label { "Undo" }, { me::undo } } AUI_LET {
                          connect(
                              AUI_REACT(mState.history.nextAction != mState.history.begin()), AUI_SLOT(it)::setEnabled);
                      },
                  Button { Label { "Redo" }, { me::redo } } AUI_LET {
                          connect(
examples/7guis/timer/src/main.cpp

7GUIs Timer — Timer example.

          Vertical::Expanding {
            Horizontal {
              Label { "Elapsed Time:" },
              Centered::Expanding {
                _new<AProgressBar>() AUI_LET {
                        it & mElapsedTimeRatio;
                        it->setCustomStyle({ Expanding { 1, 0 } });
                    },
              },
            } AUI_OVERRIDE_STYLE { LayoutSpacing { 4_dp } },
examples/7guis/temperature_converter/src/main.cpp

7GUIs Temperature Converter — Fahrenheit to Celsius and vice versa.

using namespace declarative;

auto myPicker() {
    return _new<ANumberPicker>() AUI_LET {
        it->setMin(-999);
        it->setMax(999);
    };
}
examples/app/minesweeper/src/NewGameWindow.cpp

Minesweeper Game — Minesweeper game implementation driven by ass.

    setContents(Vertical {
      _form({
        {
          "Cells by width:"_as,
          mWidth = _new<ANumberPicker>() AUI_LET {
                       it->setMin(8);
                       it->setMax(25);
                   },
        },
        {
examples/app/fractal/src/FractalWindow.cpp

Fractal Example — Fractal viewer application demonstrating usage of custom shaders.

        _new<AButton>("Jump to coords...")
            .connect(&AButton::clicked, this, [&, fractal]() { _new<JumpToCoordsWindow>(fractal, this)->show(); }),
        _new<ALabel>("Iterations:"),
        _new<ANumberPicker>().connect(
            &ANumberPicker::valueChanged, this, [fractal](int v) { fractal->setIterations(v); }) AUI_LET {
                it->setMax(1000);
                it->setValue(350);
            },
      } AUI_OVERRIDE_STYLE { LayoutSpacing { 4_dp } },
    } AUI_OVERRIDE_STYLE { LayoutSpacing { 4_dp } });
examples/app/game_of_life/src/main.cpp

Game of Life — Game of Life implementation that uses advanced large dynamic data rendering techniques such as ITexture, AImage to be GPU friendly. The computation is performed in AThreadPool.

    GameOfLifeWindow() : AWindow("Game of Life") {
        setContents(Vertical {
          Centered {
            Horizontal {
              _new<AButton>("Randomize") AUI_LET {
                      connect(it->clicked, AUI_SLOT(mCells)::randomize);
                  },
              _new<AButton>() AUI_LET {
                      it & mCells.isRunning > [](AButton& b, bool isRunning) {
                          b.setText(isRunning ? "Pause" : "Run");
examples/app/notes/src/main.cpp

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

        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()) {
                      it->focus();
                  }
examples/ui/contacts/src/main.cpp

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

                            SpacerFixed(8_dp),
                            experimental::Dynamic {
                                .content = AUI_REACT(mSearchQuery->empty() ? indexedList() : searchQueryList()),
                            },
                            Label { AUI_REACT("{} contact(s)"_format(mContactCount)) } AUI_LET {
                                AObject::connect(AUI_REACT(ass::PropertyList{
                                    FontSize { 10_pt },
                                    ATextAlign::CENTER,
                                    Margin { 8_dp },
                                    mSearchQuery->empty() ? Visibility::VISIBLE : Visibility::GONE,
examples/ui/backdrop/src/main.cpp

Backdrop — Backdrop effects demo.

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

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

              .withContents(
                  Vertical {
                    Centered { _new<ALabel>("ALabel") },
                    Centered { _new<AButton>("AButton") },
                    Centered { _new<ATextField>() AUI_LET { it->setText("ATextField"); } },
                  }
                  << ".all_views_wrap")
              .withExpanding() });
    }
};
examples/ui/infinite_lazy_list/src/main.cpp

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

    return Vertical {
        AUI_DECLARATIVE_FOR(i, *state->items, AVerticalLayout) { return Label{} & i->value; },
        Centered {
          _new<ASpinnerV2>() AUI_LET {
                  AObject::connect(it->redrawn, AObject::GENERIC_OBSERVER, [state] {
                      // when a spinner appears, we indicate that we need more items.
                      state->needMore = true;
                  });
              },

Examples#

examples/app/fractal/src/JumpToCoordsWindow.cpp

Fractal Example — Fractal viewer application demonstrating usage of custom shaders.

                    close();
                } catch (...) {
                    AMessageBox::show(this, "Error", "Please check your values are valid numbers.");
                }
            }) AUI_LET { it->setDefault(); },
        _new<AButton>("Cancel").connect(&AButton::clicked, me::close),
      } AUI_OVERRIDE_STYLE { LayoutSpacing { 4_dp } },
    } AUI_OVERRIDE_STYLE { LayoutSpacing { 4_dp } });

    pack();