From fd4ba13cfa2767d4bb34d070983427023b9d7dc8 Mon Sep 17 00:00:00 2001 From: onepiecefreak3 Date: Sat, 23 Mar 2024 15:23:13 +0100 Subject: [PATCH] Fix contentRect for TableLayouts, if it's centered in at least one dimension; Fix PictureBox not being able to receive image dimensions; Adjust application starting position; --- ImGui.Forms/Application.cs | 10 ++-------- ImGui.Forms/Controls/Label.cs | 2 +- ImGui.Forms/Controls/Layouts/TableLayout.cs | 8 ++++---- ImGui.Forms/Controls/PictureBox.cs | 2 +- ImGui.Forms/ImGui.Forms.nuspec | 2 +- 5 files changed, 9 insertions(+), 15 deletions(-) diff --git a/ImGui.Forms/Application.cs b/ImGui.Forms/Application.cs index aa0c306..f6631c5 100644 --- a/ImGui.Forms/Application.cs +++ b/ImGui.Forms/Application.cs @@ -16,7 +16,7 @@ public class Application private bool _isClosing; private bool _shouldClose; - private GraphicsBackend? _backend = null; + private GraphicsBackend? _backend; private ExecutionContext _executionContext; @@ -125,7 +125,7 @@ private void CreateApplication(Form form) private void CreateWindow(Form form, out Sdl2Window window, out GraphicsDevice gd) { - var windowInfo = new WindowCreateInfo(20, 20, form.Width, form.Height, WindowState.Normal, form.Title); + var windowInfo = new WindowCreateInfo(50, 70, form.Width, form.Height, WindowState.Normal, form.Title); var graphicsDeviceOptions = new GraphicsDeviceOptions(true, null, true, ResourceBindingModel.Improved, true, true); if (_backend.HasValue) @@ -259,22 +259,16 @@ private void Window_Resized() private void Window_DragDrop(DragDropEvent obj) { - Console.WriteLine("[EVENT] DragDrop"); - _dragDropEvent = new DragDropEventEx(obj, ImGuiNET.ImGui.GetMousePos()); } private void Window_KeyUp(KeyEvent obj) { - Console.WriteLine("[EVENT] KeyUp"); - _keyUpCommand = new KeyCommand(obj.Modifiers, obj.Key); } private void Window_KeyDown(KeyEvent obj) { - Console.WriteLine("[EVENT] KeyDown"); - _keyDownCommand = new KeyCommand(obj.Modifiers, obj.Key); } diff --git a/ImGui.Forms/Controls/Label.cs b/ImGui.Forms/Controls/Label.cs index 344c61c..4e77024 100644 --- a/ImGui.Forms/Controls/Label.cs +++ b/ImGui.Forms/Controls/Label.cs @@ -83,7 +83,7 @@ protected override void RemoveStyles() protected string EscapeText() { - return (Text.ToString()).Replace("\n", Environment.NewLine); + return Text.ToString().Replace("\n", Environment.NewLine); } } } diff --git a/ImGui.Forms/Controls/Layouts/TableLayout.cs b/ImGui.Forms/Controls/Layouts/TableLayout.cs index 066bb7f..1146eed 100644 --- a/ImGui.Forms/Controls/Layouts/TableLayout.cs +++ b/ImGui.Forms/Controls/Layouts/TableLayout.cs @@ -87,15 +87,15 @@ protected override void UpdateInternal(Rectangle contentRect) if (ImGuiNET.ImGui.BeginChild($"{Id}", contentRect.Size, ImGuiChildFlags.None, childFlags)) { - Vector2 cellPosition = GetInitPoint(localWidths, localHeights, contentRect); - ImGuiNET.ImGui.SetCursorPos(cellPosition); + Vector2 initPosition = GetInitPoint(localWidths, localHeights, contentRect); + ImGuiNET.ImGui.SetCursorPos(initPosition); float outerScrollX = ImGuiNET.ImGui.GetScrollX(); float outerScrollY = ImGuiNET.ImGui.GetScrollY(); if (ImGuiNET.ImGui.BeginChild($"{Id}-in", new Vector2(totalWidth, totalHeight), ImGuiChildFlags.None, ImGuiWindowFlags.NoScrollbar)) { - cellPosition = Vector2.Zero; + var cellPosition = Vector2.Zero; float origX = cellPosition.X; float innerScrollX = ImGuiNET.ImGui.GetScrollX(); @@ -163,7 +163,7 @@ protected override void UpdateInternal(Rectangle contentRect) if (ImGuiNET.ImGui.BeginChild($"{Id}-{r}-{c}-content", new Vector2(cellInternalWidth, cellInternalHeight), ImGuiChildFlags.None, ImGuiWindowFlags.NoScrollbar)) { // Draw component - cell.Content?.Update(new Rectangle((int)(contentRect.X + cellPosition.X + cellXOffset - outerScrollX - innerScrollX), (int)(contentRect.Y + cellPosition.Y + cellYOffset - outerScrollY - innerScrollY), cellInternalWidth, cellInternalHeight)); + cell.Content?.Update(new Rectangle((int)(contentRect.X + initPosition.X + cellPosition.X + cellXOffset - outerScrollX - innerScrollX), (int)(contentRect.Y + initPosition.Y + cellPosition.Y + cellYOffset - outerScrollY - innerScrollY), cellInternalWidth, cellInternalHeight)); } ImGuiNET.ImGui.EndChild(); diff --git a/ImGui.Forms/Controls/PictureBox.cs b/ImGui.Forms/Controls/PictureBox.cs index 377921c..1263596 100644 --- a/ImGui.Forms/Controls/PictureBox.cs +++ b/ImGui.Forms/Controls/PictureBox.cs @@ -23,7 +23,7 @@ public ImageResource Image public override Size GetSize() { - return new Size(_baseImg.Width, _baseImg.Height); + return new Size(_baseImg?.Width ?? 0, _baseImg?.Height ?? 0); } protected override void UpdateInternal(Rectangle contentRect) diff --git a/ImGui.Forms/ImGui.Forms.nuspec b/ImGui.Forms/ImGui.Forms.nuspec index 290a3b7..06f7603 100644 --- a/ImGui.Forms/ImGui.Forms.nuspec +++ b/ImGui.Forms/ImGui.Forms.nuspec @@ -2,7 +2,7 @@ Imgui.Forms - 1.0.52 + 1.0.54 A WinForms-inspired object-oriented framework around Dear ImGui (https://github.com/ocornut/imgui) onepiecefreak