Skip to content

Commit

Permalink
Fix contentRect for TableLayouts, if it's centered in at least one di…
Browse files Browse the repository at this point in the history
…mension;

Fix PictureBox not being able to receive image dimensions;
Adjust application starting position;
  • Loading branch information
onepiecefreak3 committed Mar 23, 2024
1 parent 45a7ca0 commit fd4ba13
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 15 deletions.
10 changes: 2 additions & 8 deletions ImGui.Forms/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Application
private bool _isClosing;
private bool _shouldClose;

private GraphicsBackend? _backend = null;
private GraphicsBackend? _backend;

private ExecutionContext _executionContext;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion ImGui.Forms/Controls/Label.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
8 changes: 4 additions & 4 deletions ImGui.Forms/Controls/Layouts/TableLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion ImGui.Forms/Controls/PictureBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ImGui.Forms/ImGui.Forms.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>Imgui.Forms</id>
<version>1.0.52</version>
<version>1.0.54</version>
<description>A WinForms-inspired object-oriented framework around Dear ImGui (https://github.com/ocornut/imgui)</description>

<authors>onepiecefreak</authors>
Expand Down

0 comments on commit fd4ba13

Please sign in to comment.