plot(tooltip): Fix the dots not centered (#1229)

This commit is contained in:
Floyd Wang 2025-09-09 18:01:01 +08:00 committed by GitHub
parent e1dede93b4
commit ab98e53a5a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -145,16 +145,19 @@ impl Dot {
impl RenderOnce for Dot { impl RenderOnce for Dot {
fn render(self, _: &mut Window, _: &mut App) -> impl IntoElement { fn render(self, _: &mut Window, _: &mut App) -> impl IntoElement {
let border_width = px(1.);
let offset = self.size / 2. - border_width / 2.;
div() div()
.absolute() .absolute()
.w(self.size) .w(self.size)
.h(self.size) .h(self.size)
.rounded_full() .rounded_full()
.border_1() .border(border_width)
.border_color(self.stroke) .border_color(self.stroke)
.bg(self.fill) .bg(self.fill)
.left(self.point.x - self.size / 2.) .left(self.point.x - offset)
.top(self.point.y - self.size / 2.) .top(self.point.y - offset)
} }
} }
@ -264,21 +267,25 @@ impl RenderOnce for Tooltip {
.left_0() .left_0()
.when_some(self.cross_line, |this, cross_line| this.child(cross_line)) .when_some(self.cross_line, |this, cross_line| this.child(cross_line))
.when_some(self.dots, |this, dots| this.children(dots)) .when_some(self.dots, |this, dots| this.children(dots))
.child(self.base.when(self.appearance, |this| { .child(self.base.map(|this| {
this.absolute() if self.appearance {
.min_w(px(168.)) this.absolute()
.p_2() .min_w(px(168.))
.border_1() .p_2()
.border_color(cx.theme().border) .border_1()
.rounded_sm() .border_color(cx.theme().border)
.bg(cx.theme().background.opacity(0.9)) .rounded_sm()
.when_some(self.position, |this, position| { .bg(cx.theme().background.opacity(0.9))
if position == TooltipPosition::Left { .when_some(self.position, |this, position| {
this.left(self.gap) if position == TooltipPosition::Left {
} else { this.left(self.gap)
this.right(self.gap) } else {
} this.right(self.gap)
}) }
})
} else {
this.size_full().relative()
}
})) }))
} }
} }