Allow specifying all corners for ImGui gradients. (#247)

This commit is contained in:
Skyth (Asilkan) 2025-01-30 23:25:19 +03:00 committed by GitHub
parent 70f042d11f
commit 21c1d36836
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 25 additions and 9 deletions

View file

@ -32,8 +32,10 @@ union ImGuiCallbackData
{ {
float boundsMin[2]; float boundsMin[2];
float boundsMax[2]; float boundsMax[2];
uint32_t gradientTop; uint32_t gradientTopLeft;
uint32_t gradientBottom; uint32_t gradientTopRight;
uint32_t gradientBottomRight;
uint32_t gradientBottomLeft;
} setGradient; } setGradient;
struct struct

View file

@ -6,8 +6,10 @@ struct PushConstants
{ {
float2 BoundsMin; float2 BoundsMin;
float2 BoundsMax; float2 BoundsMax;
uint GradientTop; uint GradientTopLeft;
uint GradientBottom; uint GradientTopRight;
uint GradientBottomRight;
uint GradientBottomLeft;
uint ShaderModifier; uint ShaderModifier;
uint Texture2DDescriptorIndex; uint Texture2DDescriptorIndex;
float2 InverseDisplaySize; float2 InverseDisplaySize;

View file

@ -165,7 +165,9 @@ float4 main(in Interpolators interpolators) : SV_Target
} }
else else
{ {
color *= lerp(DecodeColor(g_PushConstants.GradientTop), DecodeColor(g_PushConstants.GradientBottom), smoothstep(0.0, 1.0, factor.y)); float4 top = lerp(DecodeColor(g_PushConstants.GradientTopLeft), DecodeColor(g_PushConstants.GradientTopRight), smoothstep(0.0, 1.0, factor.x));
float4 bottom = lerp(DecodeColor(g_PushConstants.GradientBottomLeft), DecodeColor(g_PushConstants.GradientBottomRight), smoothstep(0.0, 1.0, factor.x));
color *= lerp(top, bottom, smoothstep(0.0, 1.0, factor.y));
} }
} }

View file

@ -1196,8 +1196,10 @@ struct ImGuiPushConstants
{ {
ImVec2 boundsMin{}; ImVec2 boundsMin{};
ImVec2 boundsMax{}; ImVec2 boundsMax{};
ImU32 gradientTop{}; ImU32 gradientTopLeft{};
ImU32 gradientBottom{}; ImU32 gradientTopRight{};
ImU32 gradientBottomRight{};
ImU32 gradientBottomLeft{};
uint32_t shaderModifier{}; uint32_t shaderModifier{};
uint32_t texture2DDescriptorIndex{}; uint32_t texture2DDescriptorIndex{};
ImVec2 inverseDisplaySize{}; ImVec2 inverseDisplaySize{};

View file

@ -23,14 +23,21 @@ void InitImGuiUtils()
} }
void SetGradient(const ImVec2& min, const ImVec2& max, ImU32 top, ImU32 bottom) void SetGradient(const ImVec2& min, const ImVec2& max, ImU32 top, ImU32 bottom)
{
SetGradient(min, max, top, top, bottom, bottom);
}
void SetGradient(const ImVec2& min, const ImVec2& max, ImU32 topLeft, ImU32 topRight, ImU32 bottomRight, ImU32 bottomLeft)
{ {
auto callbackData = AddImGuiCallback(ImGuiCallback::SetGradient); auto callbackData = AddImGuiCallback(ImGuiCallback::SetGradient);
callbackData->setGradient.boundsMin[0] = min.x; callbackData->setGradient.boundsMin[0] = min.x;
callbackData->setGradient.boundsMin[1] = min.y; callbackData->setGradient.boundsMin[1] = min.y;
callbackData->setGradient.boundsMax[0] = max.x; callbackData->setGradient.boundsMax[0] = max.x;
callbackData->setGradient.boundsMax[1] = max.y; callbackData->setGradient.boundsMax[1] = max.y;
callbackData->setGradient.gradientTop = top; callbackData->setGradient.gradientTopLeft = topLeft;
callbackData->setGradient.gradientBottom = bottom; callbackData->setGradient.gradientTopRight = topRight;
callbackData->setGradient.gradientBottomRight = bottomRight;
callbackData->setGradient.gradientBottomLeft = bottomLeft;
} }
void ResetGradient() void ResetGradient()

View file

@ -35,6 +35,7 @@ struct Paragraph {
void InitImGuiUtils(); void InitImGuiUtils();
void SetGradient(const ImVec2& min, const ImVec2& max, ImU32 top, ImU32 bottom); void SetGradient(const ImVec2& min, const ImVec2& max, ImU32 top, ImU32 bottom);
void SetGradient(const ImVec2& min, const ImVec2& max, ImU32 topLeft, ImU32 topRight, ImU32 bottomRight, ImU32 bottomLeft);
void ResetGradient(); void ResetGradient();
void SetShaderModifier(uint32_t shaderModifier); void SetShaderModifier(uint32_t shaderModifier);
void SetOrigin(ImVec2 origin); void SetOrigin(ImVec2 origin);