mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Improved UI of component edit window
- Also fixed some errors in list and dictionary editors
This commit is contained in:
@@ -255,6 +255,91 @@ namespace ImGui
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
/// Control to edit a vector 2 with drag functionality and reset buttons
|
||||
public static bool Float2Editor(StringView label, ref float2 value, float2 resetValues = .Zero, float dragSpeed = 0.1f, float2 minValue = .Zero, float2 maxValue = .Zero, bool2 componentEnabled = true, StringView[2] format = .())
|
||||
{
|
||||
return VectorEditor<2>(label, ref *(float[2]*)&value, (float[2])resetValues, dragSpeed, (float[2])minValue, (float[2])maxValue, (bool[2])componentEnabled, format);
|
||||
}
|
||||
|
||||
/// Control to edit a vector 3 with drag functionality and reset buttons
|
||||
public static bool Float3Editor(StringView label, ref float3 value, float3 resetValues = .Zero, float dragSpeed = 0.1f, float3 minValue = .Zero, float3 maxValue = .Zero, bool3 componentEnabled = true, StringView[3] format = .())
|
||||
{
|
||||
return VectorEditor<3>(label, ref *(float[3]*)&value, (float[3])resetValues, dragSpeed, (float[3])minValue, (float[3])maxValue, (bool[3])componentEnabled, format);
|
||||
}
|
||||
|
||||
/// Control to edit a vector 4 with drag functionality and reset buttons
|
||||
public static bool Float4Editor(StringView label, ref float4 value, float4 resetValues = .Zero, float dragSpeed = 0.1f, float4 minValue = .Zero, float4 maxValue = .Zero, bool4 componentEnabled = true, StringView[4] format = .())
|
||||
{
|
||||
return VectorEditor<4>(label, ref *(float[4]*)&value, (float[4])resetValues, dragSpeed, (float[4])minValue, (float[4])maxValue, (bool[4])componentEnabled, format);
|
||||
}
|
||||
|
||||
public static bool VectorEditor<NumComponents>(StringView label, ref float[NumComponents] value, float[NumComponents] resetValues = .(), float dragSpeed = 0.1f, float[NumComponents] minValue = .(), float[NumComponents] maxValue = .(), bool[NumComponents] componentEnabled = .(), StringView[NumComponents] numberFormat = .()) where NumComponents : const int32
|
||||
{
|
||||
const String[?] componentNames = .("X", "Y", "Z", "W");
|
||||
const String[?] componentIds = .("##X", "##Y", "##Z", "##W");
|
||||
|
||||
bool changed = false;
|
||||
|
||||
PushID(label);
|
||||
defer PopID();
|
||||
|
||||
PushMultiItemsWidths(NumComponents, CalcItemWidth());
|
||||
|
||||
float lineHeight = GetFont().FontSize + GetStyle().FramePadding.y * 2.0f;
|
||||
ImGui.Vec2 buttonSize = .(lineHeight + 3.0f, lineHeight);
|
||||
|
||||
componentLoop: for (int i < NumComponents)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
SameLine();
|
||||
}
|
||||
|
||||
PushStyleColor(.Button, VectorButtonColors[i].Default.ImGuiU32);
|
||||
PushStyleColor(.ButtonHovered, VectorButtonColors[i].Hovered.ImGuiU32);
|
||||
PushStyleColor(.ButtonActive, VectorButtonColors[i].Active.ImGuiU32);
|
||||
|
||||
ImGui.BeginDisabled(!componentEnabled[i]);
|
||||
|
||||
if (Button(componentNames[i], buttonSize))
|
||||
{
|
||||
value[i] = resetValues[i];
|
||||
changed = true;
|
||||
}
|
||||
|
||||
PushStyleVar(.ItemSpacing, Vec2.Zero);
|
||||
|
||||
SameLine();
|
||||
|
||||
char8* format = "%.3f";
|
||||
|
||||
if (!numberFormat[i].IsWhiteSpace)
|
||||
{
|
||||
// Look if we have a format for the specific index
|
||||
format = numberFormat[i].ToScopeCStr!:componentLoop();
|
||||
}
|
||||
else if (!numberFormat[0].IsWhiteSpace)
|
||||
{
|
||||
// Try to take the first number format
|
||||
format = numberFormat[0].ToScopeCStr!:componentLoop();
|
||||
}
|
||||
|
||||
if (DragFloat(componentIds[i], &value[i], dragSpeed, minValue[i], maxValue[i], format))
|
||||
{
|
||||
changed = true;
|
||||
}
|
||||
|
||||
PopStyleVar();
|
||||
|
||||
ImGui.EndDisabled();
|
||||
|
||||
PopItemWidth();
|
||||
PopStyleColor(3);
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
/// Draws a rectangle with the given color.
|
||||
public static void DrawRect(Vec2 min, Vec2 max, Color color)
|
||||
@@ -364,5 +449,46 @@ namespace ImGui
|
||||
#unwarn
|
||||
return SliderScalar(label, dataType, &value, &minValue, &maxValue, format, sliderFlags);
|
||||
}
|
||||
|
||||
public static void ListElementGrabber()
|
||||
{
|
||||
Window* window = GetCurrentWindow();
|
||||
if (window.SkipItems)
|
||||
return;
|
||||
|
||||
Context* g = GetCurrentContext();
|
||||
ref Style style = ref g.Style;
|
||||
|
||||
Vec2 cursorPos = ImGui.GetCursorScreenPos();
|
||||
|
||||
float line_height = max(min(window.DC.CurrLineSize.y, g.FontSize + style.FramePadding.y * 2), g.FontSize);
|
||||
Rect bb = .(cursorPos, Vec2(cursorPos.x + g.FontSize, cursorPos.y + line_height));
|
||||
ItemSize(bb);
|
||||
if (!ItemAdd(bb, 0))
|
||||
{
|
||||
SameLine(0, style.FramePadding.x * 2);
|
||||
return;
|
||||
}
|
||||
|
||||
// Render and stay on same line
|
||||
U32 text_col = GetColorU32(Col.Text);
|
||||
|
||||
float bar_height = line_height / 4.0f;
|
||||
|
||||
Rect topBb = .(cursorPos, (Vec2)((float2)cursorPos + float2(g.FontSize, bar_height)));
|
||||
RenderFrame(topBb.Min, topBb.Max, text_col, true, 4);
|
||||
|
||||
Rect middleBb = topBb;
|
||||
middleBb.Min.y = cursorPos.y + line_height / 2.0f - bar_height / 2.0f;
|
||||
middleBb.Max.y = middleBb.Min.y + bar_height;
|
||||
RenderFrame(middleBb.Min, middleBb.Max, text_col, true, 4);
|
||||
|
||||
Rect bottomBb = middleBb;
|
||||
bottomBb.Max.y = cursorPos.y + line_height;
|
||||
bottomBb.Min.y = bottomBb.Max.y - bar_height;
|
||||
RenderFrame(bottomBb.Min, bottomBb.Max, text_col, true, 4);
|
||||
|
||||
SameLine(0, style.FramePadding.x * 2.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ using internal ImGui;
|
||||
#if GE_GRAPHICS_DX11
|
||||
|
||||
using GlitchyEngine.Platform.DX11;
|
||||
using GlitchyEngine.Math;
|
||||
using internal GlitchyEngine.Platform.DX11;
|
||||
|
||||
#endif
|
||||
@@ -110,11 +111,88 @@ namespace GlitchyEngine.ImGui
|
||||
ImGui.GetIO().Fonts.AddFontDefault();
|
||||
}
|
||||
|
||||
ApplyDefaultStyle();
|
||||
|
||||
ImGui.GetIO().Fonts.AddFontDefault();
|
||||
|
||||
delete fontFile;
|
||||
}
|
||||
|
||||
private void ApplyDefaultStyle(ImGui.Style* dst = null)
|
||||
{
|
||||
ImGui.Style* style = dst ?? ImGui.GetStyle();
|
||||
ImGui.Vec4* colors = &style.Colors;
|
||||
|
||||
style.FrameRounding = 4;
|
||||
style.TabRounding = 8;
|
||||
style.ScrollbarSize = 20;
|
||||
|
||||
style.WindowMinSize = ImGui.Vec2(100, 100);
|
||||
|
||||
colors[(.)ImGui.Col.WindowBg] = ImGui.Vec4(0.118f, 0.118f, 0.118f, 1.00f);
|
||||
colors[(.)ImGui.Col.FrameBg] = ImGui.Vec4(0.289f, 0.387f, 0.533f, 1.00f);
|
||||
colors[(.)ImGui.Col.Header] = ImGui.Vec4(0.267f, 0.295f, 0.329f, 1.00f);
|
||||
colors[(.)ImGui.Col.Tab] = ImGui.Vec4(0.473f, 0.519f, 0.580f, 1.00f);
|
||||
colors[(.)ImGui.Col.TabUnfocused] = ImGui.Vec4(0.255f, 0.255f, 0.255f, 1.00f);
|
||||
colors[(.)ImGui.Col.CheckMark] = ImGui.Vec4(0.851f, 0.863f, 0.900f, 1.00f);
|
||||
|
||||
/*colors[(.)ImGui.Col.Text] = ImGui.Vec4(0.00f, 0.00f, 0.00f, 1.00f);
|
||||
colors[(.)ImGui.Col.TextDisabled] = ImGui.Vec4(0.60f, 0.60f, 0.60f, 1.00f);
|
||||
colors[(.)ImGui.Col.WindowBg] = ImGui.Vec4(0.94f, 0.94f, 0.94f, 1.00f);
|
||||
colors[(.)ImGui.Col.ChildBg] = ImGui.Vec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||
colors[(.)ImGui.Col.PopupBg] = ImGui.Vec4(1.00f, 1.00f, 1.00f, 0.98f);
|
||||
colors[(.)ImGui.Col.Border] = ImGui.Vec4(0.00f, 0.00f, 0.00f, 0.30f);
|
||||
colors[(.)ImGui.Col.BorderShadow] = ImGui.Vec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||
colors[(.)ImGui.Col.FrameBg] = ImGui.Vec4(1.00f, 1.00f, 1.00f, 1.00f);
|
||||
colors[(.)ImGui.Col.FrameBgHovered] = ImGui.Vec4(0.26f, 0.59f, 0.98f, 0.40f);
|
||||
colors[(.)ImGui.Col.FrameBgActive] = ImGui.Vec4(0.26f, 0.59f, 0.98f, 0.67f);
|
||||
colors[(.)ImGui.Col.TitleBg] = ImGui.Vec4(0.96f, 0.96f, 0.96f, 1.00f);
|
||||
colors[(.)ImGui.Col.TitleBgActive] = ImGui.Vec4(0.82f, 0.82f, 0.82f, 1.00f);
|
||||
colors[(.)ImGui.Col.TitleBgCollapsed] = ImGui.Vec4(1.00f, 1.00f, 1.00f, 0.51f);
|
||||
colors[(.)ImGui.Col.MenuBarBg] = ImGui.Vec4(0.86f, 0.86f, 0.86f, 1.00f);
|
||||
colors[(.)ImGui.Col.ScrollbarBg] = ImGui.Vec4(0.98f, 0.98f, 0.98f, 0.53f);
|
||||
colors[(.)ImGui.Col.ScrollbarGrab] = ImGui.Vec4(0.69f, 0.69f, 0.69f, 0.80f);
|
||||
colors[(.)ImGui.Col.ScrollbarGrabHovered] = ImGui.Vec4(0.49f, 0.49f, 0.49f, 0.80f);
|
||||
colors[(.)ImGui.Col.ScrollbarGrabActive] = ImGui.Vec4(0.49f, 0.49f, 0.49f, 1.00f);
|
||||
colors[(.)ImGui.Col.CheckMark] = ImGui.Vec4(0.26f, 0.59f, 0.98f, 1.00f);
|
||||
colors[(.)ImGui.Col.SliderGrab] = ImGui.Vec4(0.26f, 0.59f, 0.98f, 0.78f);
|
||||
colors[(.)ImGui.Col.SliderGrabActive] = ImGui.Vec4(0.46f, 0.54f, 0.80f, 0.60f);
|
||||
colors[(.)ImGui.Col.Button] = ImGui.Vec4(0.26f, 0.59f, 0.98f, 0.40f);
|
||||
colors[(.)ImGui.Col.ButtonHovered] = ImGui.Vec4(0.26f, 0.59f, 0.98f, 1.00f);
|
||||
colors[(.)ImGui.Col.ButtonActive] = ImGui.Vec4(0.06f, 0.53f, 0.98f, 1.00f);
|
||||
colors[(.)ImGui.Col.Header] = ImGui.Vec4(0.26f, 0.59f, 0.98f, 0.31f);
|
||||
colors[(.)ImGui.Col.HeaderHovered] = ImGui.Vec4(0.26f, 0.59f, 0.98f, 0.80f);
|
||||
colors[(.)ImGui.Col.HeaderActive] = ImGui.Vec4(0.26f, 0.59f, 0.98f, 1.00f);
|
||||
colors[(.)ImGui.Col.Separator] = ImGui.Vec4(0.39f, 0.39f, 0.39f, 0.62f);
|
||||
colors[(.)ImGui.Col.SeparatorHovered] = ImGui.Vec4(0.14f, 0.44f, 0.80f, 0.78f);
|
||||
colors[(.)ImGui.Col.SeparatorActive] = ImGui.Vec4(0.14f, 0.44f, 0.80f, 1.00f);
|
||||
colors[(.)ImGui.Col.ResizeGrip] = ImGui.Vec4(0.35f, 0.35f, 0.35f, 0.17f);
|
||||
colors[(.)ImGui.Col.ResizeGripHovered] = ImGui.Vec4(0.26f, 0.59f, 0.98f, 0.67f);
|
||||
colors[(.)ImGui.Col.ResizeGripActive] = ImGui.Vec4(0.26f, 0.59f, 0.98f, 0.95f);
|
||||
colors[(.)ImGui.Col.Tab] = ImGui.Vec4(0.96f, 0.8f, 0.52f, 1.0f);//ImGui.ImLerp(colors[(.)ImGui.Col.Header], colors[(.)ImGui.Col.TitleBgActive], 0.90f);
|
||||
colors[(.)ImGui.Col.TabHovered] = ImGui.Vec4(0.73f, 0.78f, 0.95f, 1.0f);
|
||||
colors[(.)ImGui.Col.TabActive] = ImGui.ImLerp(colors[(.)ImGui.Col.HeaderActive], colors[(.)ImGui.Col.TitleBgActive], 0.60f);
|
||||
colors[(.)ImGui.Col.TabUnfocused] = ImGui.ImLerp(colors[(.)ImGui.Col.Tab], colors[(.)ImGui.Col.TitleBg], 0.80f);
|
||||
colors[(.)ImGui.Col.TabUnfocusedActive] = ImGui.ImLerp(colors[(.)ImGui.Col.TabActive], colors[(.)ImGui.Col.TitleBg], 0.40f);
|
||||
colors[(.)ImGui.Col.DockingPreview] = (.)((float4)colors[(.)ImGui.Col.Header] * (float4)ImGui.Vec4(1.0f, 1.0f, 1.0f, 0.7f));
|
||||
colors[(.)ImGui.Col.DockingEmptyBg] = ImGui.Vec4(0.20f, 0.20f, 0.20f, 1.00f);
|
||||
colors[(.)ImGui.Col.PlotLines] = ImGui.Vec4(0.39f, 0.39f, 0.39f, 1.00f);
|
||||
colors[(.)ImGui.Col.PlotLinesHovered] = ImGui.Vec4(1.00f, 0.43f, 0.35f, 1.00f);
|
||||
colors[(.)ImGui.Col.PlotHistogram] = ImGui.Vec4(0.90f, 0.70f, 0.00f, 1.00f);
|
||||
colors[(.)ImGui.Col.PlotHistogramHovered] = ImGui.Vec4(1.00f, 0.45f, 0.00f, 1.00f);
|
||||
colors[(.)ImGui.Col.TableHeaderBg] = ImGui.Vec4(0.78f, 0.87f, 0.98f, 1.00f);
|
||||
colors[(.)ImGui.Col.TableBorderStrong] = ImGui.Vec4(0.57f, 0.57f, 0.64f, 1.00f); // Prefer using Alpha=1.0 here
|
||||
colors[(.)ImGui.Col.TableBorderLight] = ImGui.Vec4(0.68f, 0.68f, 0.74f, 1.00f); // Prefer using Alpha=1.0 here
|
||||
colors[(.)ImGui.Col.TableRowBg] = ImGui.Vec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||
colors[(.)ImGui.Col.TableRowBgAlt] = ImGui.Vec4(0.30f, 0.30f, 0.30f, 0.09f);
|
||||
colors[(.)ImGui.Col.TextSelectedBg] = ImGui.Vec4(0.26f, 0.59f, 0.98f, 0.35f);
|
||||
colors[(.)ImGui.Col.DragDropTarget] = ImGui.Vec4(0.26f, 0.59f, 0.98f, 0.95f);
|
||||
colors[(.)ImGui.Col.NavHighlight] = colors[(.)ImGui.Col.HeaderHovered];
|
||||
colors[(.)ImGui.Col.NavWindowingHighlight] = ImGui.Vec4(0.70f, 0.70f, 0.70f, 0.70f);
|
||||
colors[(.)ImGui.Col.NavWindowingDimBg] = ImGui.Vec4(0.20f, 0.20f, 0.20f, 0.20f);
|
||||
colors[(.)ImGui.Col.ModalWindowDimBg] = ImGui.Vec4(0.20f, 0.20f, 0.20f, 0.35f);*/
|
||||
}
|
||||
|
||||
public void ImGuiRender()
|
||||
{
|
||||
Debug.Profiler.ProfileFunction!();
|
||||
@@ -131,6 +209,8 @@ namespace GlitchyEngine.ImGui
|
||||
}
|
||||
|
||||
Begin();
|
||||
|
||||
ImGui.ShowDemoWindow();
|
||||
|
||||
{
|
||||
Debug.Profiler.ProfileScope!("ImGuiRenderEvent");
|
||||
|
||||
@@ -1063,6 +1063,16 @@ static class ScriptGlue
|
||||
fullTypeName = Mono.mono_string_new(ScriptEngine.[Friend]s_AppDomain, context.TypeName);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ImGui Extension
|
||||
|
||||
[RegisterCall("ScriptGlue::ImGuiExtension_ListElementGrabber")]
|
||||
static void ImGuiExtension_ListElementGrabber()
|
||||
{
|
||||
ImGui.ImGui.ListElementGrabber();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private static void RegisterCall<T>(String name, T method) where T : var
|
||||
|
||||
Reference in New Issue
Block a user