MCPcopy Create free account
hub / github.com/donkeyteethUX/iced_plot / view_top_right_overlay

Method view_top_right_overlay

src/plot_widget.rs:1040–1072  ·  view source on GitHub ↗
(&self, has_legend: bool)

Source from the content-addressed store, hash-verified

1038
1039 fn view_tooltip_overlay<'a>(
1040 &'a self,
1041 payload: &'a Option<TooltipUiPayload>,
1042 camera_bounds: &Option<(Camera, Rectangle)>,
1043 ) -> Option<Element<'a, PlotUiMessage>> {
1044 // Offset a bit from point position
1045 const OFFSET: f32 = 8.0;
1046 let payload = payload.as_ref()?;
1047 let [screen_x, screen_y] = payload.screen_xy?;
1048
1049 let mut anchor = [screen_x + OFFSET, screen_y + OFFSET];
1050 let mut horizontal_position = Horizontal::Right;
1051 let mut vertical_position = Vertical::Bottom;
1052
1053 // flip the tooltip if the point is outside this percentage of the bounds
1054 const FLIP_PCT: f32 = 0.8;
1055 if let Some((_, bounds)) = &camera_bounds {
1056 if screen_y > bounds.height * FLIP_PCT {
1057 // Place the tooltip above the point.
1058 anchor[1] = screen_y - OFFSET;
1059 vertical_position = Vertical::Top;
1060 }
1061 if screen_x > bounds.width * FLIP_PCT {
1062 // Place the tooltip to the left of the point.
1063 anchor[0] = screen_x - OFFSET;
1064 horizontal_position = Horizontal::Left;
1065 }
1066 }
1067
1068 let tooltip_bubble = container(
1069 widget::text(&payload.text)
1070 .size(14.0)
1071 .wrapping(widget::text::Wrapping::None),
1072 )
1073 .padding(6.0)
1074 .style(|theme| self.update_style(theme).tooltip);
1075

Callers 1

Calls 2

thenMethod · 0.80
sizeMethod · 0.80

Tested by

no test coverage detected