From 0b062651176340c8415f9cc2ccf24f17f9dbcc91 Mon Sep 17 00:00:00 2001 From: Codex CLI Date: Wed, 27 Aug 2025 03:00:31 -0500 Subject: [PATCH] UI: Replace two-column Grid with SplitView; add narrow pane toggle; add WidthToBooleanConverter and width-based DisplayMode triggers for a responsive layout across Web, Desktop, Android. --- .../Converters/WidthToBooleanConverter.cs | 31 +++ src/AdvancedCalculator/Views/MainView.axaml | 205 +++++++++++------- 2 files changed, 153 insertions(+), 83 deletions(-) create mode 100644 src/AdvancedCalculator/Converters/WidthToBooleanConverter.cs diff --git a/src/AdvancedCalculator/Converters/WidthToBooleanConverter.cs b/src/AdvancedCalculator/Converters/WidthToBooleanConverter.cs new file mode 100644 index 0000000..6efa5f6 --- /dev/null +++ b/src/AdvancedCalculator/Converters/WidthToBooleanConverter.cs @@ -0,0 +1,31 @@ +using System; +using System.Globalization; +using Avalonia.Data.Converters; + +namespace AdvancedCalculator.Converters; + +// Returns true if width (double) is less than the provided threshold (parameter), +// otherwise false. Default threshold is 640 when parameter is null or invalid. +public class WidthToBooleanConverter : IValueConverter +{ + public static readonly WidthToBooleanConverter Instance = new(); + + public object? Convert(object? value, Type targetType, object? parameter, CultureInfo? culture) + { + if (value is double width) + { + double threshold = 640; + if (parameter is double p) + threshold = p; + else if (parameter is string s && double.TryParse(s, NumberStyles.Number, CultureInfo.InvariantCulture, out var parsed)) + threshold = parsed; + + return width < threshold; + } + return false; + } + + public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo? culture) + => throw new NotSupportedException(); +} + diff --git a/src/AdvancedCalculator/Views/MainView.axaml b/src/AdvancedCalculator/Views/MainView.axaml index 71ffac9..35b2c61 100644 --- a/src/AdvancedCalculator/Views/MainView.axaml +++ b/src/AdvancedCalculator/Views/MainView.axaml @@ -10,92 +10,131 @@ x:DataType="vm:MainViewModel"> + + + + + + + - - - - - - - + + + + + + + - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +