#include <AUI/Platform/Entry.h>
#include <AUI/Platform/AWindow.h>
#include <AUI/Util/UIBuildingHelpers.h>
#include <AUI/View/AButton.h>
#include "AUI/View/ATextField.h"
#include "AUI/View/AScrollArea.h"
#include "AUI/View/AGridSplitter.h"
#include "Spreadsheet.h"
using namespace declarative;
using namespace ass;
struct State {
Spreadsheet spreadsheet{glm::uvec2 { 'Z' - 'A' + 1, 100 }};
};
ATextAlign::CENTER,
};
}
public:
CellView(_<State> state, Cell& cell) : mState(std::move(state)), mCell(cell) { inflateLabel(); }
private:
_<State> mState;
Cell& mCell;
AAbstractSignal::AutoDestroyedConnection mConnection;
void inflateLabel() {
mConnection =
connect(mCell.value, [
this](
const formula::Value& v) {
ALayoutInflater::inflate(
this,
std::visit(
aui::lambda_overloaded {
[](std::nullopt_t) -> _<AView> { return _new<AView>(); },
[](double v) -> _<AView> { return Label { "{}"_format(v) } with_style { ATextAlign::RIGHT }; },
[](const AString& v) -> _<AView> { return Label { "{}"_format(v) }; },
[](const formula::Range& v) -> _<AView> { return Label { "#RANGE?" }; },
},
v));
});
}
void inflateEditor() {
mState->currentExpression = mCell.expression;
this,
it && mState->currentExpression;
it->focus();
connect(it->focusLost, me::commitExpression);
});
}
void commitExpression() {
mCell.expression = mState->currentExpression;
inflateLabel();
}
};
public:
CellsView(_<State> state) : mState(std::move(state)) {
this,
AGridSplitter::Builder()
.noDefaultSpacers()
.withItems([&] {
AVector<AVector<_<AView>>> views;
views.resize(mState->spreadsheet.size().y + 1);
for (auto& c : views) {
c.resize(mState->spreadsheet.size().x + 1);
}
views[0][0] = _new<AView>();
for (unsigned i = 0; i < mState->spreadsheet.size().x; ++i) {
views[0][i + 1] = Centered{ labelTitle(Cell::columnName(i)) }
with_style { Expanding(1, 0) };
}
for (unsigned row = 0; row < mState->spreadsheet.size().y; ++row) {
views[row + 1][0] = labelTitle("{}"_format(Cell::rowName(row)));
for (unsigned column = 0; column < mState->spreadsheet.size().x; ++column) {
views[row + 1][column + 1] = _new<CellView>(mState, mState->spreadsheet[{ column, row }])
with_style {
BackgroundSolid { AColor::WHITE },
};
}
}
return views;
}())
.build()
with_style { Expanding(), LayoutSpacing { 1_dp }, MinSize { 80_dp * float(mState->spreadsheet.size().x), {} } });
}
private:
_<State> mState;
};
class CellsWindow :
public AWindow {
public:
CellsWindow() : AWindow("AUI - 7GUIs - Cells", 500_dp, 400_dp) {
AScrollArea::Builder()
.withContents(Horizontal { _new<CellsView>(_new<State>()) })
Expanding(),
ScrollbarAppearance(ScrollbarAppearance::ALWAYS, ScrollbarAppearance::ALWAYS),
},
}
};
_new<CellsWindow>()->show();
return 0;
}
static void inflate(aui::no_escape< AViewContainer > root, const _< AView > &view)
Wraps view with root using Stacked layout and expanding.
Represents a Unicode character string.
Definition AString.h:38
int getContentMinimumWidth() override
const AVector< _< AView > > & getViews() const
Get all views of the container.
Definition AViewContainerBase.h:131
int getContentMinimumHeight() override
A trivial modifiable view that represents a set of views.
Definition AViewContainer.h:33
void setContents(const _< AViewContainer > &container)
Moves (like via std::move) all children and layout of the specified container to this container.
Represents a window in the underlying windowing system.
Definition AWindow.h:45
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179
class_of c
Selects views that are of the specified classes.
Definition class_of.h:84
static decltype(auto) connect(const Signal &signal, Object *object, Function &&function)
Connects signal to the slot of the specified object.
Definition AObject.h:86
#define let
Performs multiple operations on a single object without repeating its name (in place) This function c...
Definition kAUI.h:262
#define with_style
Allows to define a style to the view right in place.
Definition kAUI.h:287
#define AUI_ENTRY
Application entry point.
Definition Entry.h:90
Basic easy-to-use property implementation containing T.
Definition AProperty.h:30
Controls border radius.
Definition BorderRadius.h:28
Controls view's margins.
Definition Margin.h:29
Controls the min size of AView.
Definition MinSize.h:28
Controls the opacity of AView.
Definition Opacity.h:28