AViewContainerBase#
A view that represents a set of views.
| Header: | #include <AUI/View/AViewContainerBase.h> |
| CMake: | aui_link(my_target PUBLIC aui::views) |
Detailed Description#
AViewContainerBase can store, render, resize, provide events to and handle the child views.
AViewContainerBase does not control the position and size of the child views by itself; instead, it delegates that responsibility to it's layout manager.
Since AViewContainerBase is an instance of AView, AViewContainerBase can handle AViewContainerBases recursively, thus, making possible complex UI by nested AViewContainerBases with different layout managers.
This class is abstract. The methods for modifying it's views are protected. You can use AViewContainer which exposes these methods to public or extend AViewContainerBase to make your own container-like view.
Public Types#
PointerEventsMapping#
struct AViewContainerBase::PointerEventsMapping
Empty structure.
Public fields and Signals#
childrenChanged#
emits<> childrenChanged
Emitted when addView(s)/removeView/setLayout was called.
Public Methods#
addView#
void AViewContainerBase::addView(const _<AView>& view)
Add view to the container.
Examples:
examples/app/minesweeper/src/MinesweeperWindow.cpp
Minesweeper Game — Minesweeper game implementation driven by ass.
examples/ui/views/src/ExampleWindow.cpp
Views Example — All-in-one views building example.
using namespace declarative;
void fillWindow(_<AViewContainer> t) {
t->setLayout(std::make_unique<AStackedLayout>());
t->addView(_new<ALabel>("Window contents"));
}
class AllViewsWindow : public AWindow {
public:
AllViewsWindow() : AWindow("All views", 300_dp, 500_dp, nullptr, WindowStyle::MODAL) {
Add view at specific index to the container.
Examples:
addViewCustomLayout#
void AViewContainerBase::addViewCustomLayout(const _<AView>& view)
Adds view to container without exposing it to the layout manager.
User is obligated to manage view's layout by themselves.
View is not visible until it's layout is determined. @see AView::mSkipUntilLayoutUpdate
addViews#
Add all views from vector.
focusChainTarget#
_<AView> AViewContainerBase::focusChainTarget()
- Returns
- Focus chain target.
See mFocusChainTarget for further info.
getLayout#
const _unique<ALayout>& AViewContainerBase::getLayout()
Get layout manager of the container.
getViewAt#
virtual _<AView> AViewContainerBase::getViewAt(glm::ivec2 pos, ABitField<AViewLookupFlags> flags = AViewLookupFlags::NONE)
Finds first direct child view under position.
- Arguments
posposition relative to this containerflagssee AViewLookupFlags- Returns
- found view or nullptr
Some containers may implement getViewAt by it's own (i.e. AListView for performance reasons).
getViewAtRecursive#
_<AView> AViewContainerBase::getViewAtRecursive(glm::ivec2 pos, ABitField<AViewLookupFlags> flags = AViewLookupFlags::NONE)
Acts as AViewContainerBase::getViewAt but recursively (may include non-direct child).
- Arguments
posposition relative to this containerflagssee AViewLookupFlags- Returns
- found view or nullptr
template<aui::predicate<_<AView> > Callback >
bool AViewContainerBase::getViewAtRecursive(glm::ivec2 pos, const Callback& callback, ABitField<AViewLookupFlags> flags = AViewLookupFlags::NONE)
Acts as AViewContainerBase::getViewAtRecursive but calls a callback instead of returning value.
- Arguments
posposition relative to this containercallbackcallback to callflagssee AViewLookupFlags- Returns
- true if callback returned true; false otherwise
The passed callback is a predicate. If predicate returns true, the execution of lookup is stopped and getViewAt returns true. If predicate returns false, the lookup continues.
getViewAtRecursiveOfType#
template<typename T >
_<T> AViewContainerBase::getViewAtRecursiveOfType(glm::ivec2 pos, ABitField<AViewLookupFlags> flags = AViewLookupFlags::NONE)
Acts as AViewContainerBase::getViewAtRecursive but finds a view castable to specified template type.
- Arguments
posposition relative to this containerflagssee AViewLookupFlags- Returns
- found view or nullptr
getViews#
Get all views of the container.
Examples:
examples/7guis/cells/src/main.cpp
7GUIs Cells — Spreadsheet processor (Excel).
pointerEventsMapping#
const ASmallVector<PointerEventsMapping,1>& AViewContainerBase::pointerEventsMapping()
removeAllViews#
Remove all views from container.
removeView#
void AViewContainerBase::removeView(const _<AView>& view)
Remove view from the container.
void AViewContainerBase::removeView(size_t index)
Remove view from the container at specified index.
removeViews#
Remove views from the container.
setContents#
void AViewContainerBase::setContents(const _<AViewContainer>& container)
Moves (like via std::move) all children and layout of the specified container to this container.
- Arguments
containercontainer. Must be pure AViewContainer (cannot be a derivative from AViewContainer).
Examples:
examples/7guis/flight_booker/src/main.cpp
7GUIs Flight Booker — Flight Booker.
// Create window
auto window = _new<AWindow>("AUI - 7GUIs - Book Flight", 150_dp, 50_dp);
// Set contents
window->setContents(Centered {
Vertical {
_new<ADropdownList>(AListModel<AString>::make({ "one-way flight", "return flight" })) AUI_LET {
AObject::connect(AUI_REACT(state->isReturnFlight ? 1 : 0), it->selectionId());
AObject::connect(it->selectionId().changed, AObject::GENERIC_OBSERVER, [=](int newSelection) {
state->isReturnFlight = newSelection == 1;
examples/7guis/circle_drawer/src/main.cpp
7GUIs Circle Drawer — Undo, redo, dialog control.
.onAction =
[this, circle] {
auto radiusPopup = _new<AWindow>(
"", 200_dp, 50_dp, dynamic_cast<AWindow*>(ASurface::current()), WindowStyle::MODAL);
radiusPopup->setContents(Vertical {
Label { "Adjust diameter of circle at {}."_format(circle->position) },
Slider {
.value = AUI_REACT(circle->radius / MAX_RADIUS),
.onValueChanged =
[this, circle](aui::float_within_0_1 s) {
examples/7guis/timer/src/main.cpp
7GUIs Timer — Timer example.
examples/7guis/crud/src/main.cpp
7GUIs CRUD — Create/Read/Update/Delete example.
auto FILTER_VIEW = ranges::views::filter([this](const _<User>& user) {
return user->displayName->startsWith(*mFilterPrefix);
});
setContents(Vertical {
Horizontal::Expanding {
Vertical::Expanding {
Horizontal {
Label { "Filter prefix:" },
_new<ATextField>() AUI_OVERRIDE_STYLE { Expanding(1, 0) } && mFilterPrefix,
examples/7guis/counter/src/main.cpp
7GUIs Counter — Simple counter.
/// [counter]
class CounterWindow : public AWindow {
public:
CounterWindow() : AWindow("AUI - 7GUIs - Counter", 200_dp, 100_dp) {
setContents(Centered {
Horizontal {
Label { AUI_REACT("Count: {}"_format(mCounter)) },
Button { Label { "Count" }, [this] { mCounter += 1; } },
} AUI_OVERRIDE_STYLE { LayoutSpacing { 4_dp } },
});
examples/7guis/temperature_converter/src/main.cpp
7GUIs Temperature Converter — Fahrenheit to Celsius and vice versa.
examples/app/minesweeper/src/NewGameWindow.cpp
Minesweeper Game — Minesweeper game implementation driven by ass.
: AWindow("New game", 100, 100, minesweeper), mMinesweeper(minesweeper) {
setWindowStyle(WindowStyle::MODAL);
setLayout(std::make_unique<AVerticalLayout>());
setContents(Vertical {
_form({
{
"Cells by width:"_as,
mWidth = _new<ANumberPicker>() AUI_LET {
it->setMin(8);
examples/app/fractal/src/FractalWindow.cpp
Fractal Example — Fractal viewer application demonstrating usage of custom shaders.
connect(fractal->centerPosChanged, this, [centerPosDisplay](const glm::dvec2& newPos, double scale) {
centerPosDisplay->setText("Center position: {} {}, scale: {}"_format(newPos.x, -newPos.y, scale));
});
setContents(Horizontal {
Stacked::Expanding {
fractal,
Vertical::Expanding {
SpacerExpanding {},
Horizontal {
examples/app/fractal/src/JumpToCoordsWindow.cpp
Fractal Example — Fractal viewer application demonstrating usage of custom shaders.
re->setText(AString::number(pos.x));
im->setText(AString::number(pos.y));
scale->setText(AString::number(fractalView->getPlotScale()));
setContents(Vertical {
_form({
{ "Re="_as, re },
{ "Im="_as, im },
{ "Scale="_as, scale },
}) 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.
examples/app/notes/src/main.cpp
Notes App — Note taking app that demonstrates usage of AListModel, AProperty, user data saving and loading.
examples/ui/minimal_ui_assets_xmake/src/MainWindow.cpp
Minimal UI Template XMake with Assets — Minimal UI boilerplate template XMake with AUI Assets.
using namespace declarative;
MainWindow::MainWindow(): AWindow("Project template app", 300_dp, 200_dp) {
setContents(
Centered{
Vertical{
Centered { Icon { ":img/logo.svg" } AUI_OVERRIDE_STYLE { FixedSize(64_dp) } },
Centered { Label { "Hello world from AUI!" } },
_new<AButton>("Visit GitHub repo").connect(&AView::clicked, this, [] {
examples/ui/minimal_ui_xmake/src/MainWindow.cpp
Minimal UI Template XMake — Minimal UI boilerplate template XMake.
using namespace declarative;
MainWindow::MainWindow(): AWindow("Project template app", 300_dp, 200_dp) {
setContents(
Centered{
Vertical{
Centered { Label { "Hello world from AUI!" } },
_new<AButton>("Visit GitHub repo").connect(&AView::clicked, this, [] {
APlatform::openUrl("https://github.com/aui-framework/aui");
examples/ui/contacts/src/main.cpp
AUI Contacts — Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
class ContactsWindow : public AWindow {
public:
ContactsWindow() : AWindow("AUI Contacts", 600_dp, 300_dp) {
setContents(
Horizontal {
AScrollArea::Builder()
.withContents(
Vertical {
SpacerFixed(8_dp),
examples/ui/contacts/src/view/ContactDetailsView.cpp
AUI Contacts — Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
Expanding(1, 0),
},
});
connect(mEditorMode, [this] {
setContents(Vertical::Expanding {
AScrollArea::Builder().withContents(Centered {
Vertical::Expanding {
Horizontal {
profilePhoto(mContact),
Centered::Expanding {
examples/ui/opengl_simple/src/main.cpp
OpenGL Example — Demonstrates how to integrate custom OpenGL rendering with AUI Framework.
examples/ui/infinite_lazy_list/src/main.cpp
Infinite Lazy List — Usage of AUI_DECLARATIVE_FOR to make an infinite lazy list.
}
AUI_ENTRY {
auto window = _new<AWindow>("Infinite Lazy List", 200_dp, 300_dp);
window->setContents(Stacked { AScrollArea::Builder().withContents(myLazyList(_new<State>())) });
window->show();
return 0;
}
setFocusChainTarget#
void AViewContainerBase::setFocusChainTarget(_weak<AView> target)
Set focus chain target.
- Arguments
targeta new focus chain view belonging to this container
See mFocusChainTarget for further info.
setLayout#
void AViewContainerBase::setLayout(_unique<ALayout> layout)
Set new layout manager for this AViewContainerBase. DESTROYS OLD LAYOUT MANAGER WITH ITS VIEWS!!!
Examples:
setViews#
Replace views.
visitsViewRecursive#
template<aui::predicate<_<AView> > Callback >
bool AViewContainerBase::visitsViewRecursive(Callback&& callback, ABitField<AViewLookupFlags> flags = AViewLookupFlags::NONE)
Performs recursive view traversal.
- Arguments
callbackcallback to call. Returns true to finish traversal.flagssee AViewLookupFlags- Returns
- true if there's at least one view for which callback returned true, false otherwise.