Skip to content

AString#

Concept shortcut to std::is_arithmetic_v

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

Examples#

examples/app/minesweeper/src/NewGameWindow.cpp

Minesweeper Game - Minesweeper game implementation driven by ass.

void NewGameWindow::updateDifficultyLabel() {
    mMines->setMax(mWidth->getValue() * mHeight->getValue() * 3 / 4);
    int difficulty = mWidth->getValue() * mHeight->getValue() / glm::max(mMines->getValue(), int64_t(1));

    AString text = "Difficulty: ";
    switch (difficulty) {
        default:
        case 0:
        case 1:
            text += "very low";

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/DemoListModel.h

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

#include <AUI/Common/AString.h>
#include <AUI/Model/IListModel.h>


class DemoListModel: public IListModel<AString> {
private:
    size_t mListSize = 3;

public:
    ~DemoListModel() override = default;

examples/7guis/cells/tests/FormulaTests.cpp

7GUIs Cells - Spreadsheet processor (Excel).

    EXPECT_EQ(std::get<double>(formula::evaluate(mSpreadsheet, "0")), 0.0);
}

TEST_F(Cells_Formula, String) {
    EXPECT_EQ(std::get<AString>(formula::evaluate(mSpreadsheet, "test")), "test");
}

TEST_F(Cells_Formula, EConstant) {
    EXPECT_DOUBLE_EQ(std::get<double>(formula::evaluate(mSpreadsheet, "=1")), 1.0);
}

examples/app/minesweeper/src/CellView.cpp

Minesweeper Game - Minesweeper game implementation driven by ass.

                    break;
            }

            context.render.setColor(color);
            context.render.string({getWidth() / 3, (getHeight() - fs.size) / 2 + fs.getAscenderHeight()}, AString::number(count), fs);
        }
    }
}

examples/app/fractal/src/JumpToCoordsWindow.cpp

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

    auto im = _new<ATextField>();
    auto scale = _new<ATextField>();

    auto pos = fractalView->getPlotPosition();
    re->setText(AString::number(pos.x));
    im->setText(AString::number(pos.y));
    scale->setText(AString::number(fractalView->getPlotScale()));

    setContents(Vertical {
      _form({

examples/ui/contacts/src/model/Contact.h

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

#include <AUI/Common/AObject.h>
#include "AUI/Common/AProperty.h"

struct Contact {
    AProperty<AString> displayName;
    AProperty<AString> phone;
    AProperty<AString> address;
    AProperty<AString> email;
    AProperty<AString> homepage;
    AProperty<AString> note;

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

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

    template<typename T>
    _<AView> presentation(AProperty<T>& property);

    template<typename T>
    _<AView> row(AString title, AProperty<T>& property);

    void drop();
    void toggleEdit();
};

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

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

namespace {
_<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/views/src/DemoListModel.cpp

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

size_t DemoListModel::listSize() {
    return mListSize;
}

AString DemoListModel::listItemAt(const AListModelIndex& index) {
    return "List item #{}"_format(index.getRow() + 1);
}

void DemoListModel::addItem() {
    mListSize += 1;

examples/7guis/cells/src/Functions.h

7GUIs Cells - Spreadsheet processor (Excel).

    AVector<formula::Value> args;
};
using Invocable = std::function<formula::Value(Ctx ctx)>;

const AMap<AString, Invocable>& predefined();
}

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

7GUIs Cells - Spreadsheet processor (Excel).

    }
}
}

const AMap<AString, functions::Invocable>& functions::predefined() {
    static AMap<AString, functions::Invocable> out = {
        { "SUM",
          [](Ctx ctx) {
              double accumulator = 0.0;
              forEachArgAndRangeCell(ctx, [&](const formula::Value& v) {

examples/7guis/cells/src/Tokens.h

7GUIs Cells - Spreadsheet processor (Excel).

#include "AUI/Util/ATokenizer.h"

namespace token {
struct Identifier {
    AString name;
};
struct Double {
    double value;
};
struct Semicolon {};   // ;

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

7GUIs Cells - Spreadsheet processor (Excel).

 */

#include "Cell.h"

AString Cell::columnName(unsigned int index) {
    return AString(U'A') + index;
}
AString Cell::rowName(unsigned int index) {
    return AString::number(index);
}

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

7GUIs Cells - Spreadsheet processor (Excel).

    formula::Value evaluate(const Spreadsheet& ctx) override { return value; }
};

struct StringLiteralNode : INode {
    AString value;
    explicit StringLiteralNode(AString value) : value(std::move(value)) {}
    ~StringLiteralNode() override = default;

    formula::Value evaluate(const Spreadsheet& ctx) override { return value; }
};

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

7GUIs Cells - Spreadsheet processor (Excel).

using namespace ass;

struct State {
    Spreadsheet spreadsheet{glm::uvec2 { 'Z' - 'A' + 1, 100 }};
    AProperty<AString> currentExpression;
};

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