feat: add public current_viewport() getter + ViewportInfo#20
Open
mmavka wants to merge 1 commit intodonkeyteethUX:mainfrom
Open
feat: add public current_viewport() getter + ViewportInfo#20mmavka wants to merge 1 commit intodonkeyteethUX:mainfrom
mmavka wants to merge 1 commit intodonkeyteethUX:mainfrom
Conversation
Adds PlotWidget::current_viewport() returning the current data-space x/y ranges plus the plot-area pixel rectangle as a new public ViewportInfo struct. Reads from the widget's cached camera_bounds state which is already synced on every pan/zoom/resize via the internal RenderUpdate flow. For non-linear axis scales (Log), plot-space values are inverted back to data-space before return. Enables downstream code to coordinate external behavior with the plot viewport (e.g. fetching a data range from a backend, syncing a secondary view, serializing session state) without having to subscribe to PlotUiMessage::RenderUpdate and parse tick positions out of its doc-hidden payload.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Applications embedding
PlotWidgetoften need to read the current viewportprogrammatically to coordinate external behavior: fetching a data range from
a backend, syncing a secondary view or minimap, serializing session state,
building viewport-aware tooltips, or computing pixel-to-data projections
outside the widget's own event loop.
Today, the only way to observe viewport changes is to subscribe to
PlotUiMessage::RenderUpdateand read thex_ticks/y_ticksarrays —which is indirect (tick positions approximate the viewport rather than
describe it exactly), fragile (the payload struct is
#[doc(hidden)]),and costly (consumers allocate a full tick vec per change). Reading on-demand
currently isn't possible at all: the relevant camera/bounds state is cached
inside
PlotWidget.camera_boundsbut is crate-private.This PR exposes a direct, on-demand getter that returns the current data-space
ranges plus the plot area's pixel rectangle as a single
Copystruct.What this PR does
PlotWidget::current_viewport() -> Option<ViewportInfo>.ViewportInfo { x_min, x_max, y_min, y_max, plot_area: Rectangle }.ViewportInfofrom the crate root.camera_boundsstate — no new state, no newsyncing logic, no shader/renderer changes.
AxisScale::plot_to_dataso the returned ranges are meaningful even withAxisScale::Log.Noneif the widget hasn't been rendered yet (camera_bounds islazily populated during the first shader update).
API additions
Non-breaking
unsafe, no new panics.Example use case
Alternatives considered
PlotUiMessage::RenderUpdateand reading tick positions.Works, but approximate (tick values under-estimate the viewport edges),
ties consumers to a
#[doc(hidden)]payload struct, and doesn't supporton-demand reads.
Cameradirectly. Tighter binding to internal representation(e.g.
render_offsetis an implementation detail for high-precisionrendering, not a concept the API consumer should see). The
ViewportInfoshape keeps the surface minimal and stable.
ViewportChangedmessage variant. Nice additional signal butorthogonal to on-demand reads. Could follow as a separate PR if useful.
Related
None.