Skip to content

Commit cd1fe3a

Browse files
committed
WinUI 3 IME integration enabled
1 parent fcf0424 commit cd1fe3a

4 files changed

Lines changed: 341 additions & 76 deletions

File tree

src/UnoEdit.WinUI.Sample/App.xaml.cs

Lines changed: 9 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.IO;
23
using Microsoft.UI.Xaml;
4+
using Microsoft.UI.Xaml.Markup;
35

46
namespace UnoEdit.WinUI.Sample;
57

@@ -16,61 +18,11 @@ public App()
1618

1719
private void LoadUnoEditorResources()
1820
{
19-
var dict = new Microsoft.UI.Xaml.ResourceDictionary();
20-
21-
// Scalar resources
22-
dict["UnoTextEditorBorderThickness"] = new Microsoft.UI.Xaml.Thickness(1);
23-
dict["UnoTextEditorCornerRadius"] = new Microsoft.UI.Xaml.CornerRadius(10);
24-
dict["UnoSearchPanelCornerRadius"] = new Microsoft.UI.Xaml.CornerRadius(8);
25-
dict["UnoSearchPanelMargin"] = new Microsoft.UI.Xaml.Thickness(12, 12, 12, 0);
26-
dict["UnoSearchPanelPadding"] = new Microsoft.UI.Xaml.Thickness(10);
27-
dict["UnoEditorLineHeight"] = 22.0;
28-
dict["UnoEditorTextFontSize"] = 13.0;
29-
dict["UnoEditorGlyphFontSize"] = 10.0;
30-
dict["UnoEditorOverlayHeight"] = 16.0;
31-
dict["UnoEditorCaretWidth"] = 2.0;
32-
33-
// Dark theme
34-
var dark = new Microsoft.UI.Xaml.ResourceDictionary();
35-
dark["UnoEditorBackgroundBrush"] = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.ColorHelper.FromArgb(0xFF, 0x0F, 0x17, 0x2A));
36-
dark["UnoEditorBorderBrush"] = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.ColorHelper.FromArgb(0xFF, 0x33, 0x41, 0x55));
37-
dark["UnoEditorTitleBarBackgroundBrush"] = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.ColorHelper.FromArgb(0xFF, 0x0F, 0x17, 0x2A));
38-
dark["UnoEditorTitleBarForegroundBrush"] = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.ColorHelper.FromArgb(0xFF, 0xE5, 0xE7, 0xEB));
39-
dark["UnoEditorSummaryForegroundBrush"] = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.ColorHelper.FromArgb(0xFF, 0x94, 0xA3, 0xB8));
40-
dark["UnoEditorGutterForegroundBrush"] = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.ColorHelper.FromArgb(0xFF, 0x64, 0x74, 0x8B));
41-
dark["UnoSearchPanelBackgroundBrush"] = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.ColorHelper.FromArgb(0xFF, 0x17, 0x20, 0x33));
42-
dark["UnoSearchPanelBorderBrush"] = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.ColorHelper.FromArgb(0xFF, 0x33, 0x41, 0x55));
43-
dark["UnoSearchPanelResultsBrush"] = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.ColorHelper.FromArgb(0xFF, 0x94, 0xA3, 0xB8));
44-
dict.ThemeDictionaries["Dark"] = dark;
45-
46-
// Light theme
47-
var light = new Microsoft.UI.Xaml.ResourceDictionary();
48-
light["UnoEditorBackgroundBrush"] = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.ColorHelper.FromArgb(0xFF, 0xFF, 0xFF, 0xFF));
49-
light["UnoEditorBorderBrush"] = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.ColorHelper.FromArgb(0xFF, 0xD1, 0xD5, 0xDB));
50-
light["UnoEditorTitleBarBackgroundBrush"] = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.ColorHelper.FromArgb(0xFF, 0xF9, 0xFA, 0xFB));
51-
light["UnoEditorTitleBarForegroundBrush"] = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.ColorHelper.FromArgb(0xFF, 0x11, 0x18, 0x27));
52-
light["UnoEditorSummaryForegroundBrush"] = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.ColorHelper.FromArgb(0xFF, 0x6E, 0x76, 0x81));
53-
light["UnoEditorGutterForegroundBrush"] = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.ColorHelper.FromArgb(0xFF, 0x6E, 0x76, 0x81));
54-
light["UnoSearchPanelBackgroundBrush"] = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.ColorHelper.FromArgb(0xFF, 0xF3, 0xF4, 0xF6));
55-
light["UnoSearchPanelBorderBrush"] = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.ColorHelper.FromArgb(0xFF, 0xD1, 0xD5, 0xDB));
56-
light["UnoSearchPanelResultsBrush"] = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.ColorHelper.FromArgb(0xFF, 0x6E, 0x76, 0x81));
57-
dict.ThemeDictionaries["Light"] = light;
21+
string resourcePath = Path.Combine(AppContext.BaseDirectory, "UnoEditorResources.xaml");
22+
string resourceXaml = File.ReadAllText(resourcePath);
23+
var dict = (ResourceDictionary)XamlReader.Load(resourceXaml);
5824

5925
this.Resources.MergedDictionaries.Add(dict);
60-
61-
// Styles (must be added after theme resources so ThemeResource refs resolve)
62-
var btnStyle = new Microsoft.UI.Xaml.Style(typeof(Microsoft.UI.Xaml.Controls.Button));
63-
btnStyle.Setters.Add(new Microsoft.UI.Xaml.Setter(Microsoft.UI.Xaml.Controls.Button.MinWidthProperty, 44.0));
64-
btnStyle.Setters.Add(new Microsoft.UI.Xaml.Setter(Microsoft.UI.Xaml.Controls.Button.MinHeightProperty, 32.0));
65-
this.Resources["UnoSearchActionButtonStyle"] = btnStyle;
66-
67-
var cbStyle = new Microsoft.UI.Xaml.Style(typeof(Microsoft.UI.Xaml.Controls.CheckBox));
68-
cbStyle.Setters.Add(new Microsoft.UI.Xaml.Setter(Microsoft.UI.Xaml.FrameworkElement.VerticalAlignmentProperty, Microsoft.UI.Xaml.VerticalAlignment.Center));
69-
cbStyle.Setters.Add(new Microsoft.UI.Xaml.Setter(Microsoft.UI.Xaml.FrameworkElement.MarginProperty, new Microsoft.UI.Xaml.Thickness(0, 2, 0, 0)));
70-
cbStyle.Setters.Add(new Microsoft.UI.Xaml.Setter(Microsoft.UI.Xaml.FrameworkElement.MinHeightProperty, 0.0));
71-
cbStyle.Setters.Add(new Microsoft.UI.Xaml.Setter(Microsoft.UI.Xaml.FrameworkElement.MinWidthProperty, 0.0));
72-
cbStyle.Setters.Add(new Microsoft.UI.Xaml.Setter(Microsoft.UI.Xaml.Controls.Control.PaddingProperty, new Microsoft.UI.Xaml.Thickness(6, 0, 0, 0)));
73-
this.Resources["UnoSearchOptionCheckBoxStyle"] = cbStyle;
7426
}
7527

7628
protected override void OnLaunched(LaunchActivatedEventArgs args)
@@ -96,18 +48,14 @@ private static void OnUnhandledException(object sender, Microsoft.UI.Xaml.Unhand
9648

9749
private static void OnDomainException(object sender, System.UnhandledExceptionEventArgs e)
9850
{
99-
var msg = $"[DOMAIN] {e.ExceptionObject}";
100-
System.Diagnostics.Debug.WriteLine(msg);
101-
Console.Error.WriteLine(msg);
102-
System.IO.File.AppendAllText("crash.log", msg + "\n");
51+
System.Diagnostics.Debug.WriteLine($"[DOMAIN] {e.ExceptionObject}");
52+
Console.Error.WriteLine($"Fatal: {e.ExceptionObject}");
10353
}
10454

10555
private static void ShowFatal(Exception ex)
10656
{
107-
var msg = $"Fatal during launch: {ex}";
108-
System.Diagnostics.Debug.WriteLine(msg);
109-
Console.Error.WriteLine(msg);
110-
System.IO.File.AppendAllText("crash.log", msg + "\n");
57+
System.Diagnostics.Debug.WriteLine($"[FATAL] {ex}");
58+
Console.Error.WriteLine($"Fatal during launch: {ex}");
11159
// Show a simple WinUI dialog — create a minimal window just for the message.
11260
var w = new Microsoft.UI.Xaml.Window();
11361
var tb = new Microsoft.UI.Xaml.Controls.TextBlock

src/UnoEdit.WinUI.Sample/UnoEdit.WinUI.Sample.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
</ItemGroup>
2727

2828
<ItemGroup>
29-
<!-- Exclude the resource dictionary from XAML compilation (it has no x:Class) -->
29+
<!-- Keep UnoEditorResources as loose XAML loaded at runtime from OnLaunched. -->
3030
<Page Remove="UnoEditorResources.xaml" />
31-
<Content Include="UnoEditorResources.xaml" />
31+
<Content Include="UnoEditorResources.xaml">
32+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
33+
</Content>
3234
</ItemGroup>
3335
</Project>

src/UnoEdit.WinUI.Sample/UnoEditorResources.xaml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@
1313
<x:Double x:Key="UnoEditorOverlayHeight">16</x:Double>
1414
<x:Double x:Key="UnoEditorCaretWidth">2</x:Double>
1515

16+
<Style x:Key="UnoSearchActionButtonStyle" TargetType="Button">
17+
<Setter Property="MinWidth" Value="44" />
18+
<Setter Property="MinHeight" Value="32" />
19+
<Setter Property="Foreground" Value="{ThemeResource UnoEditorTitleBarForegroundBrush}" />
20+
</Style>
21+
22+
<Style x:Key="UnoSearchOptionCheckBoxStyle" TargetType="CheckBox">
23+
<Setter Property="VerticalAlignment" Value="Center" />
24+
<Setter Property="Margin" Value="0,2,0,0" />
25+
<Setter Property="MinHeight" Value="0" />
26+
<Setter Property="MinWidth" Value="0" />
27+
<Setter Property="Padding" Value="6,0,0,0" />
28+
</Style>
29+
1630
<ResourceDictionary.ThemeDictionaries>
1731
<ResourceDictionary x:Key="Dark">
1832
<SolidColorBrush x:Key="UnoEditorBackgroundBrush" Color="#0F172A" />
@@ -46,17 +60,4 @@
4660
</ResourceDictionary>
4761
</ResourceDictionary.ThemeDictionaries>
4862

49-
<Style x:Key="UnoSearchActionButtonStyle" TargetType="Button">
50-
<Setter Property="MinWidth" Value="44" />
51-
<Setter Property="MinHeight" Value="32" />
52-
<Setter Property="Foreground" Value="{ThemeResource UnoEditorTitleBarForegroundBrush}" />
53-
</Style>
54-
55-
<Style x:Key="UnoSearchOptionCheckBoxStyle" TargetType="CheckBox">
56-
<Setter Property="VerticalAlignment" Value="Center" />
57-
<Setter Property="Margin" Value="0,2,0,0" />
58-
<Setter Property="MinHeight" Value="0" />
59-
<Setter Property="MinWidth" Value="0" />
60-
<Setter Property="Padding" Value="6,0,0,0" />
61-
</Style>
6263
</ResourceDictionary>

0 commit comments

Comments
 (0)