Skip to content

Commit

Permalink
Bump to version 1.0.63;
Browse files Browse the repository at this point in the history
Move all Color structs to ImageSharp;
Make modal close cancel check async;
  • Loading branch information
onepiecefreak3 committed Sep 9, 2024
1 parent 73fbbd6 commit 973efd8
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 22 deletions.
2 changes: 1 addition & 1 deletion ImGui.Forms/Controls/Base/ActivableComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected bool ToggleActive(bool toggleActive)

private void OnActivated()
{
Activated?.Invoke(this, new EventArgs());
Activated?.Invoke(this, EventArgs.Empty);
}
}
}
4 changes: 3 additions & 1 deletion ImGui.Forms/Controls/Layouts/ZLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions ImGui.Forms/Controls/Lists/BaseList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand All @@ -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 :
Expand Down
5 changes: 2 additions & 3 deletions ImGui.Forms/Controls/ProgressBar.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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()
{
Expand Down
15 changes: 9 additions & 6 deletions ImGui.Forms/Extensions/ColorExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
using System.Drawing;
using System.Numerics;
using System.Numerics;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;

namespace ImGui.Forms.Extensions
{
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<Rgba32>();
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<Rgba32>();
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));
}
}
}
5 changes: 5 additions & 0 deletions ImGui.Forms/Form.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public void PopModal()
_modals.Last().ChildModal = null;
}

public bool HasOpenModals()
{
return _modals.Count > 0;
}

public void Update()
{
// Set icon
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.62</version>
<version>1.0.63</version>
<description>A WinForms-inspired object-oriented framework around Dear ImGui (https://github.com/ocornut/imgui)</description>

<authors>onepiecefreak</authors>
Expand Down
8 changes: 4 additions & 4 deletions ImGui.Forms/Modals/Modal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected override async void UpdateInternal(Rectangle contentRect)
ImGuiNET.ImGui.PopStyleColor();

if (!exists)
_shouldClose = !ShouldCancelClose();
Close();
}

public async Task<DialogResult> ShowAsync(bool blockFormClosing = false)
Expand Down Expand Up @@ -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
Expand All @@ -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<bool> ShouldCancelClose() => Task.FromResult(false);

#region Helper

Expand Down
8 changes: 4 additions & 4 deletions ImGui.Forms/Style.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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()
{
Expand All @@ -234,7 +234,7 @@ private Color GetColor()
return _darkColor;

default:
return Color.Empty;
return Color.Transparent;
}
}

Expand Down

0 comments on commit 973efd8

Please sign in to comment.