Introduce Tooltip::gap
to control spacing
This commit is contained in:
parent
9f60a256fc
commit
2f766b7341
@ -113,5 +113,6 @@ fn tooltip<'a>(
|
|||||||
Text::new("Tooltip"),
|
Text::new("Tooltip"),
|
||||||
position,
|
position,
|
||||||
)
|
)
|
||||||
|
.gap(10)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ where
|
|||||||
content: &Element<'_, Message, Self>,
|
content: &Element<'_, Message, Self>,
|
||||||
tooltip: &Text<Self>,
|
tooltip: &Text<Self>,
|
||||||
position: Position,
|
position: Position,
|
||||||
|
gap: u16,
|
||||||
) -> Self::Output {
|
) -> Self::Output {
|
||||||
let bounds = content_layout.bounds();
|
let bounds = content_layout.bounds();
|
||||||
|
|
||||||
@ -58,18 +59,21 @@ where
|
|||||||
let y_center =
|
let y_center =
|
||||||
bounds.y + (bounds.height - tooltip_bounds.height) / 2.0;
|
bounds.y + (bounds.height - tooltip_bounds.height) / 2.0;
|
||||||
|
|
||||||
|
let gap = f32::from(gap);
|
||||||
|
|
||||||
let offset = match position {
|
let offset = match position {
|
||||||
Position::Top => {
|
Position::Top => Vector::new(
|
||||||
Vector::new(x_center, bounds.y - tooltip_bounds.height)
|
x_center,
|
||||||
}
|
bounds.y - tooltip_bounds.height - gap,
|
||||||
|
),
|
||||||
Position::Bottom => {
|
Position::Bottom => {
|
||||||
Vector::new(x_center, bounds.y + bounds.height)
|
Vector::new(x_center, bounds.y + bounds.height + gap)
|
||||||
}
|
}
|
||||||
Position::Left => {
|
Position::Left => {
|
||||||
Vector::new(bounds.x - tooltip_bounds.width, y_center)
|
Vector::new(bounds.x - tooltip_bounds.width - gap, y_center)
|
||||||
}
|
}
|
||||||
Position::Right => {
|
Position::Right => {
|
||||||
Vector::new(bounds.x + bounds.width, y_center)
|
Vector::new(bounds.x + bounds.width + gap, y_center)
|
||||||
}
|
}
|
||||||
Position::FollowCursor => Vector::new(
|
Position::FollowCursor => Vector::new(
|
||||||
cursor_position.x,
|
cursor_position.x,
|
||||||
|
@ -15,6 +15,7 @@ pub struct Tooltip<'a, Message, Renderer: self::Renderer + text::Renderer> {
|
|||||||
content: Element<'a, Message, Renderer>,
|
content: Element<'a, Message, Renderer>,
|
||||||
tooltip: Text<Renderer>,
|
tooltip: Text<Renderer>,
|
||||||
position: Position,
|
position: Position,
|
||||||
|
gap: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Message, Renderer> Tooltip<'a, Message, Renderer>
|
impl<'a, Message, Renderer> Tooltip<'a, Message, Renderer>
|
||||||
@ -33,8 +34,15 @@ where
|
|||||||
content: content.into(),
|
content: content.into(),
|
||||||
tooltip,
|
tooltip,
|
||||||
position,
|
position,
|
||||||
|
gap: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the gap between the content and its [`Tooltip`].
|
||||||
|
pub fn gap(mut self, gap: u16) -> Self {
|
||||||
|
self.gap = gap;
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The position of the tooltip. Defaults to following the cursor.
|
/// The position of the tooltip. Defaults to following the cursor.
|
||||||
@ -109,6 +117,7 @@ where
|
|||||||
&self.content,
|
&self.content,
|
||||||
&self.tooltip,
|
&self.tooltip,
|
||||||
self.position,
|
self.position,
|
||||||
|
self.gap,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,6 +152,7 @@ pub trait Renderer: crate::Renderer + text::Renderer {
|
|||||||
content: &Element<'_, Message, Self>,
|
content: &Element<'_, Message, Self>,
|
||||||
tooltip: &Text<Self>,
|
tooltip: &Text<Self>,
|
||||||
position: Position,
|
position: Position,
|
||||||
|
gap: u16,
|
||||||
) -> Self::Output;
|
) -> Self::Output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user