Button completed

This commit is contained in:
2026-01-16 04:14:34 +00:00
parent a2800464c8
commit 9a49185183
3 changed files with 652 additions and 314 deletions

View File

@@ -1,6 +1,7 @@
// 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.Controls;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Graphics;
using SkiaSharp;
@@ -80,13 +81,13 @@ public partial class ButtonHandler : ViewHandler<IButton, SkiaButton>
var strokeColor = button.StrokeColor;
if (strokeColor is not null)
handler.PlatformView.BorderColor = strokeColor.ToSKColor();
handler.PlatformView.BorderColor = strokeColor;
}
public static void MapStrokeThickness(ButtonHandler handler, IButton button)
{
if (handler.PlatformView is null) return;
handler.PlatformView.BorderWidth = (float)button.StrokeThickness;
handler.PlatformView.BorderWidth = button.StrokeThickness;
}
public static void MapCornerRadius(ButtonHandler handler, IButton button)
@@ -101,8 +102,12 @@ public partial class ButtonHandler : ViewHandler<IButton, SkiaButton>
if (button.Background is SolidPaint solidPaint && solidPaint.Color is not null)
{
// Set ButtonBackgroundColor (used for rendering) not base BackgroundColor
handler.PlatformView.ButtonBackgroundColor = solidPaint.Color.ToSKColor();
// Set BackgroundColor (used for rendering)
handler.PlatformView.BackgroundColor = new SKColor(
(byte)(solidPaint.Color.Red * 255),
(byte)(solidPaint.Color.Green * 255),
(byte)(solidPaint.Color.Blue * 255),
(byte)(solidPaint.Color.Alpha * 255));
}
}
@@ -111,17 +116,16 @@ public partial class ButtonHandler : ViewHandler<IButton, SkiaButton>
if (handler.PlatformView is null) return;
var padding = button.Padding;
handler.PlatformView.Padding = new SKRect(
(float)padding.Left,
(float)padding.Top,
(float)padding.Right,
(float)padding.Bottom);
handler.PlatformView.Padding = new Thickness(
padding.Left,
padding.Top,
padding.Right,
padding.Bottom);
}
public static void MapIsEnabled(ButtonHandler handler, IButton button)
{
if (handler.PlatformView is null) return;
Console.WriteLine($"[ButtonHandler] MapIsEnabled - Text='{handler.PlatformView.Text}', IsEnabled={button.IsEnabled}");
handler.PlatformView.IsEnabled = button.IsEnabled;
handler.PlatformView.Invalidate();
}
@@ -172,7 +176,7 @@ public partial class TextButtonHandler : ButtonHandler
if (handler.PlatformView is null) return;
if (button.TextColor is not null)
handler.PlatformView.TextColor = button.TextColor.ToSKColor();
handler.PlatformView.TextColor = button.TextColor;
}
public static void MapFont(TextButtonHandler handler, ITextButton button)
@@ -181,18 +185,23 @@ public partial class TextButtonHandler : ButtonHandler
var font = button.Font;
if (font.Size > 0)
handler.PlatformView.FontSize = (float)font.Size;
handler.PlatformView.FontSize = font.Size;
if (!string.IsNullOrEmpty(font.Family))
handler.PlatformView.FontFamily = font.Family;
handler.PlatformView.IsBold = font.Weight >= FontWeight.Bold;
handler.PlatformView.IsItalic = font.Slant == FontSlant.Italic || font.Slant == FontSlant.Oblique;
// Convert Font weight/slant to FontAttributes
FontAttributes attrs = FontAttributes.None;
if (font.Weight >= FontWeight.Bold)
attrs |= FontAttributes.Bold;
if (font.Slant == FontSlant.Italic || font.Slant == FontSlant.Oblique)
attrs |= FontAttributes.Italic;
handler.PlatformView.FontAttributes = attrs;
}
public static void MapCharacterSpacing(TextButtonHandler handler, ITextButton button)
{
if (handler.PlatformView is null) return;
handler.PlatformView.CharacterSpacing = (float)button.CharacterSpacing;
handler.PlatformView.CharacterSpacing = button.CharacterSpacing;
}
}