TFT_eSPI version 2.x introduced a viewport/clipping system (signalled byDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Marcussacapuces91/doc-TFT_eSPI/llms.txt
Use this file to discover all available pages before exploring further.
TFT_ESPI_FEATURES bit 0 being set) that lets you constrain all drawing operations to a rectangular sub-region of the display. Any pixel written outside the viewport is silently discarded with no performance penalty. Below the viewport layer is the address-window layer — raw hardware window commands that set the pixel RAM pointer before a burst write. Both layers are documented here, along with helper functions for checking whether a rectangle intersects the current viewport and for drawing a coloured border around it.
setViewport() — Define the Active Clipping Region
(x, y, w, h). Pixels drawn outside this region are discarded. When vpDatum is true the coordinate origin (0, 0) is relocated to the top-left corner of the viewport, so you can write self-contained widget code that always draws from (0, 0).
X position of the viewport top-left corner in screen coordinates.
Y position of the viewport top-left corner in screen coordinates.
Viewport width in pixels.
Viewport height in pixels.
When
true (default), drawing coordinates are relative to the viewport top-left corner — (0, 0) maps to the viewport origin. When false, screen coordinates are used but drawing outside the viewport is still clipped.resetViewport() — Remove Viewport Clipping
checkViewport() — Test Rectangle Intersection
true if the rectangle (x, y, w, h) intersects the current viewport. Useful for early-exit optimizations in render loops — if the target bounding box does not intersect the viewport, the draw call can be skipped entirely.
X coordinate of the test rectangle (screen or viewport-relative, consistent with the current datum setting).
Y coordinate of the test rectangle.
Width of the test rectangle.
Height of the test rectangle.
bool — true if the rectangle overlaps the viewport; false otherwise.
getViewportX() / getViewportY() — Read Viewport Position
int32_t — viewport X or Y position in screen pixels.
getViewportWidth() / getViewportHeight() — Read Viewport Size
int32_t — viewport width or height in pixels.
getViewportDatum() — Read Datum Setting
vpDatum flag set by the last setViewport() call.
Returns: bool — true if coordinates are relative to the viewport origin; false for screen coordinates.
frameViewport() — Draw a Border Around the Viewport
w pixels along the inner edge of the current viewport. This is a convenience function equivalent to drawing four filled rectangles at the viewport perimeter.
Border colour (RGB565 or
TFT_* constant).Border thickness in pixels.
setWindow() — Set Hardware Pixel RAM Window
pushColor(), pushColors(), or pushBlock(). This is a virtual method overridden by each driver.
Start X coordinate (top-left, inclusive).
Start Y coordinate (top-left, inclusive).
End X coordinate (bottom-right, inclusive).
End Y coordinate (bottom-right, inclusive).
setWindow() uses inclusive end coordinates. If you have a width and height, use setAddrWindow() instead.setAddrWindow() — Set Hardware Window (Width/Height Form)
setWindow() but takes a width and height instead of end coordinates, matching the convention used by most higher-level drawing calls.
Start X coordinate.
Start Y coordinate.
Window width in pixels.
Window height in pixels.
clipAddrWindow() — Clip Window to Display Bounds
false if the clipped window has zero or negative area (i.e. the window is entirely off-screen), in which case the caller should skip the draw operation.
Pointer to the X start coordinate; modified in place.
Pointer to the Y start coordinate; modified in place.
Pointer to the width; modified in place.
Pointer to the height; modified in place.
bool — true if the clipped window has a non-zero area; false if it is entirely off-screen.
clipWindow() — Clip Window to Display Bounds (End-Coordinate Form)
clipAddrWindow() but operates on inclusive end-coordinate pairs (xs, ys) to (xe, ye). Modifies the coordinates in place and returns false if the result is degenerate.
Pointer to the start X; modified in place.
Pointer to the start Y; modified in place.
Pointer to the end X (inclusive); modified in place.
Pointer to the end Y (inclusive); modified in place.
bool — true if the clipped window is valid; false if entirely off-screen.