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/app/notes/src/main.cpp

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

                      },
                      /// [scrollarea]
                      AScrollArea::Builder()
                          .withContents(
                          AUI_DECLARATIVE_FOR(note, *mNotes, AVerticalLayout) {
                              observeChangesForDirty(note);
                              return notePreview(note) AUI_LET {
                                  connect(it->clicked, [this, note] { mCurrentNote = note; });
                                  it& mCurrentNote > [note](AView& view, const _<Note>& currentNote) {
                                      ALOG_DEBUG(LOG_TAG) << "currentNote == note " << currentNote << " == " << note;

examples/ui/contacts/src/main.cpp

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

        mSelectedContact = nullptr;
    }

    _<AView> indexedList() {
        return AUI_DECLARATIVE_FOR(group, *mContacts | ranges::views::chunk_by([](const _<Contact>& lhs, const _<Contact>& rhs) {
                                return groupLetter(lhs->displayName) == groupLetter(rhs->displayName);
                            }), AVerticalLayout) {
            auto firstContact = *ranges::begin(group);
            auto firstLetter = groupLetter(firstContact->displayName);
            ALogger::info("Test") << "Computing view for group " << AString(1, firstLetter);

examples/ui/views/src/ExampleWindow.cpp

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

                                    }
                                }),
                            _new<ASpacerExpanding>(),
                          } AUI_WITH_STYLE { LayoutSpacing { 4_dp } },
                          AUI_DECLARATIVE_FOR(i, *state->colors, AWordWrappingLayout) {
                              return Horizontal {
                                  _new<ALabel>(i.toString()) AUI_WITH_STYLE {
                                      TextColor { i.readableBlackOrWhite() },
                                  }
                              } AUI_WITH_STYLE {

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/ui/backdrop/src/main.cpp

Backdrop - Backdrop effects demo.

    auto result = Stacked {
        AScrollArea::Builder().withContents(content).build() AUI_WITH_STYLE {
              Expanding(),
              Padding { 80_dp, 0, 0 },
            } AUI_LET { it->setExtraStylesheet(
                     AStylesheet {
                         {
                             t<AScrollAreaViewport>(),
                             AOverflow::VISIBLE,
                         },

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/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_WITH_STYLE { LayoutSpacing { 4_dp } },
    } AUI_WITH_STYLE { LayoutSpacing { 4_dp } });

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

7GUIs Flight Booker - Flight Booker.

    using type = _<ass::prop::IPropertyBase>;
};

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/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_WITH_STYLE { LayoutSpacing { 4_dp } },

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/cells/src/main.cpp

7GUIs Cells - Spreadsheet processor (Excel).

            _new<ATextField>() AUI_WITH_STYLE {
                  MinSize { 0 },
                  Margin { 0 },
                  BorderRadius { 0 },
                } AUI_LET {
                    it && mState->currentExpression;
                    it->focus();
                    connect(it->focusLost, me::commitExpression);
                });
    }

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#

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_WITH_STYLE { LayoutSpacing { 4_dp } },
    } AUI_WITH_STYLE { LayoutSpacing { 4_dp } });

    pack();