Skip to content

Commit

Permalink
Controls.Hosting(GTK): mappings for Frame (lytico#11)
Browse files Browse the repository at this point in the history
Add mappers for BorderColor and CornerRadius for Frame elements
so they can now have borders.
  • Loading branch information
parhamsaremi authored and aarani committed Apr 24, 2023
1 parent 0432f4e commit 75f3e35
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Controls/src/Xaml/Hosting/AppHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#elif GTK
using Microsoft.Maui.Controls.Handlers.Compatibility;
using Microsoft.Maui.Controls.Compatibility.Platform.Gtk;
using Microsoft.Maui.Graphics.Platform.Gtk;
#endif

namespace Microsoft.Maui.Controls.Hosting
Expand Down Expand Up @@ -181,6 +182,7 @@ static MauiAppBuilder SetupDefaults(this MauiAppBuilder builder)
builder.Services.TryAddEnumerable(ServiceDescriptor.Transient<IMauiInitializeService, MauiControlsInitializer>());
#endif
builder.RemapForControls();
AddDefaultMappings();

return builder;
}
Expand Down Expand Up @@ -249,5 +251,34 @@ internal static MauiAppBuilder RemapForControls(this MauiAppBuilder builder)

return builder;
}

internal static void AddDefaultMappings()
{
#if GTK
ContentViewHandler.Mapper.AppendToMapping(
"BorderColor",
(IContentViewHandler handler, IContentView view) =>
{
if (view is Frame frame)
{
Microsoft.Maui.Platform.ContentView contentView = (Microsoft.Maui.Platform.ContentView)handler.PlatformView;
contentView.SetStyleValueNode($"1px solid {frame.BorderColor.ToGdkRgba().ToString()}", contentView.CssMainNode(), "border");
}
}
);

ContentViewHandler.Mapper.AppendToMapping(
"CornerRadius",
(IContentViewHandler handler, IContentView view) =>
{
if (view is Frame frame)
{
Microsoft.Maui.Platform.ContentView contentView = (Microsoft.Maui.Platform.ContentView)handler.PlatformView;
contentView.SetStyleValueNode($"{frame.CornerRadius:f}px", contentView.CssMainNode(), "border-radius");
}
}
);
#endif
}
}
}

0 comments on commit 75f3e35

Please sign in to comment.