2025-12-19 09:30:16 +00:00
|
|
|
// Licensed to the .NET Foundation under one or more agreements.
|
|
|
|
|
// The .NET Foundation licenses this file to you under the MIT license.
|
|
|
|
|
|
|
|
|
|
using Microsoft.Maui.Handlers;
|
|
|
|
|
using Microsoft.Maui.Graphics;
|
2026-01-01 12:52:33 -05:00
|
|
|
using Microsoft.Maui.Controls;
|
2025-12-19 09:30:16 +00:00
|
|
|
using Microsoft.Maui.Platform;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.Maui.Platform.Linux.Handlers;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handler for Stepper on Linux using Skia rendering.
|
2026-01-16 05:01:27 +00:00
|
|
|
/// Maps IStepper interface to SkiaStepper platform view.
|
2025-12-19 09:30:16 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public partial class StepperHandler : ViewHandler<IStepper, SkiaStepper>
|
|
|
|
|
{
|
|
|
|
|
public static IPropertyMapper<IStepper, StepperHandler> Mapper =
|
|
|
|
|
new PropertyMapper<IStepper, StepperHandler>(ViewHandler.ViewMapper)
|
|
|
|
|
{
|
|
|
|
|
[nameof(IStepper.Value)] = MapValue,
|
|
|
|
|
[nameof(IStepper.Minimum)] = MapMinimum,
|
|
|
|
|
[nameof(IStepper.Maximum)] = MapMaximum,
|
2026-01-01 12:52:33 -05:00
|
|
|
["Increment"] = MapIncrement,
|
2025-12-19 09:30:16 +00:00
|
|
|
[nameof(IView.Background)] = MapBackground,
|
2026-01-01 12:52:33 -05:00
|
|
|
[nameof(IView.IsEnabled)] = MapIsEnabled,
|
2025-12-19 09:30:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static CommandMapper<IStepper, StepperHandler> CommandMapper =
|
|
|
|
|
new(ViewHandler.ViewCommandMapper)
|
|
|
|
|
{
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public StepperHandler() : base(Mapper, CommandMapper)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public StepperHandler(IPropertyMapper? mapper, CommandMapper? commandMapper = null)
|
|
|
|
|
: base(mapper ?? Mapper, commandMapper ?? CommandMapper)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override SkiaStepper CreatePlatformView()
|
|
|
|
|
{
|
|
|
|
|
return new SkiaStepper();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void ConnectHandler(SkiaStepper platformView)
|
|
|
|
|
{
|
|
|
|
|
base.ConnectHandler(platformView);
|
|
|
|
|
platformView.ValueChanged += OnValueChanged;
|
2026-01-01 12:52:33 -05:00
|
|
|
|
|
|
|
|
// Apply dark theme colors if needed
|
|
|
|
|
if (Application.Current?.UserAppTheme == AppTheme.Dark)
|
|
|
|
|
{
|
2026-01-16 05:01:27 +00:00
|
|
|
platformView.ButtonBackgroundColor = Color.FromRgb(66, 66, 66);
|
|
|
|
|
platformView.ButtonPressedColor = Color.FromRgb(97, 97, 97);
|
|
|
|
|
platformView.ButtonDisabledColor = Color.FromRgb(48, 48, 48);
|
|
|
|
|
platformView.SymbolColor = Color.FromRgb(224, 224, 224);
|
|
|
|
|
platformView.SymbolDisabledColor = Color.FromRgb(97, 97, 97);
|
|
|
|
|
platformView.BorderColor = Color.FromRgb(97, 97, 97);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sync properties
|
|
|
|
|
if (VirtualView != null)
|
|
|
|
|
{
|
|
|
|
|
MapValue(this, VirtualView);
|
|
|
|
|
MapMinimum(this, VirtualView);
|
|
|
|
|
MapMaximum(this, VirtualView);
|
|
|
|
|
MapIsEnabled(this, VirtualView);
|
2026-01-01 12:52:33 -05:00
|
|
|
}
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void DisconnectHandler(SkiaStepper platformView)
|
|
|
|
|
{
|
|
|
|
|
platformView.ValueChanged -= OnValueChanged;
|
|
|
|
|
base.DisconnectHandler(platformView);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-16 05:01:27 +00:00
|
|
|
private void OnValueChanged(object? sender, ValueChangedEventArgs e)
|
2025-12-19 09:30:16 +00:00
|
|
|
{
|
|
|
|
|
if (VirtualView is null || PlatformView is null) return;
|
2026-01-16 05:01:27 +00:00
|
|
|
|
|
|
|
|
if (Math.Abs(VirtualView.Value - e.NewValue) > 0.0001)
|
|
|
|
|
{
|
|
|
|
|
VirtualView.Value = e.NewValue;
|
|
|
|
|
}
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapValue(StepperHandler handler, IStepper stepper)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
2026-01-16 05:01:27 +00:00
|
|
|
|
|
|
|
|
if (Math.Abs(handler.PlatformView.Value - stepper.Value) > 0.0001)
|
|
|
|
|
handler.PlatformView.Value = stepper.Value;
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapMinimum(StepperHandler handler, IStepper stepper)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
handler.PlatformView.Minimum = stepper.Minimum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapMaximum(StepperHandler handler, IStepper stepper)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
handler.PlatformView.Maximum = stepper.Maximum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapBackground(StepperHandler handler, IStepper stepper)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
|
|
|
|
|
if (stepper.Background is SolidPaint solidPaint && solidPaint.Color is not null)
|
|
|
|
|
{
|
|
|
|
|
handler.PlatformView.BackgroundColor = solidPaint.Color.ToSKColor();
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-01 12:52:33 -05:00
|
|
|
|
|
|
|
|
public static void MapIncrement(StepperHandler handler, IStepper stepper)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
|
|
|
|
|
if (stepper is Stepper stepperControl)
|
|
|
|
|
{
|
|
|
|
|
handler.PlatformView.Increment = stepperControl.Increment;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapIsEnabled(StepperHandler handler, IStepper stepper)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
handler.PlatformView.IsEnabled = stepper.IsEnabled;
|
2026-01-16 05:01:27 +00:00
|
|
|
handler.PlatformView.Invalidate();
|
2026-01-01 12:52:33 -05:00
|
|
|
}
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|