Skip to content

PannableCanvas

@Composable



fun PannableCanvas(
    modifier: Modifier = Modifier, 
    state: PannableCanvasState = rememberPannableCanvasState(), 
    backgroundTexture: ResourceLocation? = null, 
    backgroundTextureSize: Int = 32, 
    backgroundTint: Int = -1, 
    backgroundParallax: Float = 1.0f, 
    panelTexture: String = "surface", 
    panelVariant: String? = "inset_transparent", 
    panelContentPadding: Int = 2, 
    content: @Composable



 () -> Unit
)

A fixed-size viewport (modifier's own size) over a single, arbitrarily large child, panned by click-dragging anywhere inside it - the same "pan around a graph" interaction the vanilla advancements screen (and Thaumcraft's Thaumonomicon, and quest-book mods generally) uses, built on the same Layout/Renderer primitives Scrollable is, minus the scrollbar/lerp animation (NodeTreeView's node graph pans 1:1 with the drag, not eased). Content outside the viewport is clipped via a scissor, matching how Scrollable hides its own overflowed content.

The scroll wheel adjusts PannableCanvasState.zoom by PannableCanvasState.ZOOM_STEP per notch, anchored on the cursor (see PannableCanvasState.zoomBy) - content itself decides what "zoom" actually means for whatever it draws (PannableCanvas only owns the shared zoom number/pan-math, not any particular rendering of it); NodeTreeView is the one consumer that currently does anything with it.

Parameters

  • backgroundTexture: When given, tiled across the whole viewport and panned alongside content (the same "infinite paper" backdrop Thaumonomicon-style guide/skill-tree screens use, analogous to vanilla's own repeating dirt background) - a plain, unpanned background belongs on modifier instead (e.g. via Panel/Surface), since a texture given here specifically moves.

  • backgroundTextureSize: backgroundTexture's own tile size in pixels (it's sampled with wrapping, so it must actually tile at this size - 32 matches vanilla's options_background).

  • backgroundTint: Packed ARGB tint applied to backgroundTexture - -1 draws it unmodified.

  • backgroundParallax: How fast backgroundTexture pans relative to content - 1f is exact lockstep, below that trails behind (a parallax depth cue), 0f pins it in place.

  • panelTexture: /panelVariant A themed Surface frame drawn over the whole viewport (see Surface's own drawOverContent), wrapping every PannableCanvas in a bordered panel by default. modifier applies to this outer frame. Pass panelVariant = null to opt out.

  • panelContentPadding: How far the pannable viewport sits inset from panelVariant's own edge, so its own corners don't peek through the border's transparent rounded corners. Ignored when panelVariant is null. Defaults to this theme's own nine-slice border thickness.