Adding agents.md, fixing long-broken initializer list constructor
This commit is contained in:
1 parent
6a6294c67d
commit
ff2e4e642d
12 files changed
+484
-526
No files matched your search
@@ -103,6 +103,10 @@ template <typename T> struct Array {
|
||||
}
|
||||
}
|
||||
}
|
||||
// initializer_list elements are const, so they can only be copied, never moved.
|
||||
// For move-only T (e.g. OwningPtr) this ctor is deleted — construct such arrays
|
||||
// with the default ctor + add()/emplace() instead (those move).
|
||||
template <typename U = T, typename = std::enable_if_t<std::is_copy_constructible_v<U>>>
|
||||
constexpr Array(std::initializer_list<T> init, const allocator_type& alloc = allocator_type())
|
||||
: arraySize(init.size()), allocated(init.size()), allocator(alloc) {
|
||||
_data = allocateArray(init.size());
|
||||
@@ -276,7 +280,12 @@ template <typename T> struct Array {
|
||||
T* tempArray = allocateArray(allocated);
|
||||
assert(tempArray != nullptr);
|
||||
|
||||
std::uninitialized_move(begin(), end(), Iterator(tempArray));
|
||||
// begin()/end() yield lvalue iterators, so uninitialized_move would
|
||||
// degrade to a copy — invalid for move-only T (e.g. OwningPtr). Move
|
||||
// each element explicitly instead.
|
||||
for (size_type i = 0; i < arraySize; ++i) {
|
||||
std::allocator_traits<allocator_type>::construct(allocator, &tempArray[i], std::move(_data[i]));
|
||||
}
|
||||
deallocateArray(_data, arraySize);
|
||||
_data = tempArray;
|
||||
}
|
||||
|
||||
@@ -32,12 +32,12 @@ void Queue::submitCommandBuffer(PCommand command, const Array<VkSemaphore>& sign
|
||||
// is also signalled in this same submit.
|
||||
for (VkSemaphore waitHandle : command->waitHandles) {
|
||||
waitSemaphores.add(waitHandle);
|
||||
std::cout << "Semaphore " << waitHandle << " waited on by cmd " << command->getHandle() << std::endl;
|
||||
// std::cout << "Semaphore " << waitHandle << " waited on by cmd " << command->getHandle() << std::endl;
|
||||
}
|
||||
|
||||
for (VkSemaphore signalSemaphore : signalSemaphores) {
|
||||
std::cout << "Semaphore " << signalSemaphore << " is signalled by cmd " << command->getHandle() << std::endl;
|
||||
}
|
||||
// for (VkSemaphore signalSemaphore : signalSemaphores) {
|
||||
// std::cout << "Semaphore " << signalSemaphore << " is signalled by cmd " << command->getHandle() << std::endl;
|
||||
// }
|
||||
|
||||
VkSubmitInfo submitInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
|
||||
|
||||
@@ -234,7 +234,7 @@ void Seele::Vulkan::Window::endFrame() {
|
||||
.pResults = &swapChainResult,
|
||||
};
|
||||
VkResult r = vkQueuePresentKHR(graphics->getGraphicsCommands()->getQueue()->getHandle(), &presentInfo);
|
||||
std::cout << "Semaphore " << renderDoneHandle << " signals present for image index " << currentImageIndex << std::endl;
|
||||
// std::cout << "Semaphore " << renderDoneHandle << " signals present for image index " << currentImageIndex << std::endl;
|
||||
if (swapChainResult == VK_ERROR_OUT_OF_DATE_KHR || swapChainResult == VK_SUBOPTIMAL_KHR || r == VK_ERROR_OUT_OF_DATE_KHR || r == VK_SUBOPTIMAL_KHR) {
|
||||
createSwapChain();
|
||||
} else {
|
||||
|
||||
+14
-11
@@ -26,6 +26,7 @@ struct UIRender {
|
||||
Vector2 uvOffset = Vector2(0);
|
||||
Vector2 uvSize = Vector2(1);
|
||||
};
|
||||
DECLARE_REF(Element)
|
||||
class Element {
|
||||
public:
|
||||
// the System walks the retained tree (style/layout/input/render) and needs to read
|
||||
@@ -36,16 +37,19 @@ class Element {
|
||||
// yields the pointer; ownership/lifetime for the demo is the caller's concern (the
|
||||
// engine does not free them here).
|
||||
explicit Element(Attributes attr) : attr(attr) {}
|
||||
Element(Attributes attr, std::initializer_list<Element*> children_) : attr(attr) {
|
||||
for (auto c : children_) {
|
||||
Element(Attributes attr, std::initializer_list<OElement> children_) : attr(attr) {
|
||||
// children is Array<OElement> (move-only), so it can't be move-constructed
|
||||
// from the initializer list (initializer_list elements are const). Add each
|
||||
// child explicitly — add() moves the OwningPtr in, transferring ownership.
|
||||
for (const OElement& c : children_) {
|
||||
if (c != nullptr) {
|
||||
c->setParent(this);
|
||||
children.add(c);
|
||||
children.add(std::move(const_cast<OElement&>(c)));
|
||||
children.back()->setParent(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual ~Element();
|
||||
void setParent(Element* p) { parent = p; }
|
||||
void setParent(PElement p) { parent = p; }
|
||||
|
||||
// resolves the inherited style + this element's static template classes against the theme.
|
||||
// only re-run for this element when style.dirty or the theme changed.
|
||||
@@ -63,7 +67,7 @@ class Element {
|
||||
// explicit mutation entry point: applies runtime overrides, then re-styles the dirty subtree
|
||||
void markDirty() {
|
||||
style.dirty = true;
|
||||
if (parent) {
|
||||
if (parent != nullptr) {
|
||||
parent->markDirty();
|
||||
}
|
||||
}
|
||||
@@ -87,7 +91,7 @@ class Element {
|
||||
// CPU unit tests need to read/write `position`+`dimensions` and read `children`
|
||||
// without a friend declaration (FlexLayout is a namespace, not a class, and the
|
||||
// tests are a separate TU).
|
||||
const Array<Element*>& getChildren() const { return children; }
|
||||
const Array<OElement>& getChildren() const { return children; }
|
||||
void setLayout(const Vector2& pos, const Vector2& dims) {
|
||||
position = pos;
|
||||
dimensions = dims;
|
||||
@@ -103,7 +107,7 @@ class Element {
|
||||
// (min/max, position, display) before re-resolving; the .cpp only reads it.
|
||||
Style& getStyle() { return style; }
|
||||
const Style& getStyle() const { return style; }
|
||||
Element* getParent() const { return parent; }
|
||||
PElement getParent() const { return parent; }
|
||||
float getIntrinsicW() const { return intrinsicW; }
|
||||
float getIntrinsicH() const { return intrinsicH; }
|
||||
|
||||
@@ -146,9 +150,8 @@ class Element {
|
||||
|
||||
protected:
|
||||
Attributes attr;
|
||||
Element* parent = nullptr;
|
||||
// raw, non-owning (see the ctor comment); matches the pre-existing call sites
|
||||
Array<Element*> children;
|
||||
PElement parent = nullptr;
|
||||
Array<OElement> children;
|
||||
// set by the System when the theme changed; forces a one-time full re-style
|
||||
bool themeChanged = false;
|
||||
// the theme this element was last styled against. the System sets it before
|
||||
|
||||
@@ -40,12 +40,12 @@ namespace {
|
||||
struct Flow {
|
||||
std::vector<size_t> idx;
|
||||
std::vector<int32> order;
|
||||
static void build(Element* parent, Flow& f) {
|
||||
static void build(PElement parent, Flow& f) {
|
||||
f.idx.clear();
|
||||
f.order.clear();
|
||||
const auto& kids = parent->getChildren();
|
||||
for (size_t i = 0; i < kids.size(); i++) {
|
||||
Element* c = kids[i];
|
||||
PElement c = kids[i];
|
||||
if (c == nullptr || c->getStyle().display == Display::Hidden) {
|
||||
continue;
|
||||
}
|
||||
@@ -92,7 +92,7 @@ static float resolvePx(DimensionType t, float v, float cont) {
|
||||
// (px/%) size resolves against the parent's content box; an Auto (or nested-container)
|
||||
// child contributes its intrinsic size (0 for a container, since its real size is
|
||||
// finalized when the place phase recurses into it). Includes main-axis margins.
|
||||
static float childMainFootprint(Element* c, const FlexLayout::Axis& axis, float parentContentMain) {
|
||||
static float childMainFootprint(PElement c, const FlexLayout::Axis& axis, float parentContentMain) {
|
||||
const Style& s = c->getStyle();
|
||||
bool isX = axis.mainIsX;
|
||||
float size;
|
||||
@@ -120,7 +120,7 @@ static float childMainFootprint(Element* c, const FlexLayout::Axis& axis, float
|
||||
// flow children of their footprints (resolved against the element's *content* box on
|
||||
// that axis) + gaps, or the element's intrinsic size for a leaf. This is the Auto
|
||||
// fallback for the element's own size.
|
||||
static float contentAxis(bool isX, Element* el, const Flow& flow, const Array<Element*>& kids) {
|
||||
static float contentAxis(bool isX, PElement el, const Flow& flow, const Array<OElement>& kids) {
|
||||
if (flow.size() == 0) {
|
||||
return isX ? el->getIntrinsicW() : el->getIntrinsicH();
|
||||
}
|
||||
@@ -130,7 +130,7 @@ static float contentAxis(bool isX, Element* el, const Flow& flow, const Array<El
|
||||
// parent), the reference is 0 (percent sizes on a root with no containing box
|
||||
// are degenerate; the caller should use px).
|
||||
float parentContent = 0.0f;
|
||||
Element* parent = el->getParent();
|
||||
PElement parent = el->getParent();
|
||||
if (parent != nullptr) {
|
||||
if (isX) {
|
||||
parentContent = std::max(0.0f, (float)parent->getLayoutDimensions().x - (float)(parent->getStyle().paddingLeft + parent->getStyle().paddingRight));
|
||||
@@ -140,7 +140,7 @@ static float contentAxis(bool isX, Element* el, const Flow& flow, const Array<El
|
||||
}
|
||||
float m = 0.0f;
|
||||
for (size_t k = 0; k < flow.size(); k++) {
|
||||
Element* c = kids[flow[k]];
|
||||
PElement c = kids[flow[k]];
|
||||
m = std::max(m, childMainFootprint(c, isX ? Axis{true, false} : Axis{false, false}, parentContent));
|
||||
}
|
||||
float gap = (float)el->getStyle().gap;
|
||||
@@ -152,7 +152,7 @@ static float contentAxis(bool isX, Element* el, const Flow& flow, const Array<El
|
||||
|
||||
// resolve one concrete axis of the element's own size: explicit wins; Auto falls back
|
||||
// to the content measurement; min/max then clamp. Returns the final axis size.
|
||||
static float resolveAxisSize(bool isX, Element* el, float content, const Style& s) {
|
||||
static float resolveAxisSize(bool isX, PElement el, float content, const Style& s) {
|
||||
// the percent reference for this element's own size is its *parent's* box (the
|
||||
// containing block). the element's own dimensions are finalized before this is
|
||||
// called (layoutElement sets them before recursing into placeFlowChildren), so
|
||||
@@ -183,7 +183,7 @@ static float resolveAxisSize(bool isX, Element* el, float content, const Style&
|
||||
// resolves against the parent's content box on the cross axis; Auto falls back to the
|
||||
// element's intrinsic cross size. includes cross-axis margins. used for the parent's
|
||||
// Auto cross measurement (max over children) and for non-stretch item sizing.
|
||||
static float childCrossFootprint(Element* c, const FlexLayout::Axis& axis, float parentContentCross) {
|
||||
static float childCrossFootprint(PElement c, const FlexLayout::Axis& axis, float parentContentCross) {
|
||||
const Style& s = c->getStyle();
|
||||
bool isX = axis.mainIsX; // cross axis is the other one
|
||||
float size;
|
||||
@@ -214,7 +214,7 @@ static float childCrossFootprint(Element* c, const FlexLayout::Axis& axis, float
|
||||
// resolve the child's main-axis basis for flex distribution: explicit (px/%) resolves
|
||||
// against the parent's content main; Auto falls back to the child's intrinsic main.
|
||||
// does NOT include margins (those are handled separately in the layout loop).
|
||||
static float childMainBasis(Element* c, const FlexLayout::Axis& axis, float parentContentMain) {
|
||||
static float childMainBasis(PElement c, const FlexLayout::Axis& axis, float parentContentMain) {
|
||||
const Style& s = c->getStyle();
|
||||
bool isX = axis.mainIsX;
|
||||
// explicit basis (flex-basis) wins over size
|
||||
@@ -265,7 +265,7 @@ static float childMainBasis(Element* c, const FlexLayout::Axis& axis, float pare
|
||||
// apply justify (main) and align (cross), write positions. this is the core of the
|
||||
// flexbox algorithm. the element's own size is already resolved (by the caller); this
|
||||
// function only positions the children.
|
||||
static void placeFlowChildren(Element* el, const Axis& axis, const Flow& flow, const Array<Element*>& kids) {
|
||||
static void placeFlowChildren(PElement el, const Axis& axis, const Flow& flow, const Array<OElement>& kids) {
|
||||
if (flow.size() == 0) return;
|
||||
const Style& s = el->getStyle();
|
||||
// the element's content box (in the element's own coordinate space, before
|
||||
@@ -307,7 +307,7 @@ static void placeFlowChildren(Element* el, const Axis& axis, const Flow& flow, c
|
||||
std::vector<Placed> placed;
|
||||
placed.reserve(flow.size());
|
||||
for (size_t k = 0; k < flow.size(); k++) {
|
||||
Element* c = kids[flow[k]];
|
||||
PElement c = kids[flow[k]];
|
||||
const Style& cs = c->getStyle();
|
||||
Placed p{};
|
||||
p.idx = flow[k];
|
||||
@@ -482,7 +482,7 @@ static void placeFlowChildren(Element* el, const Axis& axis, const Flow& flow, c
|
||||
for (size_t k = 0; k < placed.size(); k++) {
|
||||
if (placed[k].line != ln) continue;
|
||||
Placed& p = placed[k];
|
||||
Element* c = kids[p.idx];
|
||||
PElement c = kids[p.idx];
|
||||
// main position: line start + item offset within line.
|
||||
float itemMain;
|
||||
if (firstOnLine) {
|
||||
@@ -565,8 +565,8 @@ static void placeFlowChildren(Element* el, const Axis& axis, const Flow& flow, c
|
||||
// layout one element: measure (resolve its own size + recurse to measure children),
|
||||
// then place (position flow children in the content box, handle absolute children).
|
||||
// writes `position` and `dimensions` in PARENT space (excluding margins).
|
||||
void layoutElement(Element* el, const Axis& axis) {
|
||||
const Array<Element*>& kids = el->getChildren();
|
||||
void layoutElement(PElement el, const Axis& axis) {
|
||||
const Array<OElement>& kids = el->getChildren();
|
||||
if (el->getStyle().display == Display::Hidden) {
|
||||
el->setLayout(Vector2(0), Vector2(0));
|
||||
return;
|
||||
@@ -585,7 +585,7 @@ void layoutElement(Element* el, const Axis& axis) {
|
||||
// prior layout run). for a root element (no parent), the reference is 0.
|
||||
float parentContentCross = 0.0f;
|
||||
{
|
||||
Element* parent = el->getParent();
|
||||
PElement parent = el->getParent();
|
||||
if (parent != nullptr) {
|
||||
parentContentCross = axis.mainIsX
|
||||
? std::max(0.0f, (float)parent->getLayoutDimensions().y - (float)(parent->getStyle().paddingTop + parent->getStyle().paddingBottom))
|
||||
@@ -594,7 +594,7 @@ void layoutElement(Element* el, const Axis& axis) {
|
||||
}
|
||||
float crossContent = 0.0f;
|
||||
for (size_t k = 0; k < flow.size(); k++) {
|
||||
Element* c = kids[flow[k]];
|
||||
PElement c = kids[flow[k]];
|
||||
crossContent = std::max(crossContent, childCrossFootprint(c, axis, parentContentCross));
|
||||
}
|
||||
// if there are no flow children, the cross content is the element's intrinsic cross.
|
||||
@@ -621,7 +621,7 @@ void layoutElement(Element* el, const Axis& axis) {
|
||||
// direction to determine its axis (a Row child of a Column parent has mainIsX=true
|
||||
// even though the parent has mainIsX=false).
|
||||
for (size_t k = 0; k < flow.size(); k++) {
|
||||
Element* c = kids[flow[k]];
|
||||
PElement c = kids[flow[k]];
|
||||
const Style& css = c->getStyle();
|
||||
bool cIsX = (css.direction == FlexDirection::Row || css.direction == FlexDirection::RowReverse);
|
||||
Axis childAxis{cIsX, cIsX ? (css.direction == FlexDirection::RowReverse) : (css.direction == FlexDirection::ColumnReverse)};
|
||||
@@ -631,7 +631,7 @@ void layoutElement(Element* el, const Axis& axis) {
|
||||
// content-box corner. measure them (so their own children are laid out), then
|
||||
// position by left/top offsets (right/bottom are not supported).
|
||||
for (size_t i = 0; i < kids.size(); i++) {
|
||||
Element* c = kids[i];
|
||||
PElement c = kids[i];
|
||||
if (c == nullptr || c->getStyle().display == Display::Hidden) continue;
|
||||
if (c->getStyle().position != Position::Absolute) continue;
|
||||
const Style& css = c->getStyle();
|
||||
@@ -655,7 +655,10 @@ void layoutElement(Element* el, const Axis& axis) {
|
||||
for (size_t i = 0; i < kids.size(); i++) {
|
||||
if (kids[i] == nullptr) continue;
|
||||
if (kids[i]->getStyle().display == Display::Hidden) {
|
||||
kids[i]->setLayout(Vector2(0), Vector2(0));
|
||||
// raw pointers can be modified inside a const Array<>&, but RefPtr imposes const-ness also for the elements
|
||||
// this side-steps the issue by creating a non-const RefPtr copy
|
||||
PElement kid = kids[i];
|
||||
kid->setLayout(Vector2(0), Vector2(0));
|
||||
}
|
||||
}
|
||||
// place flow children in the content box: compute per-line packing, apply
|
||||
@@ -666,7 +669,7 @@ void layoutElement(Element* el, const Axis& axis) {
|
||||
// here, so its own grandchildren were laid out relative to a stale position.
|
||||
// Re-run each container child's placement now that the parent position is final.
|
||||
for (size_t k = 0; k < flow.size(); k++) {
|
||||
Element* c = kids[flow[k]];
|
||||
PElement c = kids[flow[k]];
|
||||
if (c->getChildren().size() == 0) continue;
|
||||
const Style& css = c->getStyle();
|
||||
if (css.position == Position::Absolute) continue;
|
||||
@@ -674,7 +677,7 @@ void layoutElement(Element* el, const Axis& axis) {
|
||||
Axis childAxis{cIsX, cIsX ? (css.direction == FlexDirection::RowReverse) : (css.direction == FlexDirection::ColumnReverse)};
|
||||
Flow cf;
|
||||
Flow::build(c, cf);
|
||||
const Array<Element*>& cKids = c->getChildren();
|
||||
const Array<OElement>& cKids = c->getChildren();
|
||||
placeFlowChildren(c, childAxis, cf, cKids);
|
||||
}
|
||||
}
|
||||
@@ -682,7 +685,7 @@ void layoutElement(Element* el, const Axis& axis) {
|
||||
// the public entry point: set the root's dimensions to the viewport, then run the
|
||||
// full layout. the root has no parent, so its percent sizes are degenerate (0) —
|
||||
// the root should use explicit (px) or Auto sizes.
|
||||
void layoutRoot(Element* root, UVector2 viewport) {
|
||||
void layoutRoot(PElement root, UVector2 viewport) {
|
||||
if (root == nullptr) return;
|
||||
// the root's dimensions are the viewport (the root IS the viewport's content).
|
||||
// the root has no parent, so resolveAxisSize will treat its percent sizes as 0
|
||||
@@ -739,7 +742,7 @@ void layoutRoot(Element* root, UVector2 viewport) {
|
||||
// does *except* re-resolving the root's own size (which would use a null parent
|
||||
// and a 0 percent reference, wrong for the root).
|
||||
Axis axis{isX, isX ? (s.direction == FlexDirection::RowReverse) : (s.direction == FlexDirection::ColumnReverse)};
|
||||
const Array<Element*>& kids = root->getChildren();
|
||||
const Array<OElement>& kids = root->getChildren();
|
||||
if (root->getStyle().display == Display::Hidden) {
|
||||
root->setLayout(Vector2(0), Vector2(0));
|
||||
return;
|
||||
@@ -750,19 +753,21 @@ void layoutRoot(Element* root, UVector2 viewport) {
|
||||
for (size_t i = 0; i < kids.size(); i++) {
|
||||
if (kids[i] == nullptr) continue;
|
||||
if (kids[i]->getStyle().display == Display::Hidden) {
|
||||
kids[i]->setLayout(Vector2(0), Vector2(0));
|
||||
// modifyable copyied refptr, something you can do with raw pointers natively
|
||||
PElement kid = kids[i];
|
||||
kid->setLayout(Vector2(0), Vector2(0));
|
||||
}
|
||||
}
|
||||
// measure the flow children (recursively) and the absolute children.
|
||||
for (size_t k = 0; k < flow.size(); k++) {
|
||||
Element* c = kids[flow[k]];
|
||||
PElement c = kids[flow[k]];
|
||||
const Style& css = c->getStyle();
|
||||
bool cIsX = (css.direction == FlexDirection::Row || css.direction == FlexDirection::RowReverse);
|
||||
Axis childAxis{cIsX, cIsX ? (css.direction == FlexDirection::RowReverse) : (css.direction == FlexDirection::ColumnReverse)};
|
||||
layoutElement(c, childAxis);
|
||||
}
|
||||
for (size_t i = 0; i < kids.size(); i++) {
|
||||
Element* c = kids[i];
|
||||
PElement c = kids[i];
|
||||
if (c == nullptr || c->getStyle().display == Display::Hidden) continue;
|
||||
if (c->getStyle().position != Position::Absolute) continue;
|
||||
const Style& css = c->getStyle();
|
||||
@@ -779,7 +784,7 @@ void layoutRoot(Element* root, UVector2 viewport) {
|
||||
// Same fix as in layoutElement: container children were measured before their
|
||||
// position was set, so re-run their placement with the now-final position.
|
||||
for (size_t k = 0; k < flow.size(); k++) {
|
||||
Element* c = kids[flow[k]];
|
||||
PElement c = kids[flow[k]];
|
||||
if (c->getChildren().size() == 0) continue;
|
||||
const Style& css = c->getStyle();
|
||||
if (css.position == Position::Absolute) continue;
|
||||
@@ -787,7 +792,7 @@ void layoutRoot(Element* root, UVector2 viewport) {
|
||||
Axis childAxis{cIsX, cIsX ? (css.direction == FlexDirection::RowReverse) : (css.direction == FlexDirection::ColumnReverse)};
|
||||
Flow cf;
|
||||
Flow::build(c, cf);
|
||||
const Array<Element*>& cKids = c->getChildren();
|
||||
const Array<OElement>& cKids = c->getChildren();
|
||||
placeFlowChildren(c, childAxis, cf, cKids);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace Seele {
|
||||
namespace UI {
|
||||
// forward decl: the full class lives in `UI/Element.h` (which includes this header).
|
||||
// only used as a pointer/reference here, so the forward decl is sufficient.
|
||||
class Element;
|
||||
DECLARE_REF(Element)
|
||||
namespace FlexLayout {
|
||||
// one flex container's resolved main/cross geometry, passed down the recursion.
|
||||
// `mainIsX` is true for row/row-reverse (main axis = x). `cMain`/`cCross` are the
|
||||
@@ -62,7 +62,7 @@ struct Axis {
|
||||
|
||||
// per-item scratch, indexed by position in `items` (the order-sorted flow list).
|
||||
struct Item {
|
||||
Element* el = nullptr;
|
||||
PElement el = nullptr;
|
||||
int32 order = 0;
|
||||
float basis = 0.f; // main size before grow/shrink (min/max clamped)
|
||||
float grow = 0.f, shrink = 1.f;
|
||||
@@ -82,7 +82,7 @@ struct Item {
|
||||
// viewport at the root). Resolves the element's own main/cross size (measure), then
|
||||
// lays out its children (place), recursing into each flow child with the child's
|
||||
// *own* resolved size as its containing box.
|
||||
void layoutElement(Element* el, const Axis& axis);
|
||||
void layoutElement(PElement el, const Axis& axis);
|
||||
|
||||
// public entry: lay out the whole tree. `root` is the viewport's only child; the
|
||||
// viewport's dimensions are `viewport`. `root->position` is left untouched (the
|
||||
@@ -91,7 +91,7 @@ void layoutElement(Element* el, const Axis& axis);
|
||||
// declared here, defined in FlexLayout.cpp (the body dereferences `root->style`,
|
||||
// which needs the complete Element type — not available in this header, which only
|
||||
// forward-declares Element to avoid a circular include with Element.h).
|
||||
void layoutRoot(Element* root, UVector2 viewport);
|
||||
void layoutRoot(PElement root, UVector2 viewport);
|
||||
} // namespace FlexLayout
|
||||
} // namespace UI
|
||||
} // namespace Seele
|
||||
+15
-15
@@ -6,7 +6,7 @@
|
||||
using namespace Seele;
|
||||
using namespace Seele::UI;
|
||||
|
||||
void System::markAllDirty(Element* element) {
|
||||
void System::markAllDirty(PElement element) {
|
||||
if (element == nullptr) {
|
||||
return;
|
||||
}
|
||||
@@ -17,7 +17,7 @@ void System::markAllDirty(Element* element) {
|
||||
}
|
||||
}
|
||||
|
||||
void System::styleRec(Element* element) {
|
||||
void System::styleRec(PElement element) {
|
||||
if (element == nullptr) {
|
||||
return;
|
||||
}
|
||||
@@ -25,7 +25,7 @@ void System::styleRec(Element* element) {
|
||||
// theme change (fonts are per-theme) without a friend declaration.
|
||||
element->setTheme(theme);
|
||||
// runtime interaction state overrides the static style (data, not template args)
|
||||
if (auto* button = dynamic_cast<Button<>* >(element)) {
|
||||
if (auto* button = dynamic_cast<Button<>*>(element.getHandle())) {
|
||||
if (button->isFocused()) {
|
||||
element->style.backgroundColor = theme.color(ColorToken::Gray700);
|
||||
}
|
||||
@@ -41,7 +41,7 @@ void System::styleRec(Element* element) {
|
||||
element->themeChanged = false;
|
||||
element->applyStyle({}, theme);
|
||||
// interaction state is a per-frame override; re-apply it after the static resolve
|
||||
if (auto* button = dynamic_cast<Button<>* >(element)) {
|
||||
if (auto* button = dynamic_cast<Button<>* >(element.getHandle())) {
|
||||
if (button->isFocused()) {
|
||||
element->style.backgroundColor = theme.color(ColorToken::Gray700);
|
||||
}
|
||||
@@ -59,23 +59,23 @@ void System::styleRec(Element* element) {
|
||||
}
|
||||
}
|
||||
|
||||
Element* System::hitTest(Vector2 position) {
|
||||
PElement System::hitTest(Vector2 position) {
|
||||
// walk the last rendered list; later entries are drawn on top, so the last
|
||||
// hit is the top-most element
|
||||
Element* result = nullptr;
|
||||
PElement result = nullptr;
|
||||
for (auto& render : renderElements) {
|
||||
if (render.element == nullptr) {
|
||||
continue;
|
||||
}
|
||||
if (position.x >= render.position.x && position.x < render.position.x + render.dimensions.x &&
|
||||
position.y >= render.position.y && position.y < render.position.y + render.dimensions.y) {
|
||||
result = render.element.operator->();
|
||||
result = render.element;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void System::collectFocusable(Element* element, Array<Element*>& out) {
|
||||
void System::collectFocusable(PElement element, Array<PElement>& out) {
|
||||
if (element == nullptr || element->style.display == Display::Hidden) {
|
||||
return;
|
||||
}
|
||||
@@ -89,13 +89,13 @@ void System::collectFocusable(Element* element, Array<Element*>& out) {
|
||||
|
||||
void System::processInput() {
|
||||
// hover transitions: the virtual setHovered keeps this free of dynamic_cast
|
||||
Element* under = hitTest(mousePos);
|
||||
PElement under = hitTest(mousePos);
|
||||
if (under != hovered) {
|
||||
if (hovered) {
|
||||
if (hovered != nullptr) {
|
||||
hovered->setHovered(false);
|
||||
}
|
||||
hovered = under;
|
||||
if (hovered) {
|
||||
if (hovered != nullptr) {
|
||||
hovered->setHovered(true);
|
||||
}
|
||||
}
|
||||
@@ -107,7 +107,7 @@ void System::mouseMove(Vector2 position) {
|
||||
|
||||
void System::mouseButton(MouseButton button, InputAction action, KeyModifier, Vector2 position) {
|
||||
mousePos = position;
|
||||
Element* under = hitTest(position);
|
||||
PElement under = hitTest(position);
|
||||
if (under == nullptr) {
|
||||
return;
|
||||
}
|
||||
@@ -115,7 +115,7 @@ void System::mouseButton(MouseButton button, InputAction action, KeyModifier, Ve
|
||||
Vector2 local = position;
|
||||
{
|
||||
// walk up from the hit element, subtracting each parent's position
|
||||
auto* walk = under;
|
||||
auto walk = under;
|
||||
while (walk != nullptr) {
|
||||
local.x -= walk->position.x;
|
||||
local.y -= walk->position.y;
|
||||
@@ -131,7 +131,7 @@ void System::mouseButton(MouseButton button, InputAction action, KeyModifier, Ve
|
||||
}
|
||||
|
||||
void System::scroll(Vector2 delta) {
|
||||
Element* under = hitTest(mousePos);
|
||||
PElement under = hitTest(mousePos);
|
||||
if (under == nullptr) {
|
||||
return;
|
||||
}
|
||||
@@ -154,7 +154,7 @@ void System::key(KeyCode code, InputAction action, KeyModifier modifier, char te
|
||||
if (action == InputAction::PRESS && code == KeyCode::KEY_TAB) {
|
||||
// cycle focus among focusable elements (buttons); the virtual setFocused
|
||||
// keeps this free of dynamic_cast to a concrete template type
|
||||
Array<Element*> focusable;
|
||||
Array<PElement> focusable;
|
||||
collectFocusable(rootElement.operator->(), focusable);
|
||||
if (focusable.size() > 0) {
|
||||
int32 index = -1;
|
||||
|
||||
@@ -39,12 +39,12 @@ class System {
|
||||
PElement getRoot() { return rootElement; }
|
||||
|
||||
private:
|
||||
void styleRec(Element* element);
|
||||
static void markAllDirty(Element* element);
|
||||
void styleRec(PElement element);
|
||||
static void markAllDirty(PElement element);
|
||||
// hit-test the last rendered list, top-most wins; returns the element under `position`
|
||||
Element* hitTest(Vector2 position);
|
||||
PElement hitTest(Vector2 position);
|
||||
// walks the tree in layout order, collecting focusable elements (for tab navigation)
|
||||
void collectFocusable(Element* element, Array<Element*>& out);
|
||||
void collectFocusable(PElement element, Array<PElement>& out);
|
||||
|
||||
OElement rootElement;
|
||||
Theme theme;
|
||||
@@ -52,8 +52,8 @@ class System {
|
||||
bool layoutDirty = true;
|
||||
// input state
|
||||
Vector2 mousePos = Vector2(0);
|
||||
Element* hovered = nullptr;
|
||||
Element* focused = nullptr;
|
||||
PElement hovered = nullptr;
|
||||
PElement focused = nullptr;
|
||||
Array<UIRender> renderElements;
|
||||
};
|
||||
DEFINE_REF(System)
|
||||
|
||||
Reference in new issue
Block a user