AView#
Base class of all UI objects.
Header: | #include <AUI/View/AView.h> |
CMake: | aui_link(my_target PUBLIC aui::views) |
Detailed Description#
A class that describes the minimum unit that can be placed in a container (including a window) that takes up some space on the screen, responds to changes in size, position, moving the cursor, pressing / releasing keys and buttons, mouse wheel, etc...
Analogue to Qt's QWidget, Android's View.
Examples#
examples/app/fractal/src/FractalView.cpp
Fractal Example - Fractal viewer application demonstrating usage of custom shaders.
mTexture->tex2D(*AImage::fromUrl(":img/color_scheme_wikipedia.png"));
}
void FractalView::render(ARenderContext context) {
AView::render(context);
mShader.use();
mTexture->bind();
context.render.rectangle(ACustomShaderBrush {}, { 0, 0 }, getSize());
}
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/app/minesweeper/src/Style.cpp
Minesweeper Game - Minesweeper game implementation driven by ass.
examples/ui/backdrop/src/main.cpp
Backdrop - Backdrop effects demo.
using namespace declarative;
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(
examples/ui/views/src/DemoGraphView.h
Views Example - All-in-one views building example.
#include "AUI/View/AView.h"
class DemoGraphView: public AView {
public:
DemoGraphView();
void render(ARenderContext ctx) override;
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/7guis/flight_booker/src/main.cpp
7GUIs Flight Booker - Flight Booker.
return sys_days(ymd);
},
}),
it->text());
it & state.parsed > [](AView& textField, const AOptional<system_clock::time_point>& value) {
textField.setAssName(".red", !value.hasValue());
};
};
}
examples/7guis/cells/src/main.cpp
7GUIs Cells - Spreadsheet processor (Excel).
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 },
ATextAlign::CENTER,
};
}
examples/app/fractal/src/FractalView.h
Fractal Example - Fractal viewer application demonstrating usage of custom shaders.
#include <AUI/View/AView.h>
#include <AUI/GL/Program.h>
#include <AUI/GL/Texture2D.h>
class FractalView : public AView {
private:
gl::Program mShader;
_<gl::Texture2D> mTexture;
glm::mat4 mTransform;
examples/app/minesweeper/src/CellView.h
Minesweeper Game - Minesweeper game implementation driven by ass.
#pragma once
#include "FieldCell.h"
#include "AUI/View/AView.h"
class CellView : public AView {
public:
CellView(FieldCell& cell);
void render(ARenderContext context) override;
examples/app/minesweeper/src/CellView.cpp
Minesweeper Game - Minesweeper game implementation driven by ass.
void CellView::render(ARenderContext context) {
if (mCell != mCellValueCopy) {
mCellValueCopy = mCell;
}
AView::render(context);
if (bool(mCell & FieldCell::OPEN)) {
int count = field_cell::getBombCountAround(mCell);
if (count) {
AFontStyle fs;
examples/ui/views/src/DemoGraphView.cpp
Views Example - All-in-one views building example.
}
}
void DemoGraphView::render(ARenderContext ctx) {
AView::render(ctx);
ctx.render.lines(ASolidBrush{0xff0000_rgb }, mPoints, ABorderStyle::Dashed{}, 4_dp);
}
examples/ui/contacts/src/view/common.h
AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
#include <AUI/View/AView.h>
namespace common_views {
_<AView> divider();
}
examples/ui/contacts/src/view/ContactDetailsView.cpp
AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
static constexpr auto EDITOR_CONTENT_MAX_WIDTH = 400_dp;
namespace {
_<AView> profilePhoto(const _<Contact>& contact) {
return Centered {
Label {} & contact->displayName.readProjected([](const AString& s) {
return s.empty() ? "?" : AString(1, s.first()).uppercase();
}) AUI_WITH_STYLE { Opacity(0.5f), FontSize { 32_dp } },
} AUI_WITH_STYLE {
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 } };
}
examples/ui/contacts/src/view/ContactDetailsView.h
AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
examples/ui/minimal_ui_xmake/src/MainWindow.cpp
Minimal UI Template XMake - Minimal UI boilerplate template XMake.
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");
}),
_new<AButton>("Visit docs").connect(&AView::clicked, this, [] {
APlatform::openUrl("https://aui-framework.github.io/");
}),
examples/7guis/counter/src/main.cpp
7GUIs Counter - Simple counter.
_new<ATextField>() AUI_LET {
AObject::connect(mCounter.readProjected(AString::number<int>), it->text());
it->setEditable(false);
},
Button { "Count" }.connect(&AView::clicked, [&] { mCounter += 1; }),
},
});
}
private:
Public fields and Signals#
clicked#
emits<> clicked
Left mouse button clicked.
Examples#
examples/7guis/circle_drawer/src/main.cpp
7GUIs Circle Drawer - Undo, redo, dialog control.
setContents(Vertical {
Centered {
Horizontal {
Button { "Undo" } AUI_LET {
connect(it->clicked, me::undo);
it & mState.history.nextAction.readProjected([&](UndoStack::Iterator i) { return i != mState.history.begin(); }) > &AView::setEnabled;
},
Button { "Redo" } AUI_LET {
connect(it->clicked, me::redo);
it & mState.history.nextAction.readProjected([&](UndoStack::Iterator i) { return i != mState.history.end(); }) > &AView::setEnabled;
clickedButton#
emits<APointerIndex> clickedButton
Some mouse button clicked.
clickedRight#
emits<> clickedRight
Right mouse button clicked.
clickedRightOrLongPressed#
emits<> clickedRightOrLongPressed
Right mouse button clicked or long press gesture applied.
focusState#
emits<bool> focusState
Focus state changed.
first whether focused or not.
geometryChanged#
emits<glm::ivec2,glm::ivec2> geometryChanged
Geometry (position and size) changed.
keyPressed#
emits<AInput::Key> keyPressed
Keyboard key pressed.
keyReleased#
emits<AInput::Key> keyReleased
Keyboard key released.
mAss#
std::array<ass::prop::IPropertyBase*,int(ass::prop::PropertySlot::COUNT)> mAss
Drawing list, or baking drawing commands so that you don't have to parse the ASS every time.
mCursor#
Determines shape which should pointer take when it's above this AView.
mCustomStyleRule#
ass::PropertyListRecursive mCustomStyleRule
Custom ASS Rules
mParent#
AViewContainerBase* mParent
Parent AView.
mPosition#
glm::ivec2 mPosition
Top left corner's position relative to top left corner's position of the parent AView.
redrawn#
emits<> redrawn
View is painted onto the some surface.
This signal is emitted when view's AView::postRender() is called. This signal can be used to keep track if view is visible; however, AUI performs some optimizations when painting views. For example, a view located somewhere in AScrollArea is not painted until it is outside of AScrollArea's frame or at least barely reaches it.
scrolled#
emits<glm::ivec2> scrolled
Scroll event.
viewGraphSubtreeChanged#
emits<> viewGraphSubtreeChanged
onViewGraphSubtreeChanged()
Public Methods#
addAssName#
void AView::addAssName(const AString& assName)
Adds an ASS class to this AView.
- Arguments
assName
new ASS name
capturesFocus#
- Returns
- Can this view capture focus.
For containers, capturing focus is redundant.
click#
Simulates click on the view. Useful then you want to call clicked() slots of this view.
consumesClick#
Determines whether this AView processes this click or passes it thru.
- Arguments
pos
mouse position- Returns
- true if AView processes this click
Used in AViewContainer::getViewAt method subset, thus affecting click event handling.
debugString#
virtual AString AView::debugString()
String which helps to identify this object in debug string output (i.e., for logging)
enabled#
Whether view is enabled (i.e., reacts to user).
expanding#
Expansion coefficient. Hints layout manager how much this AView should be extended relative to other AViews in the same container.
It does affect expanding environment inside the container. See expanding layout managers for more info.
It does not affect parent's size or parent's expanding property. Use AView::setExpanding() on parent, or
Expanding
variant of declarative container notation (Vertical::Expanding
, Horizontal::Expanding
,
Stacked::Expanding
) for such case.
extraStylesheet#
const _<AStylesheet>& AView::extraStylesheet()
focus#
Requests focus for this AView.
- Arguments
needFocusChainUpdate
if true, focus chain for new focused view will be updated
If needFocusChainUpdate is false you need to control focus chain targets outside the focus function
Examples#
examples/app/fractal/src/FractalWindow.cpp
Fractal Example - Fractal viewer application demonstrating usage of custom shaders.
examples/7guis/cells/src/main.cpp
7GUIs Cells - Spreadsheet processor (Excel).
Margin { 0 },
BorderRadius { 0 },
} AUI_LET {
it && mState->currentExpression;
it->focus();
connect(it->focusLost, me::commitExpression);
});
}
void commitExpression() {
examples/7guis/temperature_converter/src/main.cpp
7GUIs Temperature Converter - Fahrenheit to Celsius and vice versa.
getBorderRadius#
border-radius, specified in ASS.
getCenterPointInWindow#
The center point position of the view relatively to top left corner of the window.
Useful in UI tests:
mWindow->onPointerMove(mView->getCenterPointInWindow()); // triggers on pointer move over the view through window
getContentMinimumHeight#
- Returns
- minimal content-area height.
Examples#
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/7guis/cells/src/main.cpp
7GUIs Cells - Spreadsheet processor (Excel).
class CellView : public AViewContainer {
public:
CellView(_<State> state, Cell& cell) : mState(std::move(state)), mCell(cell) { inflateLabel(); }
int getContentMinimumWidth() override { return 0; }
int getContentMinimumHeight() override { return 0; }
private:
_<State> mState;
Cell& mCell;
AAbstractSignal::AutoDestroyedConnection mConnection;
getContentMinimumSize#
- Returns
- minimal content-area size.
getContentMinimumWidth#
- Returns
- minimal content-area width.
Examples#
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.
(*mCells)[position] = !(*mCells)[position];
updateTexture();
}
int getContentMinimumWidth() override { return mCells->size().x * SCALE; }
int getContentMinimumHeight() override { return mCells->size().y * SCALE; }
private:
_<Cells> mCells;
examples/7guis/cells/src/main.cpp
7GUIs Cells - Spreadsheet processor (Excel).
class CellView : public AViewContainer {
public:
CellView(_<State> state, Cell& cell) : mState(std::move(state)), mCell(cell) { inflateLabel(); }
int getContentMinimumWidth() override { return 0; }
int getContentMinimumHeight() override { return 0; }
private:
_<State> mState;
Cell& mCell;
getContentSize#
- Returns
- content size
getCursor#
Determines shape which should pointer take when it's above this AView.
getFixedSize#
Fixed size.
- Returns
- Fixed size. {0, 0} if unspecified.
getFloating#
AFloat AView::getFloating()
Floating value for AText.
getMargin#
const ABoxFields& AView::getMargin()
Returns the margin.
- Returns
- margin
getMaxSize#
- Returns
- maxSize (ignoring fixedSize)
getMinSize#
- Returns
- minSize (ignoring fixedSize)
getMinimumSize#
Returns the minimum size required for this view.
- Returns
- Minimum size (width, height) this view requires in pixels, excluding margins.
The minimum size includes: - Minimum content size - Padding
This value represents the absolute minimum dimensions the view needs to properly display its content. It's used by layout managers to ensure views aren't sized smaller than what they require to be functional.
getMinimumSizePlusMargin#
- Returns
- minimum content size plus margin.
This value is bare minimum space required for this view. It includes minimal content size + padding + margin which is exact space the view requires.
getOverflow#
AOverflow AView::getOverflow()
Determines whether display graphics that go out of the bounds of this AView or not.
getOverflowMask#
AOverflowMask AView::getOverflowMask()
Controls how does the overflow (stencil) mask is produced.
getPadding#
const ABoxFields& AView::getPadding()
Returns the padding.
- Returns
- padding
getParent#
AViewContainerBase* AView::getParent()
Parent AView.
getPosition#
Top left corner's position relative to top left corner's position of the parent AView.
getPositionInWindow#
- Returns
- Coords of this AView relative to window
getSize#
Size, including content area, border and padding.
Examples#
examples/app/fractal/src/FractalView.cpp
Fractal Example - Fractal viewer application demonstrating usage of custom shaders.
AView::render(context);
mShader.use();
mTexture->bind();
context.render.rectangle(ACustomShaderBrush {}, { 0, 0 }, getSize());
}
void FractalView::setSize(glm::ivec2 size) {
AView::setSize(size);
mShader.use();
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.
}
auto drawGrid = [&] {
ASmallVector<std::pair<glm::vec2, glm::vec2>, 128 * 2> points;
for (int i = 1; i < mCells->size().x; ++i) {
points << std::make_pair(glm::vec2(i * SCALE, 0.f), glm::vec2(i * SCALE, getSize().y));
}
for (int i = 1; i < mCells->size().y; ++i) {
points << std::make_pair(glm::vec2(0.f, i * SCALE), glm::vec2(getSize().x, i * SCALE));
}
ctx.render.lines(ASolidBrush { AColor::GRAY }, points);
getTotalFieldHorizontal#
- Returns
- pixel count which this AView's margin and padding acquired by width.
getTotalFieldSize#
- Returns
- pixel count which this AView's margin and padding acquired.
getTotalFieldVertical#
- Returns
- pixel count which this AView's margin and padding acquired by height.
getTotalOccupiedHeight#
- Returns
- pixel count which this AView acquired by height including content area, padding, border and margin.
getTotalOccupiedWidth#
- Returns
- pixel count which this AView acquired by width including content area, padding, border and margin.
getWindow#
Determines window which this AView belongs to.
- Returns
- window which this AView belongs to. Could be nullptr
handlesNonMouseNavigation#
- Returns
- true if this AView accepts tab focus
hasIndirectParent#
bool AView::hasIndirectParent(const _<AView>& v)
Checks if the specified view is an indirect parent of this view.
invalidateAllStyles#
Invalidates all styles, causing to iterate over all rules in global and parent stylesheets.
Unlike invalidateStateStyles(), completely resets styles for this view, causing it to iterate over all rules in global and parent stylesheets. This operation is much more expensive than invalidateStateStyles because invalidateStateStyles iterates over a small set of rules and performs fewer checks.
Prefer invalidateAllStyles over invalidateStateStyles when:
- Added/removed rules to applicable stylesheets
- The view is reinflated to other layout
- Added/removed/changed ass names of this or parent views
invalidateAssHelper#
Resets mAssHelper.
invalidateStateStyles#
Updates state selectors for ASS.
Unlike invalidateAllStyles, iterates on an already calculated small set of rules which is much more cheap that invalidateAllStyles.
Prefer invalidateStateStyles over invalidateAllStyles when:
- Changed state (hover, active, focus) of this view
markMinContentSizeInvalid#
Marks this view it requires a layout update.
See layout-managers for more info.
onClickPrevented#
Called on AWindowBase::preventClickOnPointerRelease.
onGesture#
- Arguments
origin
position where the event(s) started to occur from.event
gesture event.- Returns
- true, if consumed (handled). True value prevents click.
Handles touch screen gesture event.
The standard implementation AView::onGesture
emulates desktop events such as right click
and scroll.
onPointerMove#
virtual void AView::onPointerMove(glm::vec2 pos, const APointerMoveEvent& event)
Handles pointer hover events
- Arguments
pos
event positionevent
event description
If the view is pressed, it would still received move events. Use AView::isMouseHover to check is the pointer actually over view or not. See AView::onPointerReleased for more info.
Examples#
examples/7guis/circle_drawer/src/main.cpp
7GUIs Circle Drawer - Undo, redo, dialog control.
}
}
void onPointerMove(glm::vec2 pos, const APointerMoveEvent& event) override {
AView::onPointerMove(pos, event);
mHoveredCircle = [&] {
Circle* result = nullptr;
float nearestDistanceToCursor = std::numeric_limits<float>::max();
for (auto& circle : mState->circles.raw) {
float distanceToCursor = glm::distance2(circle.position, pos);
onPointerPressed#
virtual void AView::onPointerPressed(const APointerPressedEvent& event)
Called on pointer (mouse) released event.
- Arguments
event
event
Examples#
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.
drawGrid();
}
void onPointerPressed(const APointerPressedEvent& event) override {
AView::onPointerPressed(event);
glm::ivec2 position = glm::ivec2(event.position / float(SCALE));
(*mCells)[position] = !(*mCells)[position];
updateTexture();
}
onPointerReleased#
virtual void AView::onPointerReleased(const APointerReleasedEvent& event)
Called on pointer (mouse) released event.
- Arguments
event
event
To handle clicks, you should use AView::clicked signal instead. View still receives pointer move and released events even if cursor goes outside the view boundaries, or other exclusive event appeared (i.e. scrollarea scroll). AView::clicked emitted only if release event occurred inside view and no other event has prevented click gesture. See APointerReleasedEvent::triggerClick.
Examples#
examples/7guis/circle_drawer/src/main.cpp
7GUIs Circle Drawer - Undo, redo, dialog control.
};
}
public:
void onPointerReleased(const APointerReleasedEvent& event) override {
AView::onPointerReleased(event);
if (event.asButton != AInput::LBUTTON) {
return;
}
class ActionAddCircle : public IAction {
onScroll#
virtual void AView::onScroll(const AScrollEvent& event)
- Arguments
event
event info.
Handles mouse wheel events.
Examples#
examples/app/fractal/src/FractalView.cpp
Fractal Example - Fractal viewer application demonstrating usage of custom shaders.
mShader.set(UNIFORM_ITERATIONS, int(it));
}
void FractalView::onScroll(const AScrollEvent& event) {
AView::onScroll(event);
auto projectedPos = (glm::dvec2(event.origin) / glm::dvec2(getSize()) - glm::dvec2(0.5)) * 2.0;
projectedPos.x *= mAspectRatio;
mTransform = glm::translate(mTransform, glm::vec3 { projectedPos, 0.0 });
mTransform = glm::scale(mTransform, glm::vec3(1.0 - event.delta.y / 1000.0));
mTransform = glm::translate(mTransform, -glm::vec3 { projectedPos, 0.0 });
examples/app/fractal/src/FractalView.h
Fractal Example - Fractal viewer application demonstrating usage of custom shaders.
void onKeyDown(AInput::Key key) override;
void onKeyRepeat(AInput::Key key) override;
void onScroll(const AScrollEvent& event) override;
void setSize(glm::ivec2 size) override;
gl::Program& getShader() { return mShader; }
pack#
Sets minimal size.
Examples#
examples/app/fractal/src/JumpToCoordsWindow.cpp
Fractal Example - Fractal viewer application demonstrating usage of custom shaders.
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.
}; /// end
AUI_ENTRY {
auto w = _new<GameOfLifeWindow>();
w->pack();
w->show();
return 0;
}
examples/app/minesweeper/src/NewGameWindow.cpp
Minesweeper Game - Minesweeper game implementation driven by ass.
connect(mHeight->valueChanging, me::updateMinesMax);
connect(mHeight->valueChanging, me::updateDifficultyLabel);
connect(mMines->valueChanging, me::updateDifficultyLabel);
pack();
}
void NewGameWindow::begin() {
close();
mMinesweeper->beginGame(gWidth = mWidth->getValue(), gHeight = mHeight->getValue(), gMines = mMines->getValue());
examples/app/minesweeper/src/MinesweeperWindow.cpp
Minesweeper Game - Minesweeper game implementation driven by ass.
setupEventHandlers(x, y, cell);
mGrid->addView(cell);
}
pack();
}
/// [beginGame]
void MinesweeperWindow::setupEventHandlers(int x, int y, const _<CellView>& cell) {
/// [clicked]
position#
Top left corner's position relative to top left corner's position of the parent AView.
postRender#
virtual void AView::postRender(ARenderContext ctx)
Performs post-draw routines of this AView. Noone should call this function except rendering routine.
redraw#
Request window manager to redraw this AView.
Examples#
examples/app/fractal/src/FractalView.cpp
Fractal Example - Fractal viewer application demonstrating usage of custom shaders.
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/minesweeper/src/MinesweeperWindow.cpp
Minesweeper Game - Minesweeper game implementation driven by ass.
if (doGameLoseIfBomb) {
c |= FieldCell::RED_BG;
mReveal = true;
emit customCssPropertyChanged();
redraw();
AMessageBox::show(this, "You lost!", "You lost! Ahahahhaa!");
}
return;
}
c |= FieldCell::OPEN;
examples/7guis/circle_drawer/src/main.cpp
7GUIs Circle Drawer - Undo, redo, dialog control.
BackgroundSolid(AColor::WHITE),
Border(1_px, AColor::GRAY),
AOverflow::HIDDEN_FROM_THIS,
});
connect(mState->circles.changed, me::redraw);
connect(mHoveredCircle.changed, me::redraw);
}
void render(ARenderContext ctx) override {
AView::render(ctx);
removeAssName#
void AView::removeAssName(const AString& assName)
Removes an ASS class to this AView.
- Arguments
assName
ASS name to remove
render#
virtual void AView::render(ARenderContext ctx)
Draws this AView. Noone should call this function except rendering routine.
AView::render is not guaranteed to be called on per-frame basis. Moreover, this method can be called multiple times if render-to-texture caching decides to do so.
Examples#
examples/app/fractal/src/FractalView.cpp
Fractal Example - Fractal viewer application demonstrating usage of custom shaders.
mTexture->tex2D(*AImage::fromUrl(":img/color_scheme_wikipedia.png"));
}
void FractalView::render(ARenderContext context) {
AView::render(context);
mShader.use();
mTexture->bind();
context.render.rectangle(ACustomShaderBrush {}, { 0, 0 }, getSize());
}
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.
CellsView(_<Cells> cells) : mCells(std::move(cells)) { connect(mCells->frameComplete, me::updateTexture); }
void render(ARenderContext ctx) override {
AView::render(ctx);
if (mTexture) {
ctx.render.rectangle(ATexturedBrush { mTexture }, { 0, 0 }, float(SCALE) * glm::vec2(mCells->size()));
}
auto drawGrid = [&] {
ASmallVector<std::pair<glm::vec2, glm::vec2>, 128 * 2> points;
examples/app/minesweeper/src/CellView.cpp
Minesweeper Game - Minesweeper game implementation driven by ass.
void CellView::render(ARenderContext context) {
if (mCell != mCellValueCopy) {
mCellValueCopy = mCell;
}
AView::render(context);
if (bool(mCell & FieldCell::OPEN)) {
int count = field_cell::getBombCountAround(mCell);
if (count) {
AFontStyle fs;
examples/ui/views/src/DemoGraphView.cpp
Views Example - All-in-one views building example.
}
}
void DemoGraphView::render(ARenderContext ctx) {
AView::render(ctx);
ctx.render.lines(ASolidBrush{0xff0000_rgb }, mPoints, ABorderStyle::Dashed{}, 4_dp);
}
examples/7guis/circle_drawer/src/main.cpp
7GUIs Circle Drawer - Undo, redo, dialog control.
connect(mHoveredCircle.changed, me::redraw);
}
void render(ARenderContext ctx) override {
AView::render(ctx);
for (const auto& circle : *mState->circles) {
if (&circle == mHoveredCircle) {
ctx.render.roundedRectangle(
ASolidBrush { AColor::GRAY }, circle.position - circle.radius, glm::vec2(circle.radius * 2.f),
examples/app/fractal/src/FractalView.h
Fractal Example - Fractal viewer application demonstrating usage of custom shaders.
void handleMatrixUpdated();
public:
FractalView();
void render(ARenderContext context) override;
void reset();
void setIterations(unsigned it);
examples/app/minesweeper/src/CellView.h
Minesweeper Game - Minesweeper game implementation driven by ass.
class CellView : public AView {
public:
CellView(FieldCell& cell);
void render(ARenderContext context) override;
[[nodiscard]]
FieldCell fieldCell() const { return mCell; }
private:
examples/ui/views/src/DemoGraphView.h
Views Example - All-in-one views building example.
class DemoGraphView: public AView {
public:
DemoGraphView();
void render(ARenderContext ctx) override;
private:
AVector<glm::vec2> mPoints;
};
setAssName#
void AView::setAssName(const AString& assName, bool value)
Depending on value, either adds or removes ass name.
- Arguments
assName
ASS name to add or removevalue
boolean that determines actual operation
Examples#
examples/7guis/flight_booker/src/main.cpp
7GUIs Flight Booker - Flight Booker.
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,
},
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);
});
setExpanding#
Changes the expanding of view.
Examples#
examples/app/fractal/src/FractalView.cpp
Fractal Example - Fractal viewer application demonstrating usage of custom shaders.
static gl::Program::Uniform UNIFORM_RATIO("ratio");
static gl::Program::Uniform UNIFORM_ITERATIONS("iterations");
FractalView::FractalView() : mTransform(1.f) {
setExpanding();
mShader.load(R"(
#version 330 core
in vec4 pos;
in vec2 uv;
Changes the expanding of view.
Examples#
examples/app/fractal/src/FractalView.cpp
Fractal Example - Fractal viewer application demonstrating usage of custom shaders.
static gl::Program::Uniform UNIFORM_RATIO("ratio");
static gl::Program::Uniform UNIFORM_ITERATIONS("iterations");
FractalView::FractalView() : mTransform(1.f) {
setExpanding();
mShader.load(R"(
#version 330 core
in vec4 pos;
in vec2 uv;
setExtraStylesheet#
void AView::setExtraStylesheet(_<AStylesheet> extraStylesheet)
Examples#
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/7guis/flight_booker/src/main.cpp
7GUIs Flight Booker - Flight Booker.
examples/ui/contacts/src/view/ContactDetailsView.cpp
AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
Examples#
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/7guis/flight_booker/src/main.cpp
7GUIs Flight Booker - Flight Booker.
examples/ui/contacts/src/view/ContactDetailsView.cpp
AUI Contacts - Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.
setFloating#
void AView::setFloating(AFloat f)
Set floating value for AText.
setGeometry#
Sets position and size of the view.
See layout-managers for more info.
setMargin#
void AView::setMargin(const ABoxFields& margin)
Sets the margin.
- Arguments
margin
margin
setPadding#
void AView::setPadding(const ABoxFields& padding)
Sets the padding.
- Arguments
padding
padding
setSizeForced#
- Arguments
size
Set size ignoring all restrictions (i.e. min size, max size, fixed size, etc...). Used by AAnimator.
setSkipUntilLayoutUpdate#
size#
Size, including content area, border and padding.
Examples#
examples/app/fractal/src/FractalView.cpp
Fractal Example - Fractal viewer application demonstrating usage of custom shaders.
mTexture->bind();
context.render.rectangle(ACustomShaderBrush {}, { 0, 0 }, getSize());
}
void FractalView::setSize(glm::ivec2 size) {
AView::setSize(size);
mShader.use();
mShader.set(UNIFORM_RATIO, mAspectRatio = float(size.x) / float(size.y));
}
examples/7guis/cells/src/main.cpp
7GUIs Cells - Spreadsheet processor (Excel).
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.
using CellsImage = AFormattedImage<APixelFormat::RGBA_BYTE>;
class Cells : public AObject {
public:
Cells(glm::ivec2 size) {
mSize = size;
for (auto s : { &mStorage, &mNextPopulation }) {
s->resize(size.x * size.y);
}
examples/7guis/cells/src/Spreadsheet.h
7GUIs Cells - Spreadsheet processor (Excel).
examples/7guis/cells/src/Functions.cpp
7GUIs Cells - Spreadsheet processor (Excel).
return double(accumulator);
} },
{ "IF",
[](Ctx ctx) {
if (ctx.args.size() != 3) {
throw AException("ARG");
}
auto condition = std::get_if<double>(&ctx.args[0]);
if (condition == nullptr) {
throw AException("ARG0");
visibility#
Visibility value.
wantsTouchscreenKeyboard#
Returns true if view is textfield-like view which requires touchscreen keyboard when clicked.