Port Setup* API, SetupLock (state only), PlotToNDC/NDCToPlot/NDCToPixels/PlotToPixels
This commit is contained in:
1 parent
75db57da3e
commit
bf1ea0930d
2 files changed
+266
No files matched your search
@@ -40,10 +40,39 @@ assert(ax.Range.Min == -5 and ax.Range.Max == 5)
|
||||
assert(near(ax:NDCToPlot(ax:PlotToNDC(3.3)), 3.3))
|
||||
|
||||
-- Plot + context pool
|
||||
ImGui.CreateContext()
|
||||
local ctx = ImPlot3D.CreateContext()
|
||||
local plot = ctx.Plots:GetOrAddByKey(123)
|
||||
assert(ctx.Plots:GetByKey(123) == plot and plot.Axes[0].Range.Max == 1)
|
||||
plot:ExtendFit(ImPlot3D.ImPlot3DPoint(1, 2, 3))
|
||||
assert(plot.Axes[2].FitExtents.Max == 3)
|
||||
|
||||
-- Setup API + NDC round trip
|
||||
ctx.CurrentPlot = plot
|
||||
ctx.CurrentItems = plot.Items
|
||||
plot.FrameRect = G.ImRect(0, 0, 400, 300)
|
||||
ImPlot3D.SetupAxes("x", "y##hidden", "##z")
|
||||
assert(plot.Axes[1]:GetLabel() == "y##hidden" and not plot.Axes[2]:HasLabel())
|
||||
ImPlot3D.SetupAxesLimits(0, 10, -1, 1, 100, 200)
|
||||
assert(plot.Axes[0].Range.Max == 10 and not plot.FitThisFrame)
|
||||
ImPlot3D.SetupAxisFormat(0, "%.1f")
|
||||
ImPlot3D.SetupAxisTicks(1, -1, 1, 3, nil, true)
|
||||
assert(plot.Axes[1].Ticker:TickCount() == 3)
|
||||
ImPlot3D.SetupBoxScale(1, 2, 1)
|
||||
ImPlot3D.SetupBoxRotation(30, 45)
|
||||
ImPlot3D.SetupBoxInitialRotation(10, 20)
|
||||
ImPlot3D.SetupLegend(ImPlot3D.ImPlot3DLocation.South)
|
||||
assert(plot.Items.Legend.Location == ImPlot3D.ImPlot3DLocation.South)
|
||||
plot.Axes[2].Flags = ImPlot3D.ImPlot3DAxisFlags.Invert
|
||||
ImPlot3D.SetupLock()
|
||||
assert(plot.SetupLocked and plot.Axes[0].Ticker:TickCount() > 0 and plot.Axes[0].Ticker:GetText(0) == "0.0")
|
||||
local p = ImPlot3D.ImPlot3DPoint(2.5, 0.3, 175)
|
||||
local ndc = ImPlot3D.PlotToNDC(p)
|
||||
assert(near(ndc.x, -0.25) and near(ndc.y, 0.3) and near(ndc.z, -0.25), "ndc")
|
||||
local back = ImPlot3D.NDCToPlot(ndc)
|
||||
assert(near(back.x, 2.5) and near(back.y, 0.3) and near(back.z, 175), "round trip")
|
||||
local pix = ImPlot3D.PlotToPixels(2.5, 0.3, 175)
|
||||
local pix2 = ImPlot3D.NDCToPixels(ndc)
|
||||
assert(near(pix.x, pix2.x) and near(pix.y, pix2.y))
|
||||
|
||||
print("OK")
|
||||
Reference in new issue
Block a user