Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
vape committed Jul 18, 2024
2 parents 9ae357f + fb3fcb0 commit 4f61112
Show file tree
Hide file tree
Showing 104 changed files with 2,498 additions and 1,979 deletions.
8 changes: 6 additions & 2 deletions Runtime/Resources/imui_default.shader
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[PerRendererData] _MaskEnable("Enable Masking", int) = 0
[PerRendererData] _MaskRect("Mask Rect", Vector) = (0, 0, 0, 0)
[PerRendererData] _MaskCornerRadius("Mask Corner Radius", float) = 0
[PerRendererData] _Contrast("Contrast", float) = 1
}

SubShader
Expand Down Expand Up @@ -50,6 +51,7 @@
bool _MaskEnable;
float4 _MaskRect;
float _MaskCornerRadius;
float _Contrast;

// simplified signed distance round box from here: https://iquilezles.org/articles/distfunctions2d/
float sdf_round_box(in float2 p, in float2 s, in float r)
Expand All @@ -75,10 +77,12 @@
col.a *= _MaskEnable
? 1 - saturate(sdf_round_box(i.vertex.xy - _MaskRect.xy, _MaskRect.zw, _MaskCornerRadius) * 2 + 1)
: 1;
col *= i.color;
col.rgb = ((col.rgb - 0.5f) * (1 - _Contrast)) + 0.5f;

return i.color * col;
return col;
}

ENDCG
}
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
using Imui.Core;
using UnityEngine;

namespace Imui.Controls.Layout
namespace Imui.Controls
{
public static class ImLayoutGroup
public static class ImLayoutExt
{
public static Vector2 GetAvailableSize(this ImGui gui)
public static Vector2 GetLayoutSize(this ImGui gui)
{
return gui.Layout.GetAvailableSize();
}

public static float GetAvailableWidth(this ImGui gui)
public static float GetLayoutWidth(this ImGui gui)
{
return gui.Layout.GetAvailableWidth();
}

public static float GetAvailableHeight(this ImGui gui)
public static float GetLayoutHeight(this ImGui gui)
{
return gui.Layout.GetAvailableHeight();
}

public static ImRect GetLayoutBounds(this ImGui gui)
{
return gui.Layout.GetBoundsRect();
}

public static ImRect AddLayoutRect(this ImGui gui, float width, float height)
{
return gui.Layout.AddRect(width, height);
}

public static ImRect AddLayoutRectWithSpacing(this ImGui gui, float width, float height)
{
gui.AddSpacingIfLayoutFrameNotEmpty();

return gui.Layout.AddRect(width, height);
}

public static void BeginVertical(this ImGui gui, float width = 0.0f, float height = 0.0f)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
using Imui.Core;
using Imui.Styling;
using Imui.Controls.Styling;
using UnityEngine;

namespace Imui.Utility
namespace Imui.Controls
{
public static class RectUtility
public static class ImRectExt
{
public static Vector2 Max(this Vector2 vec, float x, float y)
{
return new Vector2(Mathf.Max(vec.x, x), Mathf.Max(vec.y, y));
}

public static Rect Intersection(this Rect rect, Rect other)
{
var x1 = Mathf.Max(rect.x, other.x);
var y1 = Mathf.Max(rect.y, other.y);
var x2 = Mathf.Min(rect.x + rect.width, other.x + other.width);
var y2 = Mathf.Min(rect.y + rect.height, other.y + other.height);

return new Rect(x1, y1, x2 - x1, y2 - y1);
}

public static ImRect SplitTop(this ImRect rect, float height)
{
rect.Y += rect.H - height;
Expand All @@ -29,48 +19,32 @@ public static ImRect SplitTop(this ImRect rect, float height)
}


public static ImRect SplitTop(this ImRect rect, float height, out ImRect next)
public static ImRect SplitTop(this ImRect rect, float height, out ImRect bottom)
{
next = rect;
next.H = rect.H - height;
rect.Y += next.H;
bottom = rect;
bottom.H = rect.H - height;
rect.Y += bottom.H;
rect.H = height;
return rect;
}

public static ImRect SplitLeft(this ImRect rect, float width, out ImRect next)
public static ImRect SplitLeft(this ImRect rect, float width, out ImRect right)
{
next = rect;
next.X += width;
next.W = rect.W - width;
right = rect;
right.X += width;
right.W = rect.W - width;
rect.W = width;
return rect;
}

public static ImRect SplitLeft(this ImRect rect, float width, float space, out ImRect next)
public static ImRect SplitLeft(this ImRect rect, float width, float space, out ImRect right)
{
next = rect;
next.X += width + space;
next.W = rect.W - width - space;
right = rect;
right.X += width + space;
right.W = rect.W - width - space;
rect.W = width;
return rect;
}

public static void AddPadding(this ref ImRect rect, float size)
{
rect.X += size;
rect.Y += size;
rect.W -= size * 2;
rect.H -= size * 2;
}

public static void AddPadding(this ref ImRect rect, ImPadding padding)
{
rect.X += padding.Left;
rect.Y += padding.Bottom;
rect.W -= padding.Left + padding.Right;
rect.H -= padding.Top + padding.Bottom;
}

public static ImRect WithAspect(this ImRect rect, float aspect)
{
Expand All @@ -92,17 +66,7 @@ public static ImRect WithPadding(this ImRect rect, float size)

return rect;
}

public static ImRect WithPadding(this ImRect rect, float left, float top, float right, float bottom)
{
rect.X += left;
rect.Y += bottom;
rect.W -= left + right;
rect.H -= top + bottom;

return rect;
}


public static ImRect WithPadding(this ImRect rect, ImPadding padding)
{
rect.X += padding.Left;
Expand All @@ -112,39 +76,58 @@ public static ImRect WithPadding(this ImRect rect, ImPadding padding)

return rect;
}

public static void ApplyPadding(this ref ImRect rect, float padding)
public static void AddPaddingToSize(ref Vector2 size, ImPadding padding)
{
rect.X += padding;
rect.Y += padding;
rect.W -= padding * 2;
rect.H -= padding * 2;
size.x += padding.Left + padding.Right;
size.y += padding.Bottom + padding.Top;
}

public static void ApplyPadding(this ref ImRect rect, ImPadding padding)
public static void AddPadding(this ref ImRect rect, ImPadding padding)
{
rect.X += padding.Left;
rect.Y += padding.Bottom;
rect.W -= padding.Left + padding.Right;
rect.H -= padding.Top + padding.Bottom;
}

public static ImRect WithMargin(this ImRect rect, ImPadding margin)
{
rect.X -= margin.Left;
rect.Y -= margin.Bottom;
rect.W += margin.Left + margin.Right;
rect.H += margin.Top + margin.Bottom;

return rect;
}

public static ImRect ScaleFromCenter(this ImRect rect, float scale)
{
var w = rect.W;
var h = rect.H;

rect.W *= scale;
rect.H *= scale;
rect.X += rect.W * 0.5f;
rect.Y += rect.H * 0.5f;
rect.X += (w - rect.W) * 0.5f;
rect.Y += (h - rect.H) * 0.5f;

return rect;
}

public static ImRect Clamp(ImRect bounds, ImRect rect)
{
rect.W = Mathf.Min(rect.W, bounds.W);
rect.H = Mathf.Min(rect.H, bounds.H);

if (rect.X < bounds.X)
{
rect.X += bounds.X - rect.X;
}

if (rect.Right > bounds.Right)
{
rect.X -= rect.Right - bounds.Right;
}

if (rect.Y < bounds.Y)
{
rect.Y += bounds.Y - rect.Y;
}

if (rect.Top > bounds.Top)
{
rect.Y -= rect.Top - bounds.Top;
}

return rect;
}
Expand Down
File renamed without changes.
25 changes: 25 additions & 0 deletions Runtime/Scripts/Controls/ImBox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using Imui.Core;
using UnityEngine;

namespace Imui.Controls
{
public static class ImBox
{
public static void Box(this ImGui gui, ImRect rect, in ImBoxStyle style)
{
gui.Canvas.RectWithOutline(rect, style.BackColor, style.BorderColor, style.BorderWidth, style.BorderRadius);
}
}


[Serializable]
public struct ImBoxStyle
{
public Color32 BackColor;
public Color32 FrontColor;
public Color32 BorderColor;
public float BorderWidth;
public ImRectRadius BorderRadius;
}
}
3 changes: 3 additions & 0 deletions Runtime/Scripts/Controls/ImBox.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4f61112

Please sign in to comment.