Skip to content

AUI_WITH_STYLE#

Allows to define a style to the view right in place.

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

Definition#

#define AUI_WITH_STYLE &ass::PropertyListRecursive

Detailed Description#

#include <AUI/ASS/ASS.h>
using namespace ass;
...
setContents(Centered {
  _new<ALabel>("Red text!") AUI_WITH_STYLE { TextColor { AColor::RED } },
});

Also applicable to declarative-style views:

#include <AUI/ASS/ASS.h>
using namespace ass;
...
setContents(Centered {
  Label { "Red text!" } AUI_WITH_STYLE { TextColor { AColor::RED } },
});

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

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

                Label { "Filter prefix:" },
                _new<ATextField>() AUI_WITH_STYLE { Expanding(1, 0) } && mFilterPrefix,
              } AUI_WITH_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/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_WITH_STYLE {
              Expanding(),
              Padding { 80_dp, 0, 0 },
            } AUI_LET { it->setExtraStylesheet(
                     AStylesheet {
                         {

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.

                          b.setText(isRunning ? "Pause" : "Run");
                      };
                      connect(it->clicked, [&] { mCells.isRunning = !mCells.isRunning; });
                  },
            } AUI_WITH_STYLE { LayoutSpacing { 4_dp } },
          },
          Centered {
            _new<CellsView>(aui::ptr::fake_shared(&mCells)) AUI_WITH_STYLE {
                  Expanding(),
                  BackgroundSolid(AColor::BLACK),

examples/app/minesweeper/src/NewGameWindow.cpp

Minesweeper Game - Minesweeper game implementation driven by ass.

        {
          "Mines count:"_as,
          mMines = _new<ANumberPicker>() AUI_LET { it->setMin(8); },
        },
      }) AUI_WITH_STYLE { LayoutSpacing { 4_dp } },
      mDifficultyLabel = _new<ALabel>(),
      Horizontal {
        _new<ASpacerExpanding>(),
        _new<AButton>("Start game") AUI_LET {
                it->setDefault();

examples/app/fractal/src/FractalWindow.cpp

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

            &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 } });

    fractal->focus();
}

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

7GUIs Counter - Simple counter.

        setContents(Centered {
          Horizontal {
            Label { AUI_REACT("Count: {}"_format(mCounter)) },
            Button { Label { "Count" }, [this] { mCounter += 1; } },
          } AUI_WITH_STYLE { LayoutSpacing { 4_dp } },
        });
    }

private:
    AProperty<int> mCounter;

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

7GUIs Flight Booker - Flight Booker.

                  }
                  AMessageBox::show(window.get(), "You've booked the flight", msg);
              },
        } AUI_LET { AObject::connect(AUI_REACT(state->isValid()), AUI_SLOT(it)::setEnabled); },
      } AUI_WITH_STYLE { LayoutSpacing { 4_dp } },
    });

    window->show();
    return 0;
}

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

7GUIs Timer - Timer example.

                        it & mElapsedTimeRatio;
                        it->setCustomStyle({ Expanding { 1, 0 } });
                    },
              },
            } AUI_WITH_STYLE { LayoutSpacing { 4_dp } },
            Label { AUI_REACT("{:.1f}s"_format(duration_cast<milliseconds>(*mElapsedTime).count() / 1000.f)) },
            Horizontal {
              Label { "Duration:" },
              Slider {
                .value = AUI_REACT(float(mDuration->count()) / float(MAX_DURATION.count())),

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

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

                      },
                },
              },
              _new<CircleDrawArea>(aui::ptr::fake_shared(&mState)),
            } AUI_WITH_STYLE { LayoutSpacing { 4_dp } });
    }

private:
    State mState;

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

7GUIs Cells - Spreadsheet processor (Excel).

    AProperty<AString> currentExpression;
};

static _<AView> labelTitle(AString s) {
    return _new<ALabel>(std::move(s)) AUI_WITH_STYLE {
        Opacity { 0.5f },
        ATextAlign::CENTER,
    };
}

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

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

                biConnect(it->value(), mCelsius);
                it->focus();
            },
            Label { "°C" },
            Label { "=" } AUI_WITH_STYLE { Margin { {}, 16_dp } },
            myPicker() AUI_LET { biConnect(it->value(), mFahrenheit); },
            Label { "°F" },
          } AUI_WITH_STYLE { LayoutSpacing { 4_dp } },
        });

Examples#

examples/app/minesweeper/src/MinesweeperWindow.cpp

Minesweeper Game - Minesweeper game implementation driven by ass.

      },
      _container<AStackedLayout>(
          { // also assign ".frame" ASS class in place
            mGrid = _new<AViewContainer>() << ".frame" }),
    } AUI_WITH_STYLE { LayoutSpacing { 4_dp } });

    beginGame(10, 10, 20);
}

void MinesweeperWindow::openCell(int x, int y, bool doGameLoseIfBomb) {

examples/app/fractal/src/JumpToCoordsWindow.cpp

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

      _form({
        { "Re="_as, re },
        { "Im="_as, im },
        { "Scale="_as, scale },
      }) AUI_WITH_STYLE { LayoutSpacing { 4_dp } },
      Horizontal {
        SpacerExpanding {},
        _new<AButton>("Jump").connect(
            &AButton::clicked, this,
            [&, fractalView, re, im, scale]() {

examples/ui/contacts/src/view/ContactDetailsView.cpp

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

_<AView> profilePhoto(const _<Contact>& contact) {
    return Centered {
        Label {
          AUI_REACT(contact->displayName->empty() ? "?" : AString(1, contact->displayName->first()).uppercase())
        } AUI_WITH_STYLE { Opacity(0.5f), FontSize { 32_dp } },
    } AUI_WITH_STYLE {
        FixedSize { 64_dp },
        BorderRadius { 32_dp },
        BackgroundGradient { AColor::GRAY.lighter(0.5f), AColor::GRAY, 163_deg },
    };

examples/ui/contacts/src/view/common.cpp

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

using namespace ass;
using namespace declarative;

_<AView> common_views::divider() {
    return _new<AView>() AUI_WITH_STYLE { FixedSize { {}, 1_px }, BackgroundSolid { AColor::GRAY } };
}