forked from dotnet/maui
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from lytico/lytico/gtksharp/init-linux-core
Maui.Core Gtk enhancements
- Loading branch information
Showing
35 changed files
with
1,690 additions
and
122 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,12 +1,148 @@ | ||
namespace Microsoft.Maui | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.Maui.Graphics; | ||
using Pango; | ||
|
||
namespace Microsoft.Maui | ||
{ | ||
|
||
// see: https://developer.gnome.org/pygtk/stable/class-pangofontdescription.html | ||
/* | ||
public enum Pango.Weight | ||
{ | ||
Thin = 100, // 0x00000064 | ||
Ultralight = 200, // 0x000000C8 | ||
Light = 300, // 0x0000012C | ||
Semilight = 350, // 0x0000015E | ||
Book = 380, // 0x0000017C | ||
Normal = 400, // 0x00000190 | ||
Medium = 500, // 0x000001F4 | ||
Semibold = 600, // 0x00000258 | ||
Bold = 700, // 0x000002BC | ||
Ultrabold = 800, // 0x00000320 | ||
Heavy = 900, // 0x00000384 | ||
Ultraheavy = 1000, // 0x000003E8 | ||
} | ||
public enum Stretch | ||
{ | ||
UltraCondensed, | ||
ExtraCondensed, | ||
Condensed, | ||
SemiCondensed, | ||
Normal, | ||
SemiExpanded, | ||
Expanded, | ||
ExtraExpanded, | ||
UltraExpanded, | ||
} | ||
public enum Style { Normal, Oblique, Italic } | ||
public enum Variant | ||
{ | ||
Normal, | ||
SmallCaps, | ||
} | ||
public enum Gravity | ||
{ | ||
South, | ||
East, | ||
North, | ||
West, | ||
Auto, | ||
} | ||
*/ | ||
|
||
public class FontManager : IFontManager | ||
{ | ||
|
||
readonly IFontRegistrar _fontRegistrar; | ||
|
||
static Pango.Context? _systemContext; | ||
|
||
Pango.Context SystemContext => _systemContext ??= Gdk.PangoHelper.ContextGet(); | ||
|
||
public FontManager(IFontRegistrar fontRegistrar) | ||
{ | ||
_fontRegistrar = fontRegistrar; | ||
} | ||
|
||
FontDescription? _defaultFontFamily; | ||
|
||
public FontDescription DefaultFontFamily | ||
{ | ||
get => _defaultFontFamily ??= GetFontFamily(default); | ||
} | ||
|
||
double? _defaultFontSize; | ||
|
||
public double DefaultFontSize => _defaultFontSize ??= DefaultFontFamily?.GetSize() ?? 0; | ||
|
||
public FontDescription GetFontFamily(Font font) => | ||
font == default ? SystemContext.FontDescription : font.ToFontDescription(); | ||
|
||
public double GetFontSize(Font font) | ||
{ | ||
if (font.UseNamedSize) | ||
return GetFontSize(font.NamedSize); | ||
|
||
return font.FontSize; | ||
} | ||
|
||
public double GetFontSize(NamedSize namedSize) | ||
{ | ||
// TODO: Hmm, maybe we need to revisit this, since we no longer support Windows Phone OR WinRT. | ||
// These are values pulled from the mapped sizes on Windows Phone, WinRT has no equivalent sizes, only intents. | ||
|
||
return namedSize switch | ||
{ | ||
NamedSize.Default => DefaultFontSize, | ||
NamedSize.Micro => 15.667, | ||
NamedSize.Small => 18.667, | ||
NamedSize.Medium => 22.667, | ||
NamedSize.Large => 32, | ||
NamedSize.Body => 14, | ||
NamedSize.Caption => 12, | ||
NamedSize.Header => 46, | ||
NamedSize.Subtitle => 20, | ||
NamedSize.Title => 24, | ||
_ => throw new ArgumentOutOfRangeException(nameof(namedSize)), | ||
}; | ||
} | ||
|
||
private IEnumerable<(Pango.FontFamily family, Pango.FontDescription description)> GetAvailableFamilyFaces(Pango.FontFamily family) | ||
{ | ||
|
||
if (family != default) | ||
{ | ||
foreach (var face in family.Faces) | ||
yield return (family, face.Describe()); | ||
} | ||
|
||
yield break; | ||
} | ||
|
||
private FontDescription[] GetAvailableFontStyles() | ||
{ | ||
var fontFamilies = SystemContext.FontMap?.Families.ToArray(); | ||
|
||
var styles = new List<FontDescription>(); | ||
|
||
if (fontFamilies != null) | ||
{ | ||
styles.AddRange(fontFamilies.SelectMany(GetAvailableFamilyFaces).Select(font => font.description) | ||
.OrderBy(d=>d.Family)); | ||
} | ||
|
||
|
||
return styles.ToArray(); | ||
} | ||
|
||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,7 +1,16 @@ | ||
namespace Microsoft.Maui | ||
using Pango; | ||
|
||
namespace Microsoft.Maui | ||
{ | ||
public interface IFontManager | ||
{ | ||
|
||
FontDescription DefaultFontFamily { get; } | ||
|
||
double DefaultFontSize { get; } | ||
|
||
FontDescription GetFontFamily(Font font); | ||
|
||
double GetFontSize(Font font); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,17 +1,36 @@ | ||
using Gtk; | ||
using System; | ||
using Gtk; | ||
|
||
namespace Microsoft.Maui.Handlers | ||
{ | ||
|
||
public partial class CheckBoxHandler : ViewHandler<ICheckBox, CheckButton> | ||
{ | ||
protected override CheckButton CreateNativeView() | ||
{ | ||
return new CheckButton(); | ||
} | ||
|
||
protected override CheckButton CreateNativeView() => new(); | ||
|
||
public static void MapIsChecked(CheckBoxHandler handler, ICheckBox check) | ||
{ | ||
handler.NativeView?.UpdateIsChecked(check); | ||
} | ||
|
||
protected override void ConnectHandler(CheckButton nativeView) | ||
{ | ||
nativeView.Toggled += OnToggledEvent; | ||
} | ||
|
||
protected override void DisconnectHandler(CheckButton nativeView) | ||
{ | ||
nativeView.Toggled -= OnToggledEvent; | ||
} | ||
|
||
protected void OnToggledEvent(object? sender, EventArgs e) | ||
{ | ||
if (sender is CheckButton nativeView && VirtualView != null) | ||
VirtualView.IsChecked = nativeView.Active; | ||
|
||
} | ||
|
||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.