Skip to content

Commit 87bda8b

Browse files
committed
跨平台窗口适配:支持 Windows 和 Linux
本次提交通过条件编译引入不同平台的运行时命名空间,并新增 CreateWindow 方法以根据操作系统创建对应窗口类型。同时在项目文件中增加了对 Windows 和 Linux 运行时的引用,提升了程序的跨平台能力。
1 parent dfd7c67 commit 87bda8b

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/Demos/SerialPort/Program.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using LVGLSharp;
22
using LVGLSharp.Interop;
3+
using LVGLSharp.Runtime.Windows;
4+
using LVGLSharp.Runtime.Linux;
5+
using System.ComponentModel.Design;
36
using System.Diagnostics;
47
using System.IO.Ports;
58
using System.Runtime.CompilerServices;
@@ -28,7 +31,7 @@ unsafe class Program
2831

2932
static void Main(string[] args)
3033
{
31-
window = PlatformWindowFactory.Create();
34+
window = CreateWindow();
3235
window.Init();
3336

3437
root = window.Root;
@@ -40,6 +43,18 @@ static void Main(string[] args)
4043
window.StartLoop(() => { });
4144
}
4245

46+
static IWindow CreateWindow()
47+
{
48+
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
49+
{
50+
return new Win32Window("SerialPort", 700, 360);
51+
}
52+
else
53+
{
54+
return new LinuxView();
55+
}
56+
}
57+
4358
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
4459
static unsafe void RefButtonClick(lv_event_t* obj)
4560
{

src/Demos/SerialPort/SerialPort.csproj

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22

33
<PropertyGroup>
44
<OutputType>WinExe</OutputType>
5-
<TargetFrameworks>net10.0-windows;net10.0</TargetFrameworks>
5+
<TargetFramework>net10.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<InvariantGlobalization>true</InvariantGlobalization>
99
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
10-
</PropertyGroup>
11-
12-
<PropertyGroup Condition="'$(TargetFramework)' == 'net10.0'">
13-
<PublishAot>true</PublishAot>
10+
<PublishAot>true</PublishAot>
1411
</PropertyGroup>
1512

1613
<ItemGroup>
@@ -21,6 +18,8 @@
2118

2219
<ItemGroup>
2320
<ProjectReference Include="..\..\LVGLSharp.Core\LVGLSharp.Core.csproj" />
21+
<ProjectReference Include="..\..\LVGLSharp.Windows\LVGLSharp.Runtime.Windows.csproj" />
22+
<ProjectReference Include="..\..\LVGLSharp.Runtime.Linux\LVGLSharp.Runtime.Linux.csproj" />
2423
</ItemGroup>
2524

2625
</Project>

0 commit comments

Comments
 (0)