Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion engine/includes/components/transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ENGINE_EXPORT Transform : public Component {
void setScale(const Vector3 scale);

Transform *parentTransform() const;
void setParentTransform(Transform *parent, bool force = false);
virtual void setParentTransform(Transform *parent, bool force = false);

const Matrix4 &localTransform() const;
const Matrix4 &worldTransform() const;
Expand Down
2 changes: 2 additions & 0 deletions modules/uikit/includes/components/recttransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class UIKIT_EXPORT RectTransform : public Transform {

Vector4 scissorArea() const;

void setParentTransform(Transform *parent, bool force = false) override;

private:
friend class Layout;

Expand Down
2 changes: 0 additions & 2 deletions modules/uikit/includes/components/widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ class UIKIT_EXPORT Widget : public NativeBehaviour {

void setRectTransform(RectTransform *transform);

void onReferenceDestroyed() override;

void actorParentChanged() override;

void composeComponent() override;
Expand Down
29 changes: 19 additions & 10 deletions modules/uikit/src/components/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ void Layout::insertLayout(int index, Layout *layout) {
if(m_rectTransform) {
m_rectTransform->recalcParent();
}

update();
}
}
/*!
Expand All @@ -68,6 +70,11 @@ void Layout::insertLayout(int index, Layout *layout) {
*/
void Layout::insertTransform(int index, RectTransform *transform) {
if(transform) {
if(transform->m_attachedLayout) {
transform->m_attachedLayout->removeTransform(transform);
transform->m_attachedLayout = nullptr;
}

Layout *layout = new Layout;
layout->m_attachedTransform = transform;
layout->m_attachedTransform->setAnchors(Vector2(0.0f, 1.0f), Vector2(0.0f, 1.0f));
Expand All @@ -87,18 +94,20 @@ void Layout::removeLayout(Layout *layout) {
Removes a \a transform from the current layout.
*/
void Layout::removeTransform(RectTransform *transform) {
for(auto it : m_items) {
if(it->m_attachedTransform == transform) {
Layout *tmp = it;
m_items.remove(tmp);
delete tmp;
invalidate();
if(transform) {
for(auto it : m_items) {
if(it->m_attachedTransform == transform) {
Layout *tmp = it;
m_items.remove(tmp);
delete tmp;
invalidate();

if(m_rectTransform) {
m_rectTransform->recalcParent();
}
if(m_rectTransform) {
m_rectTransform->recalcParent();
}

break;
break;
}
}
}
}
Expand Down
38 changes: 34 additions & 4 deletions modules/uikit/src/components/recttransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,22 +278,47 @@ void RectTransform::setEnabled(bool enabled) {
rect->recalcParent();
}
}

/*!
Returns vertical size policy.
*/
RectTransform::SizePolicy RectTransform::verticalPolicy() const {
return m_verticalPolicy;
}

/*!
Sets vertical size \a policy.
*/
void RectTransform::setVerticalPolicy(SizePolicy policy) {
m_verticalPolicy = policy;
}

/*!
Returns horizontal size policy.
*/
RectTransform::SizePolicy RectTransform::horizontalPolicy() const {
return m_horizontalPolicy;
}

/*!
Sets horizontal size \a policy.
*/
void RectTransform::setHorizontalPolicy(SizePolicy policy) {
m_horizontalPolicy = policy;
}
/*!
Changing the \a parent will modify the parent-relative position, scale and rotation but keep the world space position, rotation and scale the same.
In case of \a force flag provided as true, no recalculations of transform happen.

In addition adds current transfrom to the parent layout if it exists.
*/
void RectTransform::setParentTransform(Transform *parent, bool force) {
Transform::setParentTransform(parent, force);

RectTransform *parentRect = dynamic_cast<RectTransform *>(m_parent);
if(parentRect) {
Layout *layout = parentRect->layout();
if(layout) {
layout->addTransform(this);
}
}
}
/*!
\internal
Cleans the dirty state of the RectTransform and updates the world transformation matrix.
Expand Down Expand Up @@ -391,6 +416,11 @@ void RectTransform::recalcChilds() const {
m_layout->update();
}

if(m_attachedLayout) {
m_attachedLayout->invalidate();
m_attachedLayout->update();
}

m_dirty = true;
}

Expand Down
37 changes: 18 additions & 19 deletions modules/uikit/src/components/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ Widget::~Widget() {
if(m_transform) {
m_transform->unsubscribe(this);
}

for(auto it : m_childWidgets) {
it->m_parent = nullptr;
}

for(auto it : m_subWidgets) {
it->m_parent = nullptr;
}

if(m_parent) {
m_parent->m_childWidgets.remove(this);
m_parent->m_subWidgets.remove(this);
}

static_cast<UiSystem *>(system())->removeWidget(this);
}
/*!
Expand Down Expand Up @@ -207,13 +221,14 @@ void Widget::applyStyle() {
}

m_transform->setLayout(layout);

for(auto it : m_childWidgets) {
layout->addTransform(it->rectTransform());
}
}
}

for(auto it : m_childWidgets) {
if(layout) {
layout->addTransform(it->rectTransform());
}
it->applyStyle();
}

Expand Down Expand Up @@ -272,15 +287,11 @@ void Widget::setSubWidget(Widget *widget) {
if(current) {
m_subWidgets.remove(current);
m_childWidgets.push_back(current);

disconnect(current, _SIGNAL(destroyed()), this, _SLOT(onReferenceDestroyed()));
}

if(widget) {
m_subWidgets.push_back(widget);
m_childWidgets.remove(widget);

connect(widget, _SIGNAL(destroyed()), this, _SLOT(onReferenceDestroyed()));
}
}
}
Expand Down Expand Up @@ -314,18 +325,6 @@ void Widget::setParent(Object *parent, int32_t position, bool force) {

actorParentChanged();
}
/*!
\internal
Internal slot method called when a referenced object is destroyed.
*/
void Widget::onReferenceDestroyed() {
Widget *widget = dynamic_cast<Widget *>(sender());

if(widget) {
m_childWidgets.remove(widget);
m_subWidgets.remove(widget);
}
}
/*!
\internal
Internal method called when the parent actor of the widget changes.
Expand Down
Loading