This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Bug] [UWP] Fix FontIcons alignment (#15047)
* Update FontImageSourceHandler.cs * correction and test * tidy * Small nits Co-authored-by: Gerald Versluis <gerald@verslu.is> Co-authored-by: Gerald Versluis <gerald.versluis@microsoft.com>
- Loading branch information
1 parent
9c0131f
commit 9222f32
Showing
5 changed files
with
77 additions
and
4 deletions.
There are no files selected for viewing
Binary file added
BIN
+308 KB
Xamarin.Forms.ControlGallery.WindowsUniversal/Assets/Fonts/MaterialIconsOutlined-Regular.otf
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue8606.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Xamarin.Forms.CustomAttributes; | ||
using Xamarin.Forms.Internals; | ||
#if UITEST | ||
using Xamarin.UITest; | ||
using NUnit.Framework; | ||
using Xamarin.Forms.Core.UITests; | ||
#endif | ||
|
||
namespace Xamarin.Forms.Controls.Issues | ||
{ | ||
[Preserve(AllMembers = true)] | ||
[Issue(IssueTracker.Github, 8606, "[Bug] [UWP] FontIcons are not aligned correctly", PlatformAffected.UWP)] | ||
#if UITEST | ||
[Category(UITestCategories.Github5000)] | ||
[Category(UITestCategories.ManualReview)] | ||
#endif | ||
public class Issue8606 : TestContentPage | ||
{ | ||
protected override void Init() | ||
{ | ||
var iconColor = Color.White; | ||
List<(string fontFamily,string glyph,string familyShortName)> fontFamilyGlyphs = new List<(string,string,string)> | ||
{ | ||
(GetFontFamily("fa-solid-900.ttf","Font Awesome 5 Free"), GetGlyph("f059"),"FaSolid"), | ||
(GetFontFamily("ionicons.ttf","Ionicons"), GetGlyph("f142"),"Ionicons"), | ||
(GetFontFamily("materialdesignicons-webfont.ttf","Material Design Icons"),GetGlyph("f625"),"Material old"), | ||
(GetFontFamily("MaterialIconsOutlined-Regular.otf","Material Icons Outlined"), GetGlyph("e8fd"),"Material"), | ||
}; | ||
|
||
List<Func<FontImageSource, View>> affectedViewsCreators = new List<Func<FontImageSource, View>> | ||
{ | ||
(fontImageSource) => new Button { ImageSource = fontImageSource }, | ||
(fontImageSource) => new ImageButton { WidthRequest=39,HeightRequest=39, Source = fontImageSource, BackgroundColor = Color.FromHex("#333333")}, | ||
(fontImageSource) => new Frame{Content = new Image { Source = fontImageSource}, BorderColor=iconColor, Padding=0, } | ||
}; | ||
|
||
var content = new StackLayout { }; | ||
content.Children.Add(new Label { BackgroundColor = Color.Black, Padding = 12, TextColor = iconColor, Text = "Button, ImageButton and Image should use the same FontImageSourceHandler which should render centered." }); | ||
|
||
foreach (var (fontFamily, glyph, familyShortName) in fontFamilyGlyphs) | ||
{ | ||
var fontImageSource = new FontImageSource { Size = 24, Color = iconColor, FontFamily = fontFamily, Glyph = glyph }; | ||
var fontStackLayout = new StackLayout { }; | ||
fontStackLayout.Children.Add(new Label { FontSize = 24, Text = familyShortName }); | ||
var fontsStackLayout = new StackLayout { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.Center }; | ||
fontStackLayout.Children.Add(fontsStackLayout); | ||
foreach (var affectedViewCreator in affectedViewsCreators) | ||
{ | ||
var affectedView = affectedViewCreator(fontImageSource); | ||
affectedView.VerticalOptions = LayoutOptions.Center; | ||
fontsStackLayout.Children.Add(affectedView); | ||
} | ||
content.Children.Add(fontStackLayout); | ||
} | ||
|
||
Content = content; | ||
|
||
} | ||
|
||
private string GetFontFamily(string fileName, string fontName) | ||
{ | ||
return $"Assets/Fonts/{fileName}#{fontName}"; | ||
} | ||
|
||
private static string GetGlyph(string codePoint) | ||
{ | ||
int p = int.Parse(codePoint, System.Globalization.NumberStyles.HexNumber); | ||
return char.ConvertFromUtf32(p); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters