feat: add public plot_area_bounds() getter#22
Open
mmavka wants to merge 1 commit intodonkeyteethUX:mainfrom
Open
feat: add public plot_area_bounds() getter#22mmavka wants to merge 1 commit intodonkeyteethUX:mainfrom
mmavka wants to merge 1 commit intodonkeyteethUX:mainfrom
Conversation
Returns Option<Rectangle> with the current pixel rectangle of the plot area (excluding axes, labels, legend). Reads from the widget's cached camera_bounds state, which is kept in sync on every pan/zoom/resize via the internal RenderUpdate flow. Useful for applications that need the plot area's pixel dimensions to make pixel-aware decisions (e.g. choosing an LOD level when requesting downsampled data from a streaming source, or laying out overlay UI relative to the plot area).
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
PlotWidgetsometimes need the current pixelrectangle of the plot area (excluding axes, labels, legend) but don't need
the data-space ranges. Common cases:
source: the right bucket resolution depends on how many pixels each
bucket will cover.
drawing tools, floating annotations placed in world coordinates but
clipped to the plot box).
on top of the plot via
iced::widget::stack!.Today, the plot area rectangle is cached on
PlotWidgetas part ofcamera_bounds, but that field is crate-private;RenderUpdatealsocarries the bounds in its
camera_boundspayload, but that payload ispub(crate)behind a#[doc(hidden)]struct. So even though the data isalready tracked and updated on every pan/zoom/resize, there is no
public way to read it.
This PR exposes the minimum-viable getter for that case: a one-liner
that returns
Option<Rectangle>.What this PR does
PlotWidget::plot_area_bounds(&self) -> Option<Rectangle>.camera_boundsstate — no new state,no new tracking logic.
Noneif the widget hasn't been rendered yet (camera_bounds islazily populated during the first shader update).
API additions
Non-breaking
Example use case
Alternatives considered
current_viewport()getter (proposed in a separate PR). Viable, but callers that only
care about pixel dimensions shouldn't have to allocate/cover a full
ViewportInfoor invert axis scales that they don't use.Option<(f32, f32)>for just width+height. Losesabsolute position, which overlay UIs need.
Related
None. Complementary to any viewport-exposure PR, but independent —
applications that only need pixel dimensions can use this alone.