Skip to content

Commit

Permalink
Merge pull request AvaloniaUI#8456 from AvaloniaUI/fixes/splitview-cu…
Browse files Browse the repository at this point in the history
…lture-sensitive

make splitview not culture sensitive.
# Conflicts:
#	src/Avalonia.Controls/SplitView.cs
  • Loading branch information
maxkatz6 authored and danwalmsley committed Jul 7, 2022
1 parent a4279a5 commit 8cfa8a2
Showing 1 changed file with 48 additions and 18 deletions.
66 changes: 48 additions & 18 deletions src/Avalonia.Controls/SplitView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -431,32 +431,62 @@ private void OnCompactPaneLengthChanged(AvaloniaPropertyChangedEventArgs e)
}
}

private string GetPseudoClass(SplitViewDisplayMode mode)
{
return mode switch
{
SplitViewDisplayMode.Inline => "inline",
SplitViewDisplayMode.CompactInline => "compactinline",
SplitViewDisplayMode.Overlay => "overlay",
SplitViewDisplayMode.CompactOverlay => "compactoverlay",
_ => throw new ArgumentOutOfRangeException(nameof(mode), mode, null)
};
}

private string GetPseudoClass(SplitViewPanePlacement placement)
{
return placement switch
{
SplitViewPanePlacement.Left => "left",
SplitViewPanePlacement.Right => "right",
_ => throw new ArgumentOutOfRangeException(nameof(placement), placement, null)
};
}

private void OnPanePlacementChanged(AvaloniaPropertyChangedEventArgs e)
{
var oldState = e.OldValue.ToString().ToLower();
var newState = e.NewValue.ToString().ToLower();
PseudoClasses.Remove($":{oldState}");
PseudoClasses.Add($":{newState}");
if (e.OldValue is SplitViewPanePlacement oldValue && e.NewValue is SplitViewPanePlacement newValue)
{
var oldState = GetPseudoClass(oldValue);
var newState = GetPseudoClass(newValue);
PseudoClasses.Remove($":{oldState}");
PseudoClasses.Add($":{newState}");
}
}

private void OnDisplayModeChanged(AvaloniaPropertyChangedEventArgs e)
{
var oldState = e.OldValue.ToString().ToLower();
var newState = e.NewValue.ToString().ToLower();
if (e.OldValue is SplitViewDisplayMode oldValue && e.NewValue is SplitViewDisplayMode newValue)
{
var oldState = GetPseudoClass(oldValue);
var newState = GetPseudoClass(newValue);

PseudoClasses.Remove($":{oldState}");
PseudoClasses.Add($":{newState}");
PseudoClasses.Remove($":{oldState}");
PseudoClasses.Add($":{newState}");

var (closedPaneWidth, paneColumnGridLength) = (SplitViewDisplayMode)e.NewValue switch
{
SplitViewDisplayMode.Overlay => (0, new GridLength(0, GridUnitType.Pixel)),
SplitViewDisplayMode.CompactOverlay => (CompactPaneLength, new GridLength(CompactPaneLength, GridUnitType.Pixel)),
SplitViewDisplayMode.Inline => (0, new GridLength(0, GridUnitType.Auto)),
SplitViewDisplayMode.CompactInline => (CompactPaneLength, new GridLength(0, GridUnitType.Auto)),
_ => throw new NotImplementedException(),
};
TemplateSettings.ClosedPaneWidth = closedPaneWidth;
TemplateSettings.PaneColumnGridLength = paneColumnGridLength;

var (closedPaneWidth, paneColumnGridLength) = newValue switch
{
SplitViewDisplayMode.Overlay => (0, new GridLength(0, GridUnitType.Pixel)),
SplitViewDisplayMode.CompactOverlay => (CompactPaneLength,
new GridLength(CompactPaneLength, GridUnitType.Pixel)),
SplitViewDisplayMode.Inline => (0, new GridLength(0, GridUnitType.Auto)),
SplitViewDisplayMode.CompactInline => (CompactPaneLength, new GridLength(0, GridUnitType.Auto)),
_ => throw new NotImplementedException(),
};
TemplateSettings.ClosedPaneWidth = closedPaneWidth;
TemplateSettings.PaneColumnGridLength = paneColumnGridLength;
}
}

private void OnUseLightDismissChanged(AvaloniaPropertyChangedEventArgs e)
Expand Down

0 comments on commit 8cfa8a2

Please sign in to comment.