Skip to content

Copilot/implement winform controls lvgl#3

Merged
maikebing merged 2 commits intomasterfrom
copilot/implement-winform-controls-lvgl
Mar 14, 2026
Merged

Copilot/implement winform controls lvgl#3
maikebing merged 2 commits intomasterfrom
copilot/implement-winform-controls-lvgl

Conversation

@maikebing
Copy link
Copy Markdown
Member

No description provided.

在 `frmMain.Designer.cs` 中添加了多个控件,并调整了控件的大小和位置。重构了 `LinuxView.cs` 和 `Application.cs` 中的事件处理和应用程序生命周期管理逻辑。删除了与 DPI 和 Windows API 相关的文件。重构了 `Control.cs` 和 `Form.cs` 中的控件和窗体的创建和销毁逻辑。添加了 `PerformFlowLayout` 和表格布局支持。更新了字体管理逻辑以使用 `SixLabors.Fonts`。添加了基本的图形结构体和资源管理文件。
Copilot AI review requested due to automatic review settings March 14, 2026 19:27
@maikebing maikebing merged commit 4dd0cc6 into master Mar 14, 2026
2 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the LVGL-based WinForms compatibility layer toward a more WinForms-like lifecycle (Application.Run, Form.Show/CreateHandle/DestroyHandle) while expanding layout behavior (dock/anchor and basic flow/table layouts) and removing older Win32/DPI helper utilities.

Changes:

  • Introduces a window-host abstraction (IWindow + WindowHostFactory) and updates the Win32 host loop to expose ProcessEvents()/Stop().
  • Implements layout behaviors in Control plus adds custom layout logic for FlowLayoutPanel and TableLayoutPanel (including spans).
  • Removes old DPI/window sizing helpers and replaces System.Drawing usage with custom LVGLSharp.Darwing types; updates the demo designer/resources.

Reviewed changes

Copilot reviewed 31 out of 32 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
src/LVGLSharp.WinForms/WindowSizeCalculator.cs Removed legacy Win32 window-rect sizing helper.
src/LVGLSharp.WinForms/NativeMethods.cs Removed legacy Win32 P/Invoke + DPI helpers.
src/LVGLSharp.WinForms/DpiHelper.cs Removed legacy DPI awareness/window DPI helper.
src/LVGLSharp.WinForms/Runtime/Core/IWindow.cs Redefines IWindow to expose LVGL root/group + event loop APIs.
src/LVGLSharp.WinForms/Runtime/Core/WindowHostFactory.cs Declares platform factory for creating IWindow hosts.
src/LVGLSharp.WinForms/Runtime/Windows/WindowHostFactory.cs Windows implementation of the host factory using Win32Window.
src/LVGLSharp.WinForms/Runtime/Windows/Win32Api.cs Adds DestroyWindow P/Invoke for shutdown.
src/LVGLSharp.WinForms/Runtime/Windows/Win32Window.cs Exposes Root/Group/Callback and splits loop into ProcessEvents()/Stop().
src/LVGLSharp.WinForms/Runtime/Core/SixLaborsFontManager.cs Adds explicit type aliases to avoid naming collisions across SixLabors types.
src/LVGLSharp.WinForms/Forms/Application.cs Replaces sample UI code with Application.Run, DoEvents, Exit, OpenForms tracking.
src/LVGLSharp.WinForms/Forms/Form.cs Moves to WinForms-like handle creation + delegates window hosting to IWindow.
src/LVGLSharp.WinForms/Forms/FormCollection.cs Adds OpenForms read-only collection type.
src/LVGLSharp.WinForms/Forms/Control.cs Adds layout processing, suspend/resume, bounds updates, and LVGL property syncing.
src/LVGLSharp.WinForms/Forms/ControlCollection.cs Adds owner-aware add/remove hooks and TableLayoutPanel positional add overload.
src/LVGLSharp.WinForms/Forms/TableLayoutPanel.cs Implements table layout sizing + positioning, plus row/column spans.
src/LVGLSharp.WinForms/Forms/FlowLayoutPanel.cs Implements a simple flow layout pass before creating LVGL children.
src/LVGLSharp.WinForms/Forms/Padding.cs Converts Padding into an immutable struct with helpers.
src/LVGLSharp.WinForms/Forms/LayoutEventArgs.cs Makes LayoutEventArgs an EventArgs with affected control/property.
src/LVGLSharp.WinForms/Forms/ControlEventArgs.cs Makes ControlEventArgs an EventArgs containing the affected control.
src/LVGLSharp.WinForms/Forms/BoundsSpecified.cs Converts BoundsSpecified to a [Flags] enum.
src/LVGLSharp.WinForms/Forms/Class1.cs Removes unused placeholder file.
src/LVGLSharp.WinForms/Forms/Form.resx Adds designer resource scaffold.
src/LVGLSharp.WinForms/Forms/GroupBox.resx Adds designer resource scaffold.
src/LVGLSharp.WinForms/Forms/ListBox.resx Adds designer resource scaffold.
src/LVGLSharp.WinForms/Darwing/Point.cs Adds custom Point type replacing System.Drawing usage.
src/LVGLSharp.WinForms/Darwing/Size.cs Adds custom Size type replacing System.Drawing usage.
src/LVGLSharp.WinForms/Darwing/SizeF.cs Adds custom SizeF type replacing System.Drawing usage.
src/LVGLSharp.WinForms/Darwing/Rectangle.cs Adds custom Rectangle type replacing System.Drawing usage.
src/LVGLSharp.WinForms/Darwing/Color.cs Adds custom Color type replacing System.Drawing usage.
src/LVGLSharp.Runtime.Linux/LinuxView.cs Updates Linux host loop to route through ProcessEvents()/Stop() (in that project).
src/Demos/WinFormsDemo/frmMain.Designer.cs Updates demo layout/content and adds additional controls.
.github/copilot-instructions.md Adds repo-specific Copilot guidance (WinForms lifecycle preference, avoid System.Drawing).
Files not reviewed (1)
  • src/Demos/WinFormsDemo/frmMain.Designer.cs: Language not supported

Comment on lines 8 to +16
namespace LVGLSharp
{
public unsafe interface IWindow
{
public static lv_obj_t* root { get; set; }
public static lv_group_t* key_inputGroup { get; set; }
public static delegate* unmanaged[Cdecl]<lv_event_t*, void> SendTextAreaFocusCb { get; set; }
/// <summary>
/// Gets the root LVGL object for the current host window.
/// </summary>
lv_obj_t* Root { get; }

Comment on lines +7 to +9
internal static partial IWindow Create(string title, int width, int height)
=> new Win32Window(title, (uint)width, (uint)height);
}
Comment on lines +396 to +403
public void Stop()
{
g_running = false;
Marshal.FreeHGlobal(g_lvbuf);

if (g_hwnd != IntPtr.Zero)
{
DestroyWindow(g_hwnd);
}
Comment on lines 366 to +374
public void StartLoop(Action handle)
{
while (g_running)
{
lv_timer_handler();
ProcessEvents();
handle?.Invoke();
if (PeekMessage(out msg, IntPtr.Zero, 0, 0, 1))
Thread.Sleep(5);
}

Comment on lines 52 to 60
public void Add(Control item, int v, int v1)
{
_ctls.Add(item);
if (_owner is TableLayoutPanel tableLayoutPanel)
{
tableLayoutPanel.SetCellPosition(item, v, v1);
}

Add(item);
}
Comment on lines +56 to 62
/// <summary>
/// Processes all Windows messages currently in the message queue.
/// </summary>
public static void DoEvents()
{
lv_event_code_t code = lv_event_get_code(e);
if (code == lv_event_code_t.LV_EVENT_CLICKED)
{
fixed (byte* utf8Ptr = Encoding.ASCII.GetBytes("\0"))
lv_textarea_set_text(recv_textarea, utf8Ptr);
}
_mainForm?.ProcessEventsCore();
}
Comment on lines 164 to 180
// textBox1
//
textBox1.Location = new Point(3, 3);
textBox1.Multiline = true;
textBox1.Name = "textBox1";
textBox1.PlaceholderText = "输入的数据";
textBox1.PlaceholderText = "���������";
textBox1.Size = new Size(570, 50);
textBox1.TabIndex = 0;
//
// send_btn
//
send_btn.Location = new Point(579, 3);
send_btn.Name = "send_btn";
send_btn.Size = new Size(75, 37);
send_btn.Size = new Size(106, 50);
send_btn.TabIndex = 2;
send_btn.Text = "发送";
send_btn.Text = "����";
send_btn.UseVisualStyleBackColor = true;
Comment on lines 194 to 220
@@ -190,32 +198,79 @@ private void InitializeComponent()
recv_textarea.Name = "recv_textarea";
recv_textarea.Size = new Size(504, 183);
recv_textarea.TabIndex = 0;
recv_textarea.Text = "接收的数据...";
recv_textarea.Text = "���յ�����...";
//
// clear_btn
//
clear_btn.Location = new Point(513, 3);
clear_btn.Name = "clear_btn";
clear_btn.Size = new Size(75, 41);
clear_btn.TabIndex = 2;
clear_btn.Text = "清空";
clear_btn.Text = "���";
clear_btn.UseVisualStyleBackColor = true;
clear_btn.Click += button1_Click;
//
// hex_switch
//
hex_switch.Location = new Point(3, 192);
hex_switch.Location = new Point(594, 3);
hex_switch.Name = "hex_switch";
hex_switch.Size = new Size(91, 41);
hex_switch.TabIndex = 3;
hex_switch.Text = "HEX模式";
hex_switch.Text = "HEXģʽ";
hex_switch.UseVisualStyleBackColor = true;
@@ -0,0 +1,26 @@
namespace LVGLSharp.Darwing
private readonly Dictionary<Control, (int col, int row)> _cellPositions = new();
private readonly Dictionary<Control, int> _columnSpans = new();
private readonly Dictionary<Control, int> _rowSpans = new();

@maikebing maikebing deleted the copilot/implement-winform-controls-lvgl branch March 15, 2026 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants