Compare commits

..
19 Commits
Author SHA1 Message Date
4DBug 4e8c21fdf8 example: demo window only 2026-10-17 06:05:39 -05:00
4DBug decb7e725d Example: live sine + demo windows; run example in tools/test.sh; README usage, API differences, status 2026-10-17 03:12:17 -05:00
4DBug 4cf1840093 Port remaining demos (Tables, ItemStylingAndSpec, OffsetAndStride, CustomDataAndGetters, TickLabels, CustomStyles, CustomRendering, LegendPopups, ColormapWidgets, CustomPlottersAndTooltips); enable PlotPolygon demo 2026-10-17 03:07:55 -05:00
4DBug dc6cdeb67e Demo: port subplot, legend, drag tool, querying, annotation, tag and DnD demos 2026-10-17 03:04:22 -05:00
4DBug e01ff90a1e Port ImPlot demo: Demo_MarkersAndText..Demo_AutoFittingData (markers/text, NaN, per-index colors, log/symlog/time/custom scales, multiple/linked/constrained/equal axes, auto-fitting) 2026-10-17 02:59:39 -05:00
4DBug aa8bdb0062 Port missing query/clip/misc APIs (IsAxisHovered, IsPlotSelected, GetPlotSelection, SetAxis/SetAxes, PushPlotClipRect, HideNextItem, ...) 2026-10-17 02:56:17 -05:00
4DBug 859b8603c6 Port ImPlot demo: ShowDemoWindow (menu, tabs, tool windows) and Demo_Help..Demo_RealtimePlots; stubs for the rest 2026-10-17 02:46:14 -05:00
4DBug f46b841360 Port AddColormap (+ style editor custom colormap builder), ShowDatePicker/ShowTimePicker with PickerTimeMin/Max and time axis context menu, ShowAltLegend, ShowMetricsWindow 2026-10-17 02:38:58 -05:00
4DBug 84808261f5 Port BeginSubplots/EndSubplots, BeginAlignedPlots/EndAlignedPlots, drag & drop utils, BeginLegendPopup/EndLegendPopup, ShowStyleEditor/ShowStyleSelector/ShowColormapSelector/ShowInputMapSelector/ShowUserGuide, crosshairs, axis side switch, equal-aspect fit 2026-10-17 02:33:10 -05:00
4DBug 2f1b93a31e Port DragPoint, DragLineX/Y, DragRect, Annotation, TagX/TagY, SetupMouseText + mouse position text, LabelAxisValue, GetPlotMousePos 2026-10-17 02:25:55 -05:00
4DBug 63a2368258 Port SetupAxisScale (Linear/Time/Log10/SymLog/custom transforms), Locator_Log10/SymLog/Time, ImPlotTime utils and date/time formatting, SetupAxisTicks, SetupAxisFormat formatter overload, SetupAxisLimitsConstraints/ZoomConstraints 2026-10-17 02:20:17 -05:00
4DBug 27c7add0f4 Port PlotPieChart, PlotHeatmap, PlotHistogram, PlotHistogram2D (CalculateBins/ImPlotBin), PlotImage, ColormapScale/Slider/Button/Icon, RenderColorBar 2026-10-17 02:15:53 -05:00
4DBug bdc7eeb12b Port PlotErrorBars, PlotStems, PlotInfLines, PlotText, PlotDummy, PlotDigital, PlotBubbles 2026-10-17 02:09:14 -05:00
4DBug 99105a3676 Port PlotStairs, PlotShaded, PlotBars, PlotBarGroups with stairs/bars renderers, FitterBarV/H, PrimRectLine 2026-10-17 02:04:56 -05:00
4DBug 0de7ada363 Port items (ImPlotItem/ItemGroup/NextItemData, BeginItem/EndItem), getters/indexers, fitters, transformers, line/segment/shaded/marker renderers, PlotLine/PlotScatter, legend rendering + click-to-toggle, SetupLegend 2026-10-17 01:53:50 -05:00
4DBug 1d5fc7b712 Port UpdateInput (pan, zoom, box select, fit), ImPlotInputMap, plot/axis context menus, SetNextAxis*, SetupAxisLinks/PushLinks/PullLinks 2026-10-17 01:43:58 -05:00
4DBug 6d46bf0b5e Port ImPlotAxis, ImPlotPlot, ImPlotTicker, default locator/formatter, Setup*, BeginPlot/EndPlot rendering, plot/pixel transforms 2026-10-17 01:39:07 -05:00
4DBug 80ba5ca5df Port enums, ImPlotPoint/Range/Rect, ImPlotStyle, context, style and colormap API 2026-10-17 01:33:21 -05:00
4DBug 7e3871fe5c Scaffold: upstream @ 851cdbd, core submodule, test runner, example 2026-10-16 23:47:09 -05:00
6 changed files with 18 additions and 13384 deletions

No files matched your search

-1
View File
@@ -1,3 +1,2 @@
.gitattributes export-ignore
tools/upstream/** linguist-vendored=true
love/** linguist-generated=true
+1 -1
View File
@@ -1,3 +1,3 @@
[submodule "tools/core"]
path = tools/core
url = https://github.com/4DBug/imgui-luau.git
url = https://git.bug.tools/bug/imgui-luau.git
+17 -424
View File
@@ -835,7 +835,6 @@ return function(G)
function CM:GetTableSize(cmap) return self.TableSizes[cmap + 1] end
function CM:GetTableColor(cmap, idx) return self.Tables[self.TableOffsets[cmap + 1] + idx + 1] end
@native
function CM:LerpTable(cmap, t)
local off = self.TableOffsets[cmap + 1]
local siz = self.TableSizes[cmap + 1]
@@ -1188,7 +1187,6 @@ return function(G)
-- [Port] AddTick(value, major, level, show_label, label) and AddTick(..., formatter, data) overloads:
-- `label_or_formatter` is a string or a formatter function(value, data) -> string
function TickerMT:AddTick(value, major, level, show_label, label_or_formatter, data)
self.MemoValid = false -- [Luau] see Locator_Default
local n = self.Size + 1
local tick = self.Ticks[n]
if tick == nil then
@@ -1437,7 +1435,6 @@ return function(G)
return plt
end
@native
function AxisMT:ExtendFit(v)
if not ImNanOrInf(v) and v >= self.ConstraintRange.Min and v <= self.ConstraintRange.Max then
if v < self.FitExtents.Min then self.FitExtents.Min = v end
@@ -1445,7 +1442,6 @@ return function(G)
end
end
@native
function AxisMT:ExtendFitWith(alt, v, v_alt)
if ImHasFlag(self.Flags, ImPlotAxisFlags.RangeFit) and not alt.Range:Contains(v_alt) then
return
@@ -1640,54 +1636,10 @@ return function(G)
local TICK_FILL_X = 0.8
local TICK_FILL_Y = 1.0
-- [Luau] Locator_Default memo: the inputs of the previous call on this ticker. When the ticker held no other ticks and
-- nothing changed (range, pixels, orientation, Formatter_Default + format, font + size), the previous call's ticks
-- are still in ticker.Ticks (recycled, untouched: any AddTick clears MemoValid) and are restored instead of being
-- regenerated (labels formatted and measured again). Same ticks, labels, sizes and pruning.
local function LocatorMemoHit(ticker, range, pixels, vertical, formatter, formatter_data)
local m = ticker.Memo
if not ticker.MemoValid or m == nil or ticker.Size ~= 0 or formatter ~= internal.Formatter_Default then
return false
end
local g = ImGui.GetCurrentContext()
if m.Min ~= range.Min or m.Max ~= range.Max or m.Pixels ~= pixels or m.Vertical ~= vertical or m.Data ~= formatter_data
or m.Font ~= g.Font or m.FontSize ~= g.FontSize or m.FontBaked ~= g.FontBaked then
return false
end
ticker.Size = m.Count
if m.MaxX > ticker.MaxSize.x then ticker.MaxSize.x = m.MaxX end
if m.MaxY > ticker.MaxSize.y then ticker.MaxSize.y = m.MaxY end
return true
end
local function LocatorMemoStore(ticker, range, pixels, vertical, formatter, formatter_data, idx0)
if idx0 ~= 0 or formatter ~= internal.Formatter_Default then
return
end
local m = ticker.Memo
if m == nil then m = {}; ticker.Memo = m end
local g = ImGui.GetCurrentContext()
m.Min, m.Max, m.Pixels, m.Vertical, m.Data = range.Min, range.Max, pixels, vertical, formatter_data
m.Font, m.FontSize, m.FontBaked = g.Font, g.FontSize, g.FontBaked
m.Count = ticker.Size
-- label-only MaxSize contribution (MaxSize also starts from LateSize, which can differ next frame)
local mx, my = 0, 0
local ticks = ticker.Ticks
for i = 1, ticker.Size do
local ls = ticks[i].LabelSize
if ls.x > mx then mx = ls.x end
if ls.y > my then my = ls.y end
end
m.MaxX, m.MaxY = mx, my
ticker.MemoValid = true
end
function internal.Locator_Default(ticker, range, pixels, vertical, formatter, formatter_data)
if range.Min == range.Max then
return
end
if LocatorMemoHit(ticker, range, pixels, vertical, formatter, formatter_data) then
return
end
local nMinor = 10
local nMajor = math.max(2, math.floor(pixels / ((vertical and 300.0) or 400.0) + 0.5))
local nice_range = NiceNum((range.Max - range.Min) * 0.99, false)
@@ -1731,7 +1683,6 @@ return function(G)
ticks[i + 1].ShowLabel = false
end
end
LocatorMemoStore(ticker, range, pixels, vertical, formatter, formatter_data, idx0)
end
local Locator_Default = internal.Locator_Default
local DBL_MIN = 2.2250738585072014e-308
@@ -3660,18 +3611,9 @@ return function(G)
end
-- reset axes
-- [Luau] the cached colours do not depend on the axis: resolved once (X1) and copied to the other axes
-- (resolving the auto colours walks the auto colour chain and allocates: ~1.5 us per axis per frame)
local a0 = plot.Axes[0]
for i = 0, ImAxis.COUNT - 1 do
local axis = plot.Axes[i]
axis:Reset()
if i == 0 then
UpdateAxisColors(axis)
else
axis.ColorMaj, axis.ColorMin, axis.ColorTick, axis.ColorTxt = a0.ColorMaj, a0.ColorMin, a0.ColorTick, a0.ColorTxt
axis.ColorBg, axis.ColorHov, axis.ColorAct = a0.ColorBg, a0.ColorHov, a0.ColorAct
end
plot.Axes[i]:Reset()
UpdateAxisColors(plot.Axes[i])
end
-- ensure first axes enabled
plot.Axes[ImAxis.X1].Enabled = true
@@ -4649,7 +4591,6 @@ return function(G)
internal.ImAlphaU32 = ImAlphaU32
-- [Port] scalar alpha multiply on a packed color (replaces ColorConvertU32ToFloat4 + GetColorU32 per point)
@native
local function MulAlphaU32(col, alpha)
local a = floor(rshift(col, 24) * alpha + 0.5)
if a > 255 then a = 255 elseif a < 0 then a = 0 end
@@ -5067,13 +5008,9 @@ return function(G)
-----------------------------------------------------------------------
-- [Port] IndexData switch -> one At function per case, picked at construction
@native
local function IdxAt3(self, i) return self.Data[i + 1] end
@native
local function IdxAt2(self, i) return self.Data[(self.Offset + i) % self.Count + 1] end
@native
local function IdxAt1(self, i) return self.Data[i * self.Stride + 1] end
@native
local function IdxAt0(self, i) return self.Data[((self.Offset + i) % self.Count) * self.Stride + 1] end
function internal.IndexerIdx(data, count, offset, stride)
@@ -5088,17 +5025,9 @@ return function(G)
return { Data = data, Count = count, Offset = offset, Stride = stride, At = at }
end
@native
-- [Luau] the array behind a plain (offset 0, stride 1) IndexerIdx, or nil: hot loops read it directly instead of
-- calling At per value (same values)
local function PlainData(indexer) return indexer.At == IdxAt3 and indexer.Data or nil end
internal.PlainData = PlainData
@native
local function LinAt(self, i) return self.M * i + self.B end
function internal.IndexerLin(m, b) return { M = m, B = b, At = LinAt } end
@native
local function ConstAt(self) return self.Ref end
function internal.IndexerConst(ref) return { Ref = ref, At = ConstAt } end
@@ -5106,22 +5035,18 @@ return function(G)
-- Getters
-----------------------------------------------------------------------
@native
local function XYGet(self, i)
local ix, iy = self.IndexerX, self.IndexerY
return ix.At(ix, i), iy.At(iy, i)
end
function internal.GetterXY(ix, iy, count) return { IndexerX = ix, IndexerY = iy, Count = count, Get = XYGet } end
@native
local function OverrideXGet(self, i) local g = self.Getter; local _, y = g.Get(g, i); return self.X, y end
function internal.GetterOverrideX(getter, x) return { Getter = getter, X = x, Count = getter.Count, Get = OverrideXGet } end
@native
local function OverrideYGet(self, i) local g = self.Getter; local x = g.Get(g, i); return x, self.Y end
function internal.GetterOverrideY(getter, y) return { Getter = getter, Y = y, Count = getter.Count, Get = OverrideYGet } end
@native
local function LoopGet(self, i) local g = self.Getter; return g.Get(g, i % (self.Count - 1)) end
function internal.GetterLoop(getter) return { Getter = getter, Count = getter.Count + 1, Get = LoopGet } end
@@ -5137,7 +5062,6 @@ return function(G)
-- Fitters
-----------------------------------------------------------------------
@native
local function Fitter1Fit(self, x_axis, y_axis)
local g = self.Getter
local get = g.Get
@@ -5149,14 +5073,12 @@ return function(G)
end
function internal.Fitter1(getter) return { Getter = getter, Fit = Fitter1Fit } end
@native
local function FitterXFit(self, x_axis)
local g = self.Getter
for i = 0, g.Count - 1 do local x = g.Get(g, i); x_axis:ExtendFit(x) end
end
function internal.FitterX(getter) return { Getter = getter, Fit = FitterXFit } end
@native
local function FitterYFit(self, _, y_axis)
local g = self.Getter
for i = 0, g.Count - 1 do local _, y = g.Get(g, i); y_axis:ExtendFit(y) end
@@ -5309,21 +5231,6 @@ return function(G)
r.U, r.V = uv.x, uv.y
end
-- [Port] no axis transform functions (and per-index colours covering i0..i1): point read + transform + colour
-- inlined. Returns the getter's Get and, when it reads two plain arrays, those arrays (read directly); nil when the
-- range can't be inlined.
local function RangeSource(r, i0, i1)
if tx_fwd ~= nil or ty_fwd ~= nil or (r.Cols ~= nil and (i0 < 0 or i1 >= r.ColCount)) then
return nil
end
local g = r.Getter
if g.Get == XYGet then
local xs, ys = PlainData(g.IndexerX), PlainData(g.IndexerY)
if xs ~= nil and ys ~= nil then return XYGet, xs, ys end
end
return g.Get, nil, nil
end
@native
local function LineStripRender(r, dl, cr, prim)
local g = r.Getter
@@ -5339,67 +5246,6 @@ return function(G)
return true
end
-- [Port] prims i0..i1 in one call when there are no axis transform functions: LineStripRender + TransformX/Y +
-- Overlaps + GetCol + PrimLine inlined, same math; a getter reading two plain arrays is read directly, any other
-- getter through Get. Returns culled count.
@native
local function LineStripRange(r, dl, cr, i0, i1)
local get, xs, ys = RangeSource(r, i0, i1)
if get == nil then
local culled = 0
for i = i0, i1 do
if not LineStripRender(r, dl, cr, i) then culled += 1 end
end
return culled
end
local g, cols, alpha = r.Getter, r.Cols, r.ColAlpha
local cminx, cminy, cmaxx, cmaxy = cr.Min.x, cr.Min.y, cr.Max.x, cr.Max.y
local xpm, xm, xpl, ypm, ym, ypl = tx_pixmin, tx_m, tx_pltmin, ty_pixmin, ty_m, ty_pltmin
local hw, col, u0, v0, u1, v1, skip = r.HalfWeight, r.Col, r.U0, r.V0, r.U1, r.V1, r.Skip
local b, id = dl.VtxBuffer.Buf, dl.IdxBuffer.Data
local vw, iw, idx = dl._VtxWritePtr, dl._IdxWritePtr, dl._VtxCurrentIdx
local p1x, p1y = r.P1x, r.P1y
local culled = 0
for i = i0, i1 do
local x, y
if xs ~= nil then
x, y = xs[i + 2], ys[i + 2]
else
x, y = get(g, i + 1)
end
local p2x, p2y = xpm + xm * (x - xpl), ypm + ym * (y - ypl)
local minx, maxx = p1x, p2x
if p2x < p1x then minx, maxx = p2x, p1x end
local miny, maxy = p1y, p2y
if p2y < p1y then miny, maxy = p2y, p1y end
if miny < cmaxy and maxy > cminy and minx < cmaxx and maxx > cminx then
local c = col
if cols ~= nil then
c = cols[i + 1]
if alpha < 1 then c = MulAlphaU32(c, alpha) end
end
local dx, dy = p2x - p1x, p2y - p1y
local d2 = dx * dx + dy * dy
if d2 > 0 then local inv = 1 / sqrt(d2); dx *= inv; dy *= inv end
dx *= hw; dy *= hw
local o = (vw - 1) * VTX_STRIDE
WV(b, o, p1x + dy, p1y - dx, u0, v0, c)
WV(b, o + VTX_STRIDE, p2x + dy, p2y - dx, u0, v0, c)
WV(b, o + VTX_STRIDE * 2, p2x - dy, p2y + dx, u1, v1, c)
WV(b, o + VTX_STRIDE * 3, p1x - dy, p1y + dx, u1, v1, c)
id[iw] = idx; id[iw + 1] = idx + 1; id[iw + 2] = idx + 2
id[iw + 3] = idx; id[iw + 4] = idx + 2; id[iw + 5] = idx + 3
vw += 4; iw += 6; idx += 4
else
culled += 1
end
if not skip or (p2x == p2x and p2y == p2y) then p1x, p1y = p2x, p2y end
end
dl._VtxWritePtr, dl._IdxWritePtr, dl._VtxCurrentIdx = vw, iw, idx
r.P1x, r.P1y = p1x, p1y
return culled
end
-- RendererLineStrip / RendererLineStripSkip (skip = true skips NaNs)
function internal.RendererLineStrip(getter, weight, skip)
local x, y = getter.Get(getter, 0)
@@ -5407,7 +5253,7 @@ return function(G)
Prims = getter.Count - 1, IdxConsumed = 6, VtxConsumed = 4,
Getter = getter, HalfWeight = max(1.0, weight) * 0.5, Skip = skip or false,
P1x = TransformX(x), P1y = TransformY(y),
Init = LineInit, Render = LineStripRender, RenderRange = LineStripRange,
Init = LineInit, Render = LineStripRender,
}
end
@@ -5487,72 +5333,6 @@ return function(G)
dl._VtxWritePtr = vw + 5; dl._IdxWritePtr = iw + 6; dl._VtxCurrentIdx = idx + 5
return true
end
-- [Luau] prims i0..i1 in one call when both getters are GetterXY and there are no axis transform functions:
-- ShadedRender + XYGet + TransformX/Y + GetCol inlined (plain arrays read directly), same math. Returns culled count.
@native
local function ShadedRange(r, dl, cr, i0, i1)
local g1, g2 = r.Getter1, r.Getter2
local cols, alpha = r.Cols, r.ColAlpha
if g1.Get ~= XYGet or g2.Get ~= XYGet or tx_fwd ~= nil or ty_fwd ~= nil or (cols ~= nil and (i0 < 0 or i1 >= r.ColCount)) then
local culled = 0
for i = i0, i1 do
if not ShadedRender(r, dl, cr, i) then culled += 1 end
end
return culled
end
local iax, iay, ibx, iby = g1.IndexerX, g1.IndexerY, g2.IndexerX, g2.IndexerY
local dax, day, dbx, dby = PlainData(iax), PlainData(iay), PlainData(ibx), PlainData(iby)
local cminx, cminy, cmaxx, cmaxy = cr.Min.x, cr.Min.y, cr.Max.x, cr.Max.y
local xpm, xm, xpl, ypm, ym, ypl = tx_pixmin, tx_m, tx_pltmin, ty_pixmin, ty_m, ty_pltmin
local p11x, p11y, p12x, p12y = r.P11x, r.P11y, r.P12x, r.P12y
local col, u, v = r.Col, r.U, r.V
local b, id = dl.VtxBuffer.Buf, dl.IdxBuffer.Data
local vw, iw, idx = dl._VtxWritePtr, dl._IdxWritePtr, dl._VtxCurrentIdx
local culled = 0
for prim = i0, i1 do
local j = prim + 1
local ax = dax and dax[j + 1] or iax.At(iax, j)
local ay = day and day[j + 1] or iay.At(iay, j)
local bx = dbx and dbx[j + 1] or ibx.At(ibx, j)
local by = dby and dby[j + 1] or iby.At(iby, j)
local p21x, p21y = xpm + xm * (ax - xpl), ypm + ym * (ay - ypl)
local p22x, p22y = xpm + xm * (bx - xpl), ypm + ym * (by - ypl)
local minx, miny = min(p11x, p12x, p21x, p22x), min(p11y, p12y, p21y, p22y)
local maxx, maxy = max(p11x, p12x, p21x, p22x), max(p11y, p12y, p21y, p22y)
if miny < cmaxy and maxy > cminy and minx < cmaxx and maxx > cminx then
local c = col
if cols ~= nil then
c = cols[prim + 1]
if alpha < 1 then c = MulAlphaU32(c, alpha) end
end
local intersect = ((p11y > p12y and p22y > p21y) or (p12y > p11y and p21y > p22y)) and 1 or 0
local ix, iy = 0, 0
if intersect == 1 then
-- Intersection(P11,P21,P12,P22)
local v1 = p11x * p21y - p11y * p21x
local v2 = p12x * p22y - p12y * p22x
local v3 = (p11x - p21x) * (p12y - p22y) - (p11y - p21y) * (p12x - p22x)
ix = (v1 * (p12x - p22x) - v2 * (p11x - p21x)) / v3
iy = (v1 * (p12y - p22y) - v2 * (p11y - p21y)) / v3
end
local o = (vw - 1) * VTX_STRIDE
WV(b, o, p11x, p11y, u, v, c)
WV(b, o + VTX_STRIDE, p21x, p21y, u, v, c)
WV(b, o + VTX_STRIDE * 2, ix, iy, u, v, c)
WV(b, o + VTX_STRIDE * 3, p12x, p12y, u, v, c)
WV(b, o + VTX_STRIDE * 4, p22x, p22y, u, v, c)
id[iw] = idx; id[iw + 1] = idx + 1 + intersect; id[iw + 2] = idx + 3
id[iw + 3] = idx + 1; id[iw + 4] = idx + 4; id[iw + 5] = idx + 3 - intersect
vw += 5; iw += 6; idx += 5
else
culled += 1
end
p11x, p11y, p12x, p12y = p21x, p21y, p22x, p22y
end
dl._VtxWritePtr, dl._IdxWritePtr, dl._VtxCurrentIdx = vw, iw, idx
r.P11x, r.P11y, r.P12x, r.P12y = p11x, p11y, p12x, p12y
return culled
end
function internal.RendererShaded(getter1, getter2)
local ax, ay = getter1.Get(getter1, 0)
local bx, by = getter2.Get(getter2, 0)
@@ -5560,7 +5340,7 @@ return function(G)
Prims = min(getter1.Count, getter2.Count) - 1, IdxConsumed = 6, VtxConsumed = 5,
Getter1 = getter1, Getter2 = getter2,
P11x = TransformX(ax), P11y = TransformY(ay), P12x = TransformX(bx), P12y = TransformY(by),
Init = WhiteInit, Render = ShadedRender, RenderRange = ShadedRange,
Init = WhiteInit, Render = ShadedRender,
}
end
@@ -5591,61 +5371,11 @@ return function(G)
end
return false
end
@native
local function MarkersFillRange(r, dl, cr, i0, i1)
local get, xs, ys = RangeSource(r, i0, i1)
if get == nil then
local culled = 0
for i = i0, i1 do
if not MarkersFillRender(r, dl, cr, i) then culled += 1 end
end
return culled
end
local g, cols, alpha = r.Getter, r.Cols, r.ColAlpha
local cminx, cminy, cmaxx, cmaxy = cr.Min.x, cr.Min.y, cr.Max.x, cr.Max.y
local m, count, u, v, col, sizes, size = r.Marker, r.Count, r.U, r.V, r.Col, r.Sizes, r.Size
local b, id = dl.VtxBuffer.Buf, dl.IdxBuffer.Data
local vw, iw, idx = dl._VtxWritePtr, dl._IdxWritePtr, dl._VtxCurrentIdx
local culled = 0
for prim = i0, i1 do
local x, y
if xs ~= nil then
x, y = xs[prim + 1], ys[prim + 1]
else
x, y = get(g, prim)
end
local px, py = tx_pixmin + tx_m * (x - tx_pltmin), ty_pixmin + ty_m * (y - ty_pltmin)
if px >= cminx and py >= cminy and px <= cmaxx and py <= cmaxy then
local col = col
if cols ~= nil then
col = cols[prim + 1]
if alpha < 1 then col = MulAlphaU32(col, alpha) end
end
local sz = size
if sizes then sz = sizes[prim + 1] end
local o = (vw - 1) * VTX_STRIDE
for i = 0, count - 1 do
WV(b, o + i * VTX_STRIDE, px + m[i * 2 + 1] * sz, py + m[i * 2 + 2] * sz, u, v, col)
end
for i = 2, count - 1 do
id[iw] = idx; id[iw + 1] = idx + i - 1; id[iw + 2] = idx + i
iw += 3
end
vw += count; idx += count
else
culled += 1
end
end
dl._VtxWritePtr, dl._IdxWritePtr, dl._VtxCurrentIdx = vw, iw, idx
return culled
end
function internal.RendererMarkersFill(getter, marker, count)
return {
Prims = getter.Count, IdxConsumed = (count - 2) * 3, VtxConsumed = count,
Getter = getter, Marker = marker, Count = count,
Init = WhiteInit, Render = MarkersFillRender, RenderRange = MarkersFillRange,
Init = WhiteInit, Render = MarkersFillRender,
}
end
@@ -5667,69 +5397,11 @@ return function(G)
end
return false
end
@native
local function MarkersLineRange(r, dl, cr, i0, i1)
local get, xs, ys = RangeSource(r, i0, i1)
if get == nil then
local culled = 0
for i = i0, i1 do
if not MarkersLineRender(r, dl, cr, i) then culled += 1 end
end
return culled
end
local g, cols, alpha = r.Getter, r.Cols, r.ColAlpha
local cminx, cminy, cmaxx, cmaxy = cr.Min.x, cr.Min.y, cr.Max.x, cr.Max.y
local m, count, col, sizes, size = r.Marker, r.Count, r.Col, r.Sizes, r.Size
local hw, u0, v0, u1, v1 = r.HalfWeight, r.U0, r.V0, r.U1, r.V1
local b, id = dl.VtxBuffer.Buf, dl.IdxBuffer.Data
local vw, iw, idx = dl._VtxWritePtr, dl._IdxWritePtr, dl._VtxCurrentIdx
local culled = 0
for prim = i0, i1 do
local x, y
if xs ~= nil then
x, y = xs[prim + 1], ys[prim + 1]
else
x, y = get(g, prim)
end
local px, py = tx_pixmin + tx_m * (x - tx_pltmin), ty_pixmin + ty_m * (y - ty_pltmin)
if px >= cminx and py >= cminy and px <= cmaxx and py <= cmaxy then
local col = col
if cols ~= nil then
col = cols[prim + 1]
if alpha < 1 then col = MulAlphaU32(col, alpha) end
end
local sz = size
if sizes then sz = sizes[prim + 1] end
for i = 0, count - 1, 2 do
-- PrimLine inlined
local x1, y1 = px + m[i * 2 + 1] * sz, py + m[i * 2 + 2] * sz
local x2, y2 = px + m[i * 2 + 3] * sz, py + m[i * 2 + 4] * sz
local dx, dy = x2 - x1, y2 - y1
local d2 = dx * dx + dy * dy
if d2 > 0 then local inv = 1 / sqrt(d2); dx *= inv; dy *= inv end
dx *= hw; dy *= hw
local o = (vw - 1) * VTX_STRIDE
WV(b, o, x1 + dy, y1 - dx, u0, v0, col)
WV(b, o + VTX_STRIDE, x2 + dy, y2 - dx, u0, v0, col)
WV(b, o + VTX_STRIDE * 2, x2 - dy, y2 + dx, u1, v1, col)
WV(b, o + VTX_STRIDE * 3, x1 - dy, y1 + dx, u1, v1, col)
id[iw] = idx; id[iw + 1] = idx + 1; id[iw + 2] = idx + 2
id[iw + 3] = idx; id[iw + 4] = idx + 2; id[iw + 5] = idx + 3
vw += 4; iw += 6; idx += 4
end
else
culled += 1
end
end
dl._VtxWritePtr, dl._IdxWritePtr, dl._VtxCurrentIdx = vw, iw, idx
return culled
end
function internal.RendererMarkersLine(getter, marker, count, weight)
return {
Prims = getter.Count, IdxConsumed = count // 2 * 6, VtxConsumed = count // 2 * 4,
Getter = getter, Marker = marker, Count = count, HalfWeight = max(1.0, weight) * 0.5,
Init = LineInit, Render = MarkersLineRender, RenderRange = MarkersLineRange,
Init = LineInit, Render = MarkersLineRender,
}
end
@@ -5739,7 +5411,7 @@ return function(G)
local prims_culled = 0
local idx = 0
local idx_c, vtx_c = renderer.IdxConsumed, renderer.VtxConsumed
local render, range = renderer.Render, renderer.RenderRange
local render = renderer.Render
renderer.Init(renderer, draw_list)
while prims > 0 do
-- find how many can be reserved up to end of current draw command's limit
@@ -5763,13 +5435,9 @@ return function(G)
draw_list:PrimReserve(cnt * idx_c, cnt * vtx_c)
end
prims -= cnt
if range then
prims_culled += range(renderer, draw_list, cull_rect, idx, idx + cnt - 1)
else
for i = idx, idx + cnt - 1 do
if not render(renderer, draw_list, cull_rect, i) then
prims_culled += 1
end
for i = idx, idx + cnt - 1 do
if not render(renderer, draw_list, cull_rect, i) then
prims_culled += 1
end
end
idx += cnt
@@ -6559,7 +6227,6 @@ return function(G)
function internal.IndexerAdd(i1, i2, s1, s2) return { Indexer1 = i1, Indexer2 = i2, Scale1 = s1, Scale2 = s2, At = AddAt } end
-- [Port] GetterXYZ: Get returns (x, y, z)
@native
local function XYZGet(self, i)
local ix, iy, iz = self.IndexerX, self.IndexerY, self.IndexerZ
return ix.At(ix, i), iy.At(iy, i), iz.At(iz, i)
@@ -7035,19 +6702,16 @@ return function(G)
end
-- [Port] ImMinMaxIndexer -> returns (min, max)
@native
local function ImMinMaxIndexer(indexer, count)
local min_out, max_out = indexer.At(indexer, 0), indexer.At(indexer, 0)
local d = PlainData(indexer)
for i = 1, count - 1 do
local v = d and d[i + 1] or indexer.At(indexer, i)
local v = indexer.At(indexer, i)
if v < min_out then min_out = v end
if v > max_out then max_out = v end
end
return min_out, max_out
end
@native
local function ImStdDev(indexer, count)
local den = 1.0 / (count - 1.0)
local mu = 0
@@ -7289,8 +6953,8 @@ return function(G)
-- (renderer table reused across calls, so nothing is allocated per cell)
@native
local function HeatmapRender(r, dl, cr, prim)
local ix, d = r.Indexer, r.Data
local val = d and d[prim + 1] or ix.At(ix, prim)
local ix = r.Indexer
local val = ix.At(ix, prim)
local row, c
if r.ColMaj then
row, c = prim % r.Rows, prim // r.Rows
@@ -7310,72 +6974,7 @@ return function(G)
PrimRectFill(dl, p1x, p1y, p2x, p2y, col, r.U, r.V)
return true
end
-- [Luau] cells i0..i1 in one call when there are no axis transform functions: HeatmapRender + LerpTable +
-- TransformX/Y + Overlaps + PrimRectFill inlined, same math. Returns culled count.
@native
local function HeatmapRange(r, dl, cr, i0, i1)
if tx_fwd ~= nil or ty_fwd ~= nil then
local culled = 0
for i = i0, i1 do
if not HeatmapRender(r, dl, cr, i) then culled += 1 end
end
return culled
end
local ix, d = r.Indexer, r.Data
local rows, cols, col_maj = r.Rows, r.Cols, r.ColMaj
local w, h = r.Width, r.Height
local hx, hy = w * 0.5, h * 0.5
local xref, yref, ydir = r.XRef, r.YRef, r.YDir
local smin, smax = r.ScaleMin, r.ScaleMax
local cm, cmap = r.Colormaps, r.Cmap
local tables, off, siz, qual = cm.Tables, cm.TableOffsets[cmap + 1], cm.TableSizes[cmap + 1], cm.Quals[cmap + 1]
local cminx, cminy, cmaxx, cmaxy = cr.Min.x, cr.Min.y, cr.Max.x, cr.Max.y
local xpm, xm, xpl, ypm, ym, ypl = tx_pixmin, tx_m, tx_pltmin, ty_pixmin, ty_m, ty_pltmin
local u, v = r.U, r.V
local b, id = dl.VtxBuffer.Buf, dl.IdxBuffer.Data
local vw, iw, vi = dl._VtxWritePtr, dl._IdxWritePtr, dl._VtxCurrentIdx
local culled = 0
for prim = i0, i1 do
local val = d and d[prim + 1] or ix.At(ix, prim)
local row, c
if col_maj then
row, c = prim % rows, prim // rows
else
row, c = prim // cols, prim % cols
end
local px = xref + hx + c * w
local py = yref + ydir * (hy + row * h)
local t = math.clamp((val - smin) / (smax - smin), 0.0, 1.0)
local idx
if qual then
idx = min(max(floor(siz * t), 0), siz - 1) -- ImClamp
else
idx = floor((siz - 1) * t + 0.5)
end
local col = tables[off + idx + 1]
local x1, y1 = xpm + xm * ((px - hx) - xpl), ypm + ym * ((py - hy) - ypl)
local x2, y2 = xpm + xm * ((px + hx) - xpl), ypm + ym * ((py + hy) - ypl)
local minx, maxx = x1, x2
if x2 < x1 then minx, maxx = x2, x1 end
local miny, maxy = y1, y2
if y2 < y1 then miny, maxy = y2, y1 end
if band(col, IM_COL32_A_MASK) ~= 0 and miny < cmaxy and maxy > cminy and minx < cmaxx and maxx > cminx then
local o = (vw - 1) * VTX_STRIDE
WV(b, o, x1, y1, u, v, col)
WV(b, o + VTX_STRIDE, x2, y2, u, v, col)
WV(b, o + VTX_STRIDE * 2, x1, y2, u, v, col)
WV(b, o + VTX_STRIDE * 3, x2, y1, u, v, col)
id[iw] = vi; id[iw + 1] = vi + 1; id[iw + 2] = vi + 2
id[iw + 3] = vi; id[iw + 4] = vi + 1; id[iw + 5] = vi + 3
vw += 4; iw += 6; vi += 4
else
culled += 1
end
end
dl._VtxWritePtr, dl._IdxWritePtr, dl._VtxCurrentIdx = vw, iw, vi
return culled
end
local heat_r = { IdxConsumed = 6, VtxConsumed = 4, Init = WhiteInit, Render = HeatmapRender, RenderRange = HeatmapRange }
local heat_r = { IdxConsumed = 6, VtxConsumed = 4, Init = WhiteInit, Render = HeatmapRender }
local label_pos = ImVec2(0, 0)
@@ -7395,13 +6994,12 @@ return function(G)
if reverse_y then yref, ydir = bmax_y, -1 end
local r = heat_r
r.Indexer, r.Prims, r.Rows, r.Cols, r.ColMaj = indexer, rows * cols, rows, cols, col_maj
r.Data = PlainData(indexer)
r.ScaleMin, r.ScaleMax = scale_min, scale_max
r.Width, r.Height = (bmax_x - bmin_x) / cols, (bmax_y - bmin_y) / rows
r.XRef, r.YRef, r.YDir = bmin_x, yref, ydir
r.Colormaps, r.Cmap = gp.ColormapData, gp.Style.Colormap
RenderPrimitivesEx(r, draw_list, gp.CurrentPlot.PlotRect)
r.Indexer, r.Data = nil, nil
r.Indexer = nil
-- labels
if fmt ~= nil then
local w = (bmax_x - bmin_x) / cols
@@ -7461,7 +7059,6 @@ return function(G)
local hist_spec = SpecDefaults({})
-- PlotHistogram(label_id, values, count?, bins = ImPlotBin.Sturges, bar_scale = 1.0, range = ImPlotRange(), spec?)
@native
function ImPlot.PlotHistogram(label_id, values, count, bins, bar_scale, range, sp)
count = count or #values
bins = bins or ImPlotBin.Sturges
@@ -7498,9 +7095,8 @@ return function(G)
end
local counted = 0
local max_count = 0
local d = PlainData(indexer)
for i = 0, count - 1 do
local val = d and d[i + 1] or indexer.At(indexer, i)
local val = indexer.At(indexer, i)
if val >= rmin and val <= rmax then
local b = math.clamp(floor((val - rmin) / width), 0, bins - 1) + 1
bin_counts[b] += 1.0
@@ -7568,7 +7164,6 @@ return function(G)
local bin_counts_2d = {}
-- PlotHistogram2D(label_id, xs, ys, count?, x_bins = ImPlotBin.Sturges, y_bins = ImPlotBin.Sturges, range = ImPlotRect(), spec?)
@native
function ImPlot.PlotHistogram2D(label_id, xs, ys, count, x_bins, y_bins, range, sp)
count = count or min(#xs, #ys)
x_bins = x_bins or ImPlotBin.Sturges
@@ -7616,10 +7211,8 @@ return function(G)
local counted = 0
local max_count = 0
local dx, dy = PlainData(indexer_x), PlainData(indexer_y)
for i = 0, count - 1 do
local x = dx and dx[i + 1] or indexer_x.At(indexer_x, i)
local y = dy and dy[i + 1] or indexer_y.At(indexer_y, i)
local x, y = indexer_x.At(indexer_x, i), indexer_y.At(indexer_y, i)
if x >= xmin and x <= xmax and y >= ymin and y <= ymax then
local xb = math.clamp(floor((x - xmin) / width), 0, x_bins - 1)
local yb = math.clamp(floor((y - ymin) / height), 0, y_bins - 1)
-9939
View File
File diff suppressed because it is too large. Load diff
-2990
View File
File diff suppressed because it is too large. Load diff
-29
View File
@@ -1,29 +0,0 @@
#!/usr/bin/env sh
# Regenerates love/: Lua 5.1 (LÖVE/LuaJIT) copies of the Luau sources. Needs darklua + python3.
set -e
cd "$(dirname "$0")/.."
mkdir -p love
CFG=$(mktemp)
echo '{ "generator": "retain_lines", "rules": ["remove_types", "remove_compound_assignment", "remove_if_expression", "remove_continue", "remove_interpolated_string", "remove_floor_division"] }' > "$CFG"
for f in ImPlot.lua ImPlotDemo.lua; do
out="love/$(basename "$f")"
darklua process -c "$CFG" "$f" "$out"
python3 - "$out" <<'PY'
import re, sys
p = sys.argv[1]; src = open(p).read()
src = re.sub(r"^\s*@native\s*$", "", src, flags=re.M)
# Luau generalized iteration: for k, v in t do -> for k, v in __iter(t) do
src = re.sub(r"^([ \t]*for[ \t]+[\w][\w, \t]*[ \t]in[ \t]+)([^\n]*?)([ \t]+do\b)", r"\1__iter(\2)\3", src, flags=re.M)
head = ("-- GENERATED by tools/love.sh from the Luau source - do not edit\n"
"local function __iter(t, ...) if type(t) ~= 'table' or (getmetatable(t) and getmetatable(t).__call) then return t, ... end "
"local n, i, k = #t, 0, nil return function() if i < n then i = i + 1 return i, t[i] end "
"repeat k = next(t, k) until k == nil or type(k) ~= 'number' or k < 1 or k > n or k % 1 ~= 0 if k ~= nil then return k, t[k] end end end "
"table.create = table.create or function(n, v) local t = {} if v ~= nil then for i = 1, n do t[i] = v end end return t end "
"table.clone = table.clone or function(t) local c = {} for k, v in pairs(t) do c[k] = v end return setmetatable(c, getmetatable(t)) end "
"math.clamp = math.clamp or function(x, a, b) return math.max(a, math.min(b, x)) end "
"math.sign = math.sign or function(x) return x > 0 and 1 or (x < 0 and -1 or 0) end "
"math.round = math.round or function(x) return x >= 0 and math.floor(x + 0.5) or math.ceil(x - 0.5) end\n")
open(p, "w").write(head + src)
PY
done
rm -f "$CFG"