Skip to content

Commit

Permalink
Merge branch 'lua_ui_focus_loss' into 'master'
Browse files Browse the repository at this point in the history
Work around MyGUI bug in a less destructive way

See merge request OpenMW/openmw!3511
  • Loading branch information
petrmikheev committed Oct 24, 2023
2 parents 31f5c88 + 6081dcc commit 26ff56f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 12 additions & 8 deletions components/lua_ui/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,28 @@ namespace LuaUi
w->widget()->detachFromWidget();
}

void WidgetExtension::updateVisible()
{
// workaround for MyGUI bug
// parent visibility doesn't affect added children
MyGUI::Widget* widget = this->widget();
MyGUI::Widget* parent = widget->getParent();
bool inheritedVisible = widget->getVisible() && (parent == nullptr || parent->getInheritedVisible());
widget->setVisible(inheritedVisible);
}

void WidgetExtension::attach(WidgetExtension* ext)
{
ext->mParent = this;
ext->mTemplateChild = false;
ext->widget()->attachToWidget(mSlot->widget());
// workaround for MyGUI bug
// parent visibility doesn't affect added children
ext->widget()->setVisible(!ext->widget()->getVisible());
ext->widget()->setVisible(!ext->widget()->getVisible());
}

void WidgetExtension::attachTemplate(WidgetExtension* ext)
{
ext->mParent = this;
ext->mTemplateChild = true;
ext->widget()->attachToWidget(widget());
// workaround for MyGUI bug
// parent visibility doesn't affect added children
ext->widget()->setVisible(!ext->widget()->getVisible());
ext->widget()->setVisible(!ext->widget()->getVisible());
}

WidgetExtension* WidgetExtension::findDeep(std::string_view flagName)
Expand Down Expand Up @@ -256,6 +258,8 @@ namespace LuaUi

void WidgetExtension::updateCoord()
{
updateVisible();

MyGUI::IntCoord oldCoord = mWidget->getCoord();
MyGUI::IntCoord newCoord = calculateCoord();

Expand Down
2 changes: 2 additions & 0 deletions components/lua_ui/widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ namespace LuaUi
void focusLoss(MyGUI::Widget*, MyGUI::Widget*);

std::optional<std::function<void(WidgetExtension*, MyGUI::IntCoord)>> mOnCoordChange;

void updateVisible();
};

class LuaWidget : public MyGUI::Widget, public WidgetExtension
Expand Down

0 comments on commit 26ff56f

Please sign in to comment.