From 18bd5c1950b5b413e9becb6208e96afc81c7f270 Mon Sep 17 00:00:00 2001 From: Lorenzo Gaifas Date: Sat, 25 Jul 2026 16:22:13 +0200 Subject: [PATCH 1/2] change overlay access pattern --- docs/_scripts/homepage_video.py | 2 +- docs/getting_started/viewer.md | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/_scripts/homepage_video.py b/docs/_scripts/homepage_video.py index 9c3e5270a..ae8abddb9 100644 --- a/docs/_scripts/homepage_video.py +++ b/docs/_scripts/homepage_video.py @@ -82,7 +82,7 @@ def build_viewer(*, show: bool) -> napari.Viewer: layer.rendering = RENDERING layer.attenuation = ATTENUATION layer.colormap = COLORMAP - viewer.scale_bar.visible = True + viewer.canvas.scale_bar.visible = True viewer.axes.visible = True viewer.dims.axis_labels = ('T', 'Z', 'Y', 'X') viewer.window._qt_window.resize(*WINDOW_SIZE) diff --git a/docs/getting_started/viewer.md b/docs/getting_started/viewer.md index e224458fa..61b1b8c4c 100644 --- a/docs/getting_started/viewer.md +++ b/docs/getting_started/viewer.md @@ -635,11 +635,15 @@ The right side of the status bar contains some helpful tips depending on which l Overlays provide additional information about the render state and the data, displayed on the canvas itself. In napari there are two main types: canvas overlays - which are locked in position on the screen and hover over the rendered canvas - and scene overlays - which are located somewhere in world coordinates and follow the camera and dims just like layers. Canvas overlays can be positioned in various locations on the canvas (e.g: `top_left`, `bottom_center`), and will automatically tile if multiple are present at the same location. -The viewer gives access to a few such overlays: +Canvas overlays can be accessed via `viewer.canvas.overlays`, whereas viewer overlays live on the viewer itself. For example: -- Scale bar (canvas overlay, accessible via `viewer.scale_bar`): it displays distances in world coordinates for the displayed scene. The scale bar usually inherits layer units when they are set. If inference fails it can fall back to a dimensionless label, and if displayed axes mix dimensionalities it uses the last displayed axis unit with a warning. You can control its appearance and fixed length from the viewer. See the [units guide](units-guide) for more information. +```{tip} +`viewer.canvas.overlays` is a smart dictionary that allows access via attributes, instead of only via keys. So a shorthand for `viewer.canvas.overlays['text'] is `viewer.canvas.overlays.text`! +``` + +- Scale bar (accessible via `viewer.canvas.overlays.scale_bar`): it displays distances in world coordinates for the displayed scene. The scale bar usually inherits layer units when they are set. If inference fails it can fall back to a dimensionless label, and if displayed axes mix dimensionalities it uses the last displayed axis unit with a warning. You can control its appearance and fixed length from the viewer. See the [units guide](units-guide) for more information. - Axes (scene overlay, accessible via `viewer.axes`): displays basis axes at the origin. -- Text Overlay (canvas overlay, accessible via `viewer.text_overlay`): displays arbitrary text on the canvas. +- Text Overlay (canvas overlay, accessible via `viewer.canvas.overlays.text`): displays arbitrary text on the canvas. These overlays can also be accessed via graphical interface through the **View** menu and their respective submenus. From 323bc9402bbf95d7d26e2c1bbbfe3c1aee38c6c2 Mon Sep 17 00:00:00 2001 From: Lorenzo Gaifas Date: Sat, 25 Jul 2026 16:29:30 +0200 Subject: [PATCH 2/2] update docs --- docs/getting_started/viewer.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/getting_started/viewer.md b/docs/getting_started/viewer.md index 61b1b8c4c..f1ac93f01 100644 --- a/docs/getting_started/viewer.md +++ b/docs/getting_started/viewer.md @@ -178,6 +178,8 @@ The **canvas** is in the center of the viewer and contains the visual display of +++ +The canvas model can be accessed via `viewer.canvas`; several things are exposed here, such as the [grid mode](grid-mode), [canvas overlays](viewer-overlays) and the overlay tiling settings. + (layer-list)= ### Layer list @@ -589,6 +591,8 @@ Note that this has no effect on the order of `viewer.dims.current_step`. The fir The fourth button transposes the displayed dimensions. +(grid-mode)= + ### Grid button The fifth button, the grid button, toggles between the default layer mode and grid mode. When clicked, it distributes the layers in a grid of cells. Each cell is a small interactive canvas whose camera is linked with all the others. @@ -606,7 +610,7 @@ The fifth button, the grid button, toggles between the default layer mode and gr ``` -The distribution of the layers in the grid can be altered according to the settings below, accessible by right-clicking the button (or programmatically through `viewer.grid`). The question icons can be hovered for more information about each setting. +The distribution of the layers in the grid can be altered according to the settings below, accessible by right-clicking the button (or programmatically through `viewer.canvas.grid`). The question icons can be hovered for more information about each setting. 1. Grid stride: By default, 1, placing one layer in each view. The value determines the number of layers overlaid in each view. Negative values reverse the order in which layers are displayed in the grid. 1. Grid width/height: By default, -1, which automatically determines the grid layout.