Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
parhamsaremi authored and aarani committed Apr 24, 2023
1 parent 02150cb commit 5c2c3b3
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
@@ -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
@@ -181,6 +182,7 @@ static MauiAppBuilder SetupDefaults(this MauiAppBuilder builder)
builder.Services.TryAddEnumerable(ServiceDescriptor.Transient<IMauiInitializeService, MauiControlsInitializer>());
#endif
builder.RemapForControls();
AddDefaultMappings();

return builder;
}
@@ -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 5c2c3b3

Please sign in to comment.