pub trait Plot: IntoElement {
// Required method
fn paint(
&mut self,
bounds: Bounds<Pixels>,
window: &mut Window,
cx: &mut App,
);
// Provided methods
fn prepaint(
&mut self,
_bounds: Bounds<Pixels>,
_window: &mut Window,
_cx: &mut App,
) -> Vec<AnyElement> { ... }
fn id(&self) -> Option<ElementId> { ... }
fn tooltip_state(
&self,
_position: Point<Pixels>,
_bounds: Bounds<Pixels>,
_cx: &App,
) -> Option<TooltipState> { ... }
fn hover(
&mut self,
_hover: Option<&PlotHover>,
_window: &mut Window,
_cx: &mut App,
) { ... }
fn tooltip(
&self,
_state: &TooltipState,
_cursor: Point<Pixels>,
_bounds: Bounds<Pixels>,
_window: &mut Window,
_cx: &mut App,
) -> Option<AnyElement> { ... }
}Required Methods§
Provided Methods§
Sourcefn prepaint(
&mut self,
_bounds: Bounds<Pixels>,
_window: &mut Window,
_cx: &mut App,
) -> Vec<AnyElement>
fn prepaint( &mut self, _bounds: Bounds<Pixels>, _window: &mut Window, _cx: &mut App, ) -> Vec<AnyElement>
Lay out and place the child elements this plot hosts (e.g. element labels).
Called during the element’s prepaint phase, so implementations may use
AnyElement::layout_as_root / AnyElement::prepaint_at to measure and
position children — neither is legal from Plot::paint. The returned
elements are painted right after paint, below the tooltip overlay.
Runs before Plot::tooltip_state and Plot::tooltip, so anything
resolved here can be reused by them.
The default returns no children.
Sourcefn id(&self) -> Option<ElementId>
fn id(&self) -> Option<ElementId>
A stable element id that enables interactive tooltip support for this plot.
Return Some(id) to opt in to tooltips and hover motion; the id must be unique
among sibling elements. Returning None (the default for a hand-written plot)
disables all tooltip behavior, leaving the plot a pure, non-interactive element.
The charts in GPUI Component always return Some: their id defaults to the
source location they were constructed at, and id renames it.
Sourcefn tooltip_state(
&self,
_position: Point<Pixels>,
_bounds: Bounds<Pixels>,
_cx: &App,
) -> Option<TooltipState>
fn tooltip_state( &self, _position: Point<Pixels>, _bounds: Bounds<Pixels>, _cx: &App, ) -> Option<TooltipState>
Map the cursor to the tooltip state to display.
position is the cursor position relative to the plot’s top-left origin (already
origin-subtracted), and bounds is the painted area. Return the TooltipState
to display (highlighted index, crosshair point, dots), or None to show
nothing. Only called while the cursor is inside bounds.
The default returns None.
Sourcefn hover(
&mut self,
_hover: Option<&PlotHover>,
_window: &mut Window,
_cx: &mut App,
)
fn hover( &mut self, _hover: Option<&PlotHover>, _window: &mut Window, _cx: &mut App, )
Receive the hovered datum this frame, before Plot::tooltip and
Plot::paint run.
hover carries the TooltipState the cursor resolved to, and it
lingers after the cursor leaves while PlotHover::progress eases back to
zero, so a hover-driven presentation can fade out over the last datum
instead of vanishing. None means nothing is hovered and nothing is
fading.
Called on every frame the plot has an Plot::id, so this is where a
plot samples its hover motion (crate::motion::transition,
PlotHover::glide) and keeps the result for the other two methods.
The default ignores the hover.
Sourcefn tooltip(
&self,
_state: &TooltipState,
_cursor: Point<Pixels>,
_bounds: Bounds<Pixels>,
_window: &mut Window,
_cx: &mut App,
) -> Option<AnyElement>
fn tooltip( &self, _state: &TooltipState, _cursor: Point<Pixels>, _bounds: Bounds<Pixels>, _window: &mut Window, _cx: &mut App, ) -> Option<AnyElement>
Render the tooltip overlay for the active TooltipState.
cursor is the live cursor position (relative to the plot origin) and bounds is the
plot’s painted area, so the tooltip box can follow the cursor (pass cursor and
bounds.size to the styled layer’s tooltip). Return the overlay element; it is
painted absolutely positioned above the plot graphics but below sibling content
drawn after the plot (a box that may overflow the plot should deferred itself).
The default returns None.
Also called while the hover fades out, with the lingering state and the
last cursor; the overlay renders within the plot’s element scope, so it can
fade with hover_progress.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".