mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-03 07:39:41 +00:00
Render text and images correctly in templates with slots
This commit is contained in:
parent
e092ee2624
commit
fc50724f5c
9 changed files with 30 additions and 20 deletions
|
@ -283,7 +283,7 @@ namespace MWLua
|
|||
{
|
||||
LuaUi::TextureData data;
|
||||
sol::object path = LuaUtil::getFieldOrNil(options, "path");
|
||||
if (path.is<std::string>() and !path.as<std::string>().empty())
|
||||
if (path.is<std::string>() && !path.as<std::string>().empty())
|
||||
data.mPath = path.as<std::string>();
|
||||
else
|
||||
throw sol::error("Invalid texture path");
|
||||
|
|
|
@ -130,8 +130,7 @@ namespace LuaUi
|
|||
|
||||
void updateWidget(WidgetExtension* ext, const sol::table& layout)
|
||||
{
|
||||
ext->resetSlot(); // otherwise if template gets changed, all non-template children will get destroyed
|
||||
|
||||
ext->reset();
|
||||
ext->setLayout(layout);
|
||||
ext->setExternal(layout.get<sol::object>(LayoutKeys::external));
|
||||
setTemplate(ext, layout.get<sol::object>(LayoutKeys::templateLayout));
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace LuaUi
|
|||
mTileSize.height = 1e7;
|
||||
}
|
||||
|
||||
LuaImage::LuaImage()
|
||||
void LuaImage::initialize()
|
||||
{
|
||||
changeWidgetSkin("LuaImage");
|
||||
mTileRect = dynamic_cast<LuaTileRect*>(getSubWidgetMain());
|
||||
|
|
|
@ -25,10 +25,8 @@ namespace LuaUi
|
|||
{
|
||||
MYGUI_RTTI_DERIVED(LuaImage)
|
||||
|
||||
public:
|
||||
LuaImage();
|
||||
|
||||
protected:
|
||||
void initialize() override;
|
||||
void updateProperties() override;
|
||||
LuaTileRect* mTileRect;
|
||||
};
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace LuaUi
|
|||
|
||||
void LuaText::initialize()
|
||||
{
|
||||
changeWidgetSkin("SandText");
|
||||
changeWidgetSkin("LuaText");
|
||||
setEditStatic(true);
|
||||
setVisibleHScroll(false);
|
||||
setVisibleVScroll(false);
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace LuaUi
|
|||
{
|
||||
void LuaTextEdit::initialize()
|
||||
{
|
||||
changeWidgetSkin("LuaTextEdit");
|
||||
changeWidgetSkin("LuaText");
|
||||
|
||||
eventEditTextChange += MyGUI::newDelegate(this, &LuaTextEdit::textChange);
|
||||
|
||||
|
|
|
@ -24,9 +24,8 @@ namespace LuaUi
|
|||
{
|
||||
mLua = lua;
|
||||
mWidget = self;
|
||||
updateTemplate();
|
||||
|
||||
initialize();
|
||||
updateTemplate();
|
||||
}
|
||||
|
||||
void WidgetExtension::initialize()
|
||||
|
@ -72,6 +71,13 @@ namespace LuaUi
|
|||
w->deinitialize();
|
||||
}
|
||||
|
||||
void WidgetExtension::reset()
|
||||
{
|
||||
// detach all children from the slot widget, in case it gets destroyed
|
||||
for (auto& w: mChildren)
|
||||
w->widget()->detachFromWidget();
|
||||
}
|
||||
|
||||
void WidgetExtension::attach(WidgetExtension* ext)
|
||||
{
|
||||
ext->mParent = this;
|
||||
|
@ -182,8 +188,15 @@ namespace LuaUi
|
|||
else
|
||||
mSlot = slot->mSlot;
|
||||
if (mSlot != oldSlot)
|
||||
for (WidgetExtension* w : mChildren)
|
||||
attach(w);
|
||||
{
|
||||
MyGUI::IntSize slotSize = mSlot->widget()->getSize();
|
||||
MyGUI::IntPoint slotPosition = mSlot->widget()->getAbsolutePosition() - widget()->getAbsolutePosition();
|
||||
MyGUI::IntCoord slotCoord(slotPosition, slotSize);
|
||||
if (mWidget->getSubWidgetMain())
|
||||
mWidget->getSubWidgetMain()->setCoord(slotCoord);
|
||||
if (mWidget->getSubWidgetText())
|
||||
mWidget->getSubWidgetText()->setCoord(slotCoord);
|
||||
}
|
||||
}
|
||||
|
||||
void WidgetExtension::setCallback(const std::string& name, const LuaUtil::Callback& callback)
|
||||
|
|
|
@ -28,6 +28,9 @@ namespace LuaUi
|
|||
virtual void deinitialize();
|
||||
|
||||
MyGUI::Widget* widget() const { return mWidget; }
|
||||
WidgetExtension* slot() const { return mSlot; }
|
||||
|
||||
void reset();
|
||||
|
||||
const std::vector<WidgetExtension*>& children() { return mChildren; }
|
||||
void setChildren(const std::vector<WidgetExtension*>&);
|
||||
|
@ -50,7 +53,6 @@ namespace LuaUi
|
|||
|
||||
const sol::table& getLayout() { return mLayout; }
|
||||
void setLayout(const sol::table& layout) { mLayout = layout; }
|
||||
void resetSlot() { mSlot = this; }
|
||||
|
||||
template <typename T>
|
||||
T externalValue(std::string_view name, const T& defaultValue)
|
||||
|
|
|
@ -4,12 +4,10 @@
|
|||
<Resource type="ResourceSkin" name="LuaImage">
|
||||
<BasisSkin type="LuaTileRect"/>
|
||||
</Resource>
|
||||
|
||||
<Resource type="ResourceSkin" name="LuaTextEdit" size="512 20">
|
||||
<Property key="FontName" value="Default"/>
|
||||
<Property key="TextAlign" value="Left VCenter"/>
|
||||
<Property key="TextColour" value="#{fontcolour=normal}"/>
|
||||
|
||||
<Child type="TextBox" skin="MW_TextEditClient" offset="0 0 502 20" align="Stretch" name="Client"/>
|
||||
<Resource type="ResourceSkin" name="LuaText" size="16 16">
|
||||
<Property key="FontName" value="Default"/>
|
||||
<Property key="TextAlign" value="Left Top"/>
|
||||
<BasisSkin type="SimpleText" offset="0 0 16 16" align="Stretch" />
|
||||
</Resource>
|
||||
</MyGUI>
|
Loading…
Reference in a new issue