11using System ;
22using Gtk ;
33using Microsoft . Maui . Graphics ;
4- // using Microsoft.UI.Xaml;
5- // using Microsoft.UI.Xaml.Controls;
6- // using Microsoft.UI.Xaml.Media;
7- // using WBrush = Microsoft.UI.Xaml.Media.Brush;
84
95namespace Microsoft . Maui . Platform
106{
@@ -23,78 +19,66 @@ public static void UpdateIsChecked(this RadioButton platformRadioButton, IRadioB
2319 "RadioButtonBackgroundDisabled"
2420 } ;
2521
26- [ MissingMapper ]
2722 public static void UpdateBackground ( this RadioButton platformRadioButton , IRadioButton button )
2823 {
29- // if (button.Background is SolidPaint solidPaint)
30- // {
31- // UpdateColors(platformRadioButton.Resources, _backgroundColorKeys, solidPaint.ToPlatform());
24+ // Ref: https://github.com/jsuarezruiz/maui-linux/blob/ce1c06f1f05422a70c150276a82ad88d3b572198/src/Core/src/Platform/Gtk/ViewExtensions.cs#L15-L69
3225
33- // platformRadioButton.RefreshThemeResources();
34- // }
35- }
26+ var color = button . Background ? . BackgroundColor ;
3627
37- private static readonly string [ ] _foregroundColorKeys =
38- {
39- "RadioButtonForeground" ,
40- "RadioButtonForegroundPointerOver" ,
41- "RadioButtonForegroundPressed" ,
42- "RadioButtonForegroundDisabled"
43- } ;
28+ if ( button . Background is { } paint )
29+ color = paint . ToColor ( ) ;
4430
45- [ MissingMapper ]
46- public static void UpdateTextColor ( this RadioButton platformRadioButton , ITextStyle button )
47- {
48- // UpdateColors(platformRadioButton.Resources, _foregroundColorKeys, button.TextColor?.ToPlatform());
31+ var gradientCss = button . Background . ToCss ( ) ;
32+
33+ var disposePixbuf = false ;
34+ var pixbuf = gradientCss == null ? button . Background ? . ToPixbuf ( out disposePixbuf ) : default ;
35+
36+ // create a temporary file
37+ var picCss = default ( string ) ;
38+ var tempFile = pixbuf ? . TempFileFor ( ) ;
39+
40+ // use the tempfile as url in css
41+ if ( tempFile is not null )
42+ picCss = $ "url('{ tempFile } ')";
43+
44+ if ( color is null && ( gradientCss is null || picCss is null ) )
45+ return ;
46+
47+ if ( picCss is not null )
48+ platformRadioButton . SetStyleValue ( picCss , "background-image" ) ;
49+
50+ if ( gradientCss is not null )
51+ platformRadioButton . SetStyleValue ( gradientCss , "background" ) ;
52+ else
53+ platformRadioButton . SetBackgroundColor ( color ) ;
54+
55+ // Gtk.CssProvider translates the file of url() into Base64, so the file can safely deleted:
56+ tempFile ? . Dispose ( ) ;
4957
50- // platformRadioButton.RefreshThemeResources();
58+ if ( disposePixbuf )
59+ pixbuf ? . Dispose ( ) ;
5160 }
5261
62+ [ MissingMapper ]
63+ public static void UpdateTextColor ( this RadioButton platformRadioButton , ITextStyle button ) { }
64+
5365 public static void UpdateContent ( this RadioButton platformRadioButton , IRadioButton radioButton )
5466 {
5567 _ = radioButton . Handler ? . MauiContext ?? throw new InvalidOperationException ( $ "{ nameof ( MauiContext ) } should have been set by base class.") ;
5668
5769 if ( radioButton is { PresentedContent : IView view } )
5870 platformRadioButton . Label = $ "{ view . ToPlatform ( radioButton . Handler . MauiContext ) } ";
59- // else
60- // platformRadioButton.Label = $"{radioButton.Content}";
71+ else
72+ platformRadioButton . Label = $ "{ radioButton . Content } ";
6173 }
6274
63- private static readonly string [ ] _borderColorKeys =
64- {
65- "RadioButtonBorderBrush" ,
66- "RadioButtonBorderBrushPointerOver" ,
67- "RadioButtonBorderBrushPressed" ,
68- "RadioButtonBorderBrushDisabled"
69- } ;
70-
7175 [ MissingMapper ]
72- public static void UpdateStrokeColor ( this RadioButton platformRadioButton , IRadioButton radioButton )
73- {
74- // UpdateColors(platformRadioButton.Resources, _borderColorKeys, radioButton.StrokeColor?.ToPlatform());
75-
76- // platformRadioButton.RefreshThemeResources();
77- }
78-
79- // [MissingMapper]
80- // static void UpdateColors(ResourceDictionary resource, string[] keys, WBrush? brush)
81- // {
82- // if (brush is null)
83- // resource.RemoveKeys(keys);
84- // else
85- // resource.SetValueForAllKey(keys, brush);
86- // }
76+ public static void UpdateStrokeColor ( this RadioButton platformRadioButton , IRadioButton radioButton ) { }
8777
8878 [ MissingMapper ]
89- public static void UpdateStrokeThickness ( this RadioButton nativeRadioButton , IRadioButton radioButton )
90- {
91- // nativeRadioButton.BorderThickness = radioButton.StrokeThickness <= 0 ? WinUIHelpers.CreateThickness(3) : WinUIHelpers.CreateThickness(radioButton.StrokeThickness);
92- }
79+ public static void UpdateStrokeThickness ( this RadioButton nativeRadioButton , IRadioButton radioButton ) { }
9380
9481 [ MissingMapper ]
95- public static void UpdateCornerRadius ( this RadioButton nativeRadioButton , IRadioButton radioButton )
96- {
97- // nativeRadioButton.CornerRadius = WinUIHelpers.CreateCornerRadius(radioButton.CornerRadius);
98- }
82+ public static void UpdateCornerRadius ( this RadioButton nativeRadioButton , IRadioButton radioButton ) { }
9983 }
10084}
0 commit comments