The abstract view: a fitted 2D projection of the scene, drawn by the lab. More...
| Import Statement: | import Clayground.Lab |
| Inherits: |
Half of the highest-value pattern the labs know - dual representation, one model: the 3D scene shows what you built, this panel shows what it is, and both read the same data so they cannot disagree. Electronics draws a circuit diagram in one; street-network draws its lane graph.
Both had implemented the same two things by hand: a fit-to-content projection (fit what exists, not the whole sheet - an empty board would otherwise squeeze the drawing into a corner) and the repaint plumbing that keeps a Canvas in step with a model that mutates in place. This owns both; the lab supplies bounds and a draw callback and nothing else.
draw receives the context and a map with px(), py() and the scale s, so the lab's paint code never does arithmetic on the panel's size.
MiniMap { title: LabLang.t("plan.title") tag: "M" width: LabTheme.px(258); height: LabTheme.px(190) revision: root.graphRev emptyText: LabLang.t("plan.empty") bounds: RoadGraph.bounds(root.graph) // {x0, y0, x1, y1, empty} draw: (ctx, map) => { for (const lane of root.net.lanes) { ctx.strokeStyle = LabTheme.muted.toString() ctx.beginPath() ctx.moveTo(map.px(lane.x0), map.py(lane.z0)) ctx.lineTo(map.px(lane.x1), map.py(lane.z1)) ctx.stroke() } } }
bounds : var |
What to fit, as {x0, y0, x1, y1} - or {empty: true}.
Accepts z0 / z1 in place of y0 / y1, because a top-down view of a 3D scene is naturally expressed in x/z and re-labelling it at every call site is how a sign error gets in.
contentPadding : real |
Inset kept around the fitted content.
draw : var |
(ctx, map) -> void: the lab's paint code.
emptyText : string |
Drawn centred when bounds is empty.
map : var |
The live projection: {s, sx, sy, ox, oy, px(), py(), width, height, empty}.
Available to bindings as well as to draw, for a lab that wants to put a QtQuick item at a projected point rather than paint it.
revision : int |
Bump to repaint. The counter every in-place model needs.
uniformScale : bool |
Keep the aspect ratio, so the shape stays the shape you built.
Almost always what you want; turn it off only for a display whose two axes are different quantities.
void repaint() |
Force a repaint.