diff --git a/ImGui.Forms/Controls/Base/ActivableComponent.cs b/ImGui.Forms/Controls/Base/ActivableComponent.cs index 428bf13..0bd5e51 100644 --- a/ImGui.Forms/Controls/Base/ActivableComponent.cs +++ b/ImGui.Forms/Controls/Base/ActivableComponent.cs @@ -35,7 +35,7 @@ protected bool ToggleActive(bool toggleActive) private void OnActivated() { - Activated?.Invoke(this, new EventArgs()); + Activated?.Invoke(this, EventArgs.Empty); } } } diff --git a/ImGui.Forms/Controls/Layouts/ZLayout.cs b/ImGui.Forms/Controls/Layouts/ZLayout.cs index f896610..584961e 100644 --- a/ImGui.Forms/Controls/Layouts/ZLayout.cs +++ b/ImGui.Forms/Controls/Layouts/ZLayout.cs @@ -12,9 +12,11 @@ public class ZLayout : Component public Vector2 ItemSpacing { get; set; } + public Size Size { get; set; } = Size.Parent; + public override Size GetSize() { - return Size.Parent; + return Size; } protected override void UpdateInternal(Rectangle contentRect) diff --git a/ImGui.Forms/Controls/Lists/BaseList.cs b/ImGui.Forms/Controls/Lists/BaseList.cs index e51d0ec..8c57649 100644 --- a/ImGui.Forms/Controls/Lists/BaseList.cs +++ b/ImGui.Forms/Controls/Lists/BaseList.cs @@ -39,7 +39,7 @@ public BaseList() protected override int GetContentWidth(int parentWidth, float layoutCorrection = 1) { - var widths = Items.Select(x => x.GetWidth(parentWidth, layoutCorrection)).DefaultIfEmpty(Size.Width.IsParentAligned ? parentWidth : 0); + var widths = Items.Select(x => x.GetWidth(parentWidth, layoutCorrection)).DefaultIfEmpty(Size.Width.IsParentAligned ? parentWidth : 0).ToArray(); var totalWidth = Alignment == Alignment.Horizontal ? widths.Sum() + Math.Max(0, Items.Count - 1) * ItemSpacing : @@ -49,7 +49,7 @@ protected override int GetContentWidth(int parentWidth, float layoutCorrection = protected override int GetContentHeight(int parentHeight, float layoutCorrection = 1) { - var heights = Items.Select(x => x.GetHeight(parentHeight, layoutCorrection)).DefaultIfEmpty(Size.Height.IsParentAligned ? parentHeight : 0); + var heights = Items.Select(x => x.GetHeight(parentHeight, layoutCorrection)).DefaultIfEmpty(Size.Height.IsParentAligned ? parentHeight : 0).ToArray(); var totalHeight = Alignment == Alignment.Vertical ? heights.Sum() + Math.Max(0, Items.Count - 1) * ItemSpacing : diff --git a/ImGui.Forms/Controls/ProgressBar.cs b/ImGui.Forms/Controls/ProgressBar.cs index bbc505c..f245c27 100644 --- a/ImGui.Forms/Controls/ProgressBar.cs +++ b/ImGui.Forms/Controls/ProgressBar.cs @@ -1,11 +1,10 @@ using System; -using System.Drawing; using System.Numerics; using ImGui.Forms.Controls.Base; -using ImGui.Forms.Extensions; using ImGui.Forms.Localization; using ImGui.Forms.Resources; using ImGuiNET; +using SixLabors.ImageSharp; using Rectangle = Veldrid.Rectangle; using Size = ImGui.Forms.Models.Size; @@ -25,7 +24,7 @@ public class ProgressBar : Component public FontResource Font { get; set; } - public ThemedColor ProgressColor { get; set; } = Color.FromArgb(0x27, 0xBB, 0x65); + public ThemedColor ProgressColor { get; set; } = Color.FromRgba(0x27, 0xBB, 0x65, 0xFF); public override Size GetSize() { diff --git a/ImGui.Forms/Extensions/ColorExtensions.cs b/ImGui.Forms/Extensions/ColorExtensions.cs index 405f0e2..5628f7b 100644 --- a/ImGui.Forms/Extensions/ColorExtensions.cs +++ b/ImGui.Forms/Extensions/ColorExtensions.cs @@ -1,5 +1,6 @@ -using System.Drawing; -using System.Numerics; +using System.Numerics; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.PixelFormats; namespace ImGui.Forms.Extensions { @@ -7,22 +8,24 @@ public static class ColorExtensions { public static uint ToUInt32(this Color c) { - return (uint)((c.A << 24) | (c.B << 16) | (c.G << 8) | c.R); + var pixel = c.ToPixel(); + return (uint)((pixel.A << 24) | (pixel.B << 16) | (pixel.G << 8) | pixel.R); } public static Color ToColor(this uint value) { - return Color.FromArgb((byte)(value >> 24), (byte)value, (byte)(value >> 8), (byte)(value >> 16)); + return Color.FromRgba((byte)value, (byte)(value >> 8), (byte)(value >> 16), (byte)(value >> 24)); } public static Vector4 ToVector4(this Color c) { - return new Vector4(c.R / 255f, c.G / 255f, c.B / 255f, c.A / 255f); + var pixel = c.ToPixel(); + return new Vector4(pixel.R / 255f, pixel.G / 255f, pixel.B / 255f, pixel.A / 255f); } public static Color ToColor(this Vector4 value) { - return Color.FromArgb((int)(value.W * 255), (int)(value.X * 255), (int)(value.Y * 255), (int)(value.Z * 255)); + return Color.FromRgba((byte)(value.X * 255), (byte)(value.Y * 255), (byte)(value.Z * 255), (byte)(value.W * 255)); } } } diff --git a/ImGui.Forms/Form.cs b/ImGui.Forms/Form.cs index 2a4a6b1..5bb8048 100644 --- a/ImGui.Forms/Form.cs +++ b/ImGui.Forms/Form.cs @@ -85,6 +85,11 @@ public void PopModal() _modals.Last().ChildModal = null; } + public bool HasOpenModals() + { + return _modals.Count > 0; + } + public void Update() { // Set icon diff --git a/ImGui.Forms/ImGui.Forms.nuspec b/ImGui.Forms/ImGui.Forms.nuspec index abf3e99..85ce349 100644 --- a/ImGui.Forms/ImGui.Forms.nuspec +++ b/ImGui.Forms/ImGui.Forms.nuspec @@ -2,7 +2,7 @@ Imgui.Forms - 1.0.62 + 1.0.63 A WinForms-inspired object-oriented framework around Dear ImGui (https://github.com/ocornut/imgui) onepiecefreak diff --git a/ImGui.Forms/Modals/Modal.cs b/ImGui.Forms/Modals/Modal.cs index 7f037c4..7c39150 100644 --- a/ImGui.Forms/Modals/Modal.cs +++ b/ImGui.Forms/Modals/Modal.cs @@ -74,7 +74,7 @@ protected override async void UpdateInternal(Rectangle contentRect) ImGuiNET.ImGui.PopStyleColor(); if (!exists) - _shouldClose = !ShouldCancelClose(); + Close(); } public async Task ShowAsync(bool blockFormClosing = false) @@ -111,9 +111,9 @@ public void Close(DialogResult result) Close(); } - public void Close() + public async void Close() { - _shouldClose = !ShouldCancelClose(); + _shouldClose = !await ShouldCancelClose(); } // HINT: Only gets executed if _shouldClose is set to true @@ -134,7 +134,7 @@ protected virtual void ShowInternal() { } // HINT: Only gets executed if _shouldClose is set to true protected virtual Task CloseInternal() => Task.CompletedTask; - protected virtual bool ShouldCancelClose() => false; + protected virtual Task ShouldCancelClose() => Task.FromResult(false); #region Helper diff --git a/ImGui.Forms/Style.cs b/ImGui.Forms/Style.cs index c689c34..b6dc43a 100644 --- a/ImGui.Forms/Style.cs +++ b/ImGui.Forms/Style.cs @@ -1,9 +1,9 @@ using System.Collections.Generic; -using System.Drawing; using System.Numerics; using ImGui.Forms.Extensions; using ImGui.Forms.Models; using ImGuiNET; +using SixLabors.ImageSharp; namespace ImGui.Forms { @@ -208,12 +208,12 @@ public ThemedColor(ImGuiCol colIndex) { _colIndex = colIndex; - _lightColor = _darkColor = Color.Empty; + _lightColor = _darkColor = Color.Transparent; _hasColors = true; } - public bool IsEmpty => _hasColors && GetColor() == Color.Empty; + public bool IsEmpty => _hasColors && GetColor() == Color.Transparent; public uint ToUInt32() { @@ -234,7 +234,7 @@ private Color GetColor() return _darkColor; default: - return Color.Empty; + return Color.Transparent; } }