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: 2 additions & 0 deletions src/framework/luafunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,8 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIWidget>("getPaddingRect", &UIWidget::getPaddingRect);
g_lua.bindClassMemberFunction<UIWidget>("getChildrenRect", &UIWidget::getChildrenRect);
g_lua.bindClassMemberFunction<UIWidget>("getAnchoredLayout", &UIWidget::getAnchoredLayout);
g_lua.bindClassMemberFunction<UIWidget>("getAnchors", &UIWidget::getAnchors);
g_lua.bindClassMemberFunction<UIWidget>("getAnchorType", &UIWidget::getAnchorType);
g_lua.bindClassMemberFunction<UIWidget>("getRootParent", &UIWidget::getRootParent);
g_lua.bindClassMemberFunction<UIWidget>("getChildAfter", &UIWidget::getChildAfter);
g_lua.bindClassMemberFunction<UIWidget>("getChildBefore", &UIWidget::getChildBefore);
Expand Down
2 changes: 2 additions & 0 deletions src/framework/ui/uianchorlayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class UIAnchorLayout : public UILayout

bool isUIAnchorLayout() override { return true; }

auto getAnchorsGroup() const { return m_anchorsGroups; }

protected:
bool internalUpdate() override;
virtual bool updateWidget(const UIWidgetPtr& widget, const UIAnchorGroupPtr& anchorGroup, UIWidgetPtr first = nullptr);
Expand Down
34 changes: 34 additions & 0 deletions src/framework/ui/uiwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,40 @@ UIAnchorLayoutPtr UIWidget::getAnchoredLayout()
return nullptr;
}

UIAnchorList UIWidget::getAnchorsGroup() {
if (const auto& layout = getAnchoredLayout()) {
const auto& self = static_self_cast<UIWidget>();
if (layout->hasAnchors(self)) {
const auto& anchors = layout->getAnchorsGroup()[self]->getAnchors();
return anchors;
}
}

return {};
}

std::vector<Fw::AnchorEdge> UIWidget::getAnchors() {
const auto& anchors = getAnchorsGroup();
std::vector<Fw::AnchorEdge> anchorsVec;
anchorsVec.reserve(anchors.size());
for (const auto& anchor : anchors) {
anchorsVec.emplace_back(anchor->getAnchoredEdge());
}

return anchorsVec;
}

Fw::AnchorEdge UIWidget::getAnchorType(Fw::AnchorEdge anchorType) {
const auto& anchors = getAnchorsGroup();
for (const auto& anchor : anchors) {
if (anchor->getAnchoredEdge() == anchorType) {
return anchor->getHookedEdge();
}
}

return Fw::AnchorNone;
}

UIWidgetPtr UIWidget::getRootParent()
{
if (const auto& parent = getParent())
Expand Down
3 changes: 3 additions & 0 deletions src/framework/ui/uiwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ class UIWidget : public LuaObject
Rect getMarginRect();
Rect getChildrenRect();
UIAnchorLayoutPtr getAnchoredLayout();
UIAnchorList getAnchorsGroup();
std::vector<Fw::AnchorEdge> getAnchors();
Fw::AnchorEdge getAnchorType(Fw::AnchorEdge anchorType);
bool hasAnchoredLayout() { return getAnchoredLayout() != nullptr; }
UIWidgetPtr getRootParent();
UIWidgetPtr getNextWidget() {
Expand Down