Correct way to sustain Origin
behaviour while having transformations applied from a different axis
#6431
-
I have a new button class
(unsure if it needs to be bound to OnLoadComplete, but it felt like the safest bet to ensure I don't use a width which is incorrect or null due to the drawable not being loaded fully.) This works obviously, but it feels kinda weird and janky to me, so is there a better way to accomplish this? Any advice would be appreciated, and let me know if I need to attach .cs files or anything. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Code for reference: https://github.com/approachcircle/Blackjack/blob/511fdd33c827d438528ce0f24073a59f81131659/Blackjack/Blackjack.Game/FlashingButton.cs As far as I can gather, the issue is related to autosize. When the flashing box comes visible, it starts contributing to the autosize layout of the button causing it to become bigger as a whole. The best guidance I have to fix this is to prefer public partial class BlackjackButton : ClickableContainer
private void load()
{
disabledColour = Colour4.DarkGray.Darken(1);
- Masking = true;
- CornerRadius = 5;
- AutoSizeAxes = Axes.Both;
- InternalChildren =
- [
- new Box
- {
- Anchor = Anchor.Centre,
- Origin = Anchor.Centre,
- Size = ButtonSize,
- Colour = BackgroundColour
- },
- new SpriteText
- {
- Anchor = Anchor.Centre,
- Origin = Anchor.Centre,
- Text = Text,
- Font = FontUsage.Default.With(size: 20),
- }
- ];
+ Size = ButtonSize;
+ InternalChild = new Container
+ {
+ RelativeSizeAxes = Axes.Both,
+ Masking = true,
+ CornerRadius = 5,
+ Children =
+ [
+ new Box
+ {
+ RelativeSizeAxes = Axes.Both,
+ Colour = BackgroundColour
+ },
+ new SpriteText
+ {
+ Anchor = Anchor.Centre,
+ Origin = Anchor.Centre,
+ Text = Text,
+ Font = FontUsage.Default.With(size: 20),
+ }
+ ]
+ };
Enabled.BindValueChanged(e =>
{
Colour = e.NewValue ? Colour4.White : disabledColour;
As for It's not required, but you could also remove |
Beta Was this translation helpful? Give feedback.
Code for reference: https://github.com/approachcircle/Blackjack/blob/511fdd33c827d438528ce0f24073a59f81131659/Blackjack/Blackjack.Game/FlashingButton.cs
As far as I can gather, the issue is related to autosize. When the flashing box comes visible, it starts contributing to the autosize layout of the button causing it to become bigger as a whole.
The best guidance I have to fix this is to prefer
RelativeSizeAxes
when possible and move the masking to an inner layer, as so: