You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working on some extension methods in MonoGame.Extended for the MonoGame implementation of Gum. The Button class by default uses a ColoredRectangleRuntime as for the background, so I wanted to make an extension method to easily change it without the user having to create a full custom control. However, when changing the child element from a ColorRectangleRuntime to a NineSliceRuntime by setting it in the index directly, it does not render properly.
Reproduction
To recreate this, you can use the following extension method
publicstatic NineSliceRuntime UseNinePatch(thisButtonbutton,Texture2Dtexture){if(button.Visual.GetChildByName("ButtonBackground")is IRenderableIpso child){NineSliceRuntimenineSlice=new NineSliceRuntime();
nineSlice.Width =0;
nineSlice.Height =0;
nineSlice.WidthUnits = DimensionUnitType.RelativeToContainer;
nineSlice.HeightUnits = DimensionUnitType.RelativeToContainer;
nineSlice.Name ="ButtonBackground";
nineSlice.SourceFile =texture;intindex= button.Visual.Children.IndexOf(child);// Setting directly by index here causes the issue
button.Visual.Children[index]=nineSlice;returnnineSlice;}returnnull;}
Workaround
Instead of setting the child directly by index as shown above, you can instead remove the child then insert the new element at the same index and it works as expected
publicstatic NineSliceRuntime UseNinePatch(thisButtonbutton,Texture2Dtexture){if(button.Visual.GetChildByName("ButtonBackground")is IRenderableIpso child){NineSliceRuntimenineSlice=new NineSliceRuntime();
nineSlice.Width =0;
nineSlice.Height =0;
nineSlice.WidthUnits = DimensionUnitType.RelativeToContainer;
nineSlice.HeightUnits = DimensionUnitType.RelativeToContainer;
nineSlice.Name ="ButtonBackground";
nineSlice.SourceFile =texture;intindex= button.Visual.Children.IndexOf(child);// Remove the old child and then insert the new one at the same index works
button.Visual.Children.RemoveAt(index);
button.Visual.Children.Insert(index, nineSlice);returnnineSlice;}returnnull;}
The text was updated successfully, but these errors were encountered:
Description
I'm working on some extension methods in MonoGame.Extended for the MonoGame implementation of Gum. The
Button
class by default uses aColoredRectangleRuntime
as for the background, so I wanted to make an extension method to easily change it without the user having to create a full custom control. However, when changing the child element from aColorRectangleRuntime
to aNineSliceRuntime
by setting it in the index directly, it does not render properly.Reproduction
To recreate this, you can use the following extension method
Workaround
Instead of setting the child directly by index as shown above, you can instead remove the child then insert the new element at the same index and it works as expected
The text was updated successfully, but these errors were encountered: