mirror of https://github.com/ppy/osu
Bind axis checkbox disabled state to CanScaleX/Y
This commit is contained in:
parent
8eb23f8a60
commit
7cdc755c16
|
@ -35,6 +35,8 @@ public partial class PreciseScalePopover : OsuPopover
|
|||
private Bindable<bool> canScaleX = null!;
|
||||
private Bindable<bool> canScaleY = null!;
|
||||
|
||||
private bool scaleInProgress;
|
||||
|
||||
public PreciseScalePopover(SelectionScaleHandler scaleHandler)
|
||||
{
|
||||
this.scaleHandler = scaleHandler;
|
||||
|
@ -124,15 +126,26 @@ protected override void LoadComplete()
|
|||
// aggregate two values into canScaleFromSelectionCentre
|
||||
canScaleX = scaleHandler.CanScaleX.GetBoundCopy();
|
||||
canScaleX.BindValueChanged(_ => updateCanScaleFromSelectionCentre());
|
||||
canScaleX.BindValueChanged(e => updateAxisCheckBoxEnabled(e.NewValue, xCheckBox.Current), true);
|
||||
|
||||
canScaleY = scaleHandler.CanScaleY.GetBoundCopy();
|
||||
canScaleY.BindValueChanged(_ => updateCanScaleFromSelectionCentre(), true);
|
||||
canScaleY.BindValueChanged(e => updateAxisCheckBoxEnabled(e.NewValue, yCheckBox.Current), true);
|
||||
|
||||
void updateCanScaleFromSelectionCentre() =>
|
||||
selectionCentreButton.Selected.Disabled = !(scaleHandler.CanScaleY.Value || scaleHandler.CanScaleFromPlayfieldOrigin.Value);
|
||||
|
||||
void updateAxisCheckBoxEnabled(bool enabled, Bindable<bool> current)
|
||||
{
|
||||
current.Disabled = false; // enable the bindable to allow setting the value
|
||||
current.Value = enabled;
|
||||
current.Disabled = !enabled;
|
||||
}
|
||||
|
||||
scaleInfo.BindValueChanged(scale =>
|
||||
{
|
||||
if (!scaleInProgress) return;
|
||||
|
||||
var newScale = new Vector2(scale.NewValue.XAxis ? scale.NewValue.Scale : 1, scale.NewValue.YAxis ? scale.NewValue.Scale : 1);
|
||||
scaleHandler.Update(newScale, getOriginPosition(scale.NewValue));
|
||||
});
|
||||
|
@ -172,6 +185,7 @@ protected override void PopIn()
|
|||
{
|
||||
base.PopIn();
|
||||
scaleHandler.Begin();
|
||||
scaleInProgress = true;
|
||||
updateMaxScale();
|
||||
}
|
||||
|
||||
|
@ -180,7 +194,10 @@ protected override void PopOut()
|
|||
base.PopOut();
|
||||
|
||||
if (IsLoaded)
|
||||
{
|
||||
scaleHandler.Commit();
|
||||
scaleInProgress = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue