Button completed
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,20 +226,20 @@ public static class LinuxProgramHost
|
||||
var buttonSection = new SkiaStackLayout { Orientation = StackOrientation.Horizontal, Spacing = 10 };
|
||||
|
||||
var btnPrimary = new SkiaButton { Text = "Primary", FontSize = 14 };
|
||||
btnPrimary.BackgroundColor = new SKColor(0x21, 0x96, 0xF3);
|
||||
btnPrimary.TextColor = SKColors.White;
|
||||
btnPrimary.BackgroundColor = new SKColor(0x21, 0x96, 0xF3); // Uses base SkiaView's SKColor BackgroundColor
|
||||
btnPrimary.TextColor = Colors.White;
|
||||
var clickCount = 0;
|
||||
btnPrimary.Clicked += (s, e) => { clickCount++; btnPrimary.Text = $"Clicked {clickCount}x"; };
|
||||
buttonSection.AddChild(btnPrimary);
|
||||
|
||||
var btnSuccess = new SkiaButton { Text = "Success", FontSize = 14 };
|
||||
btnSuccess.BackgroundColor = new SKColor(0x4C, 0xAF, 0x50);
|
||||
btnSuccess.TextColor = SKColors.White;
|
||||
btnSuccess.TextColor = Colors.White;
|
||||
buttonSection.AddChild(btnSuccess);
|
||||
|
||||
var btnDanger = new SkiaButton { Text = "Danger", FontSize = 14 };
|
||||
btnDanger.BackgroundColor = new SKColor(0xF4, 0x43, 0x36);
|
||||
btnDanger.TextColor = SKColors.White;
|
||||
btnDanger.TextColor = Colors.White;
|
||||
buttonSection.AddChild(btnDanger);
|
||||
|
||||
root.AddChild(buttonSection);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user