use std::any::Any;
use std::fmt::Debug;
use std::rc::Rc;
use waft_animation::{Animatable, AnyAnimation, ColorTween, Tween};
use waft_embedder::{
Canvas, ClipOp, Color, FillRule, Offset, Paint, PaintStyle, Path, PathBuilder, RRect, Radius,
Rect, Size, Stroke, TextDirection, rrect_radii_elliptical,
};
use waft_foundation::App;
use waft_painting::{BorderRadius, ClipContext, PaintingBinding, TextPainter, draw_rrect};
use waft_rendering::{AnyRenderBox, PaintingContext, RenderView};
use waft_widgets::WidgetStates;
use crate::colors::Colors;
use crate::slider_theme::SliderThemeData;
use crate::slider_value_indicator_shape::SliderComponentShape;
pub(crate) fn evaluate_color_tween(
app: &mut App,
begin: Option<Color>,
end: Option<Color>,
animation: AnyAnimation<f64>,
) -> Option<Color> {
let tween = ColorTween::new(app, begin, end);
tween.evaluate(app, animation)
}
pub(crate) fn evaluate_tween(
app: &mut App,
begin: f64,
end: f64,
animation: AnyAnimation<f64>,
) -> f64 {
let tween = Tween::new(app, Some(begin), Some(end));
tween.evaluate(app, animation)
}
pub(crate) fn draw_shadow(
app: &App,
canvas: &mut Canvas,
parent_box: AnyRenderBox,
path: &Path,
color: Color,
elevation: f64,
transparent_occluder: bool,
) {
let device_pixel_ratio = parent_box
.as_object()
.owner(app)
.and_then(|owner| owner.root_node(app))
.and_then(|root| root.downcast::<RenderView>(app))
.map_or(1.0, |view| view.configuration(app).device_pixel_ratio);
canvas.draw_shadow(
path.as_valo(),
path.fill_type,
color.into(),
elevation as f32,
transparent_occluder,
device_pixel_ratio as f32,
);
}
pub trait SliderTickMarkShape: Any + Debug {
fn get_preferred_size(&self, slider_theme: &SliderThemeData, is_enabled: bool) -> Size;
#[expect(clippy::too_many_arguments, reason = "Dart's parameters, in its order")]
fn paint(
&self,
app: &mut App,
context: &mut PaintingContext,
center: Offset,
parent_box: AnyRenderBox,
slider_theme: &SliderThemeData,
enable_animation: AnyAnimation<f64>,
thumb_center: Offset,
is_enabled: bool,
text_direction: TextDirection,
);
fn as_any(&self) -> &dyn Any;
fn eq_shape(&self, other: &dyn SliderTickMarkShape) -> bool {
std::ptr::eq(self.as_any(), other.as_any())
}
}
pub type SliderTickMarkShapeRef = Rc<dyn SliderTickMarkShape>;
impl PartialEq for dyn SliderTickMarkShape {
fn eq(&self, other: &dyn SliderTickMarkShape) -> bool {
self.eq_shape(other)
}
}
thread_local! {
static NO_TICK_MARK: SliderTickMarkShapeRef = Rc::new(EmptySliderTickMarkShape);
}
impl dyn SliderTickMarkShape {
pub fn no_tick_mark() -> SliderTickMarkShapeRef {
NO_TICK_MARK.with(Rc::clone)
}
}
pub trait SliderTrackShape: Any + Debug {
fn get_preferred_rect(
&self,
app: &App,
parent_box: AnyRenderBox,
offset: Offset,
slider_theme: &SliderThemeData,
is_enabled: Option<bool>,
is_discrete: Option<bool>,
) -> Rect;
#[expect(clippy::too_many_arguments, reason = "Dart's parameters, in its order")]
fn paint(
&self,
app: &mut App,
context: &mut PaintingContext,
offset: Offset,
parent_box: AnyRenderBox,
slider_theme: &SliderThemeData,
enable_animation: AnyAnimation<f64>,
thumb_center: Offset,
secondary_offset: Option<Offset>,
is_enabled: Option<bool>,
is_discrete: Option<bool>,
text_direction: TextDirection,
);
fn is_rounded(&self) -> bool {
false
}
fn as_any(&self) -> &dyn Any;
fn eq_shape(&self, other: &dyn SliderTrackShape) -> bool {
std::ptr::eq(self.as_any(), other.as_any())
}
}
pub type SliderTrackShapeRef = Rc<dyn SliderTrackShape>;
impl PartialEq for dyn SliderTrackShape {
fn eq(&self, other: &dyn SliderTrackShape) -> bool {
self.eq_shape(other)
}
}
pub trait BaseSliderTrackShape {
fn get_preferred_rect(
&self,
app: &App,
parent_box: AnyRenderBox,
offset: Offset,
slider_theme: &SliderThemeData,
is_enabled: Option<bool>,
is_discrete: Option<bool>,
) -> Rect {
let is_enabled = is_enabled.unwrap_or(false);
let is_discrete = is_discrete.unwrap_or(false);
let thumb_width = slider_theme
.thumb_shape
.as_ref()
.expect("a slider theme with a thumb shape")
.get_preferred_size(is_enabled, is_discrete)
.width();
let overlay_width = slider_theme
.overlay_shape
.as_ref()
.expect("a slider theme with an overlay shape")
.get_preferred_size(is_enabled, is_discrete)
.width();
let mut track_height = slider_theme
.track_height
.expect("a slider theme with a track height");
debug_assert!(overlay_width >= 0.0);
debug_assert!(track_height >= 0.0);
if slider_theme.active_track_color == Some(Colors::TRANSPARENT)
&& slider_theme.inactive_track_color == Some(Colors::TRANSPARENT)
{
track_height = 0.0;
}
let parent_size = parent_box.size(app);
let track_left = offset.dx()
+ if slider_theme.padding.is_none() {
(overlay_width / 2.0).max(thumb_width / 2.0)
} else {
0.0
};
let track_top = offset.dy() + (parent_size.height() - track_height) / 2.0;
let track_right = track_left + parent_size.width()
- if slider_theme.padding.is_none() {
thumb_width.max(overlay_width)
} else {
0.0
};
let track_bottom = track_top + track_height;
Rect::from_ltrb(
track_left.min(track_right),
track_top,
track_left.max(track_right),
track_bottom,
)
}
fn is_rounded(&self) -> bool {
false
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct RectangularSliderTrackShape;
impl RectangularSliderTrackShape {
pub const fn new() -> RectangularSliderTrackShape {
RectangularSliderTrackShape
}
}
impl BaseSliderTrackShape for RectangularSliderTrackShape {}
impl SliderTrackShape for RectangularSliderTrackShape {
fn get_preferred_rect(
&self,
app: &App,
parent_box: AnyRenderBox,
offset: Offset,
slider_theme: &SliderThemeData,
is_enabled: Option<bool>,
is_discrete: Option<bool>,
) -> Rect {
BaseSliderTrackShape::get_preferred_rect(
self,
app,
parent_box,
offset,
slider_theme,
is_enabled,
is_discrete,
)
}
fn paint(
&self,
app: &mut App,
context: &mut PaintingContext,
offset: Offset,
parent_box: AnyRenderBox,
slider_theme: &SliderThemeData,
enable_animation: AnyAnimation<f64>,
thumb_center: Offset,
secondary_offset: Option<Offset>,
is_enabled: Option<bool>,
is_discrete: Option<bool>,
text_direction: TextDirection,
) {
let is_discrete = is_discrete.unwrap_or(false);
let is_enabled = is_enabled.unwrap_or(false);
debug_assert!(slider_theme.disabled_active_track_color.is_some());
debug_assert!(slider_theme.disabled_inactive_track_color.is_some());
debug_assert!(slider_theme.active_track_color.is_some());
debug_assert!(slider_theme.inactive_track_color.is_some());
debug_assert!(slider_theme.thumb_shape.is_some());
if slider_theme
.track_height
.expect("a slider theme with a track height")
<= 0.0
{
return;
}
let active_paint = Paint::from_color(
evaluate_color_tween(
app,
slider_theme.disabled_active_track_color,
slider_theme.active_track_color,
enable_animation,
)
.expect("both track colors are set")
.into(),
);
let inactive_paint = Paint::from_color(
evaluate_color_tween(
app,
slider_theme.disabled_inactive_track_color,
slider_theme.inactive_track_color,
enable_animation,
)
.expect("both track colors are set")
.into(),
);
let (left_track_paint, right_track_paint) = match text_direction {
TextDirection::Ltr => (&active_paint, &inactive_paint),
TextDirection::Rtl => (&inactive_paint, &active_paint),
};
let track_rect = SliderTrackShape::get_preferred_rect(
self,
app,
parent_box,
offset,
slider_theme,
Some(is_enabled),
Some(is_discrete),
);
let left_track_segment = Rect::from_ltrb(
track_rect.left,
track_rect.top,
thumb_center.dx(),
track_rect.bottom,
);
if !left_track_segment.is_empty() {
context
.canvas()
.draw_rect(left_track_segment, left_track_paint);
}
let right_track_segment = Rect::from_ltrb(
thumb_center.dx(),
track_rect.top,
track_rect.right,
track_rect.bottom,
);
if !right_track_segment.is_empty() {
context
.canvas()
.draw_rect(right_track_segment, right_track_paint);
}
let show_secondary_track =
secondary_offset.is_some_and(|secondary_offset| match text_direction {
TextDirection::Rtl => secondary_offset.dx() < thumb_center.dx(),
TextDirection::Ltr => secondary_offset.dx() > thumb_center.dx(),
});
if let Some(secondary_offset) = secondary_offset.filter(|_| show_secondary_track) {
let secondary_track_paint = Paint::from_color(
evaluate_color_tween(
app,
slider_theme.disabled_secondary_active_track_color,
slider_theme.secondary_active_track_color,
enable_animation,
)
.expect("both secondary track colors are set")
.into(),
);
let secondary_track_segment = match text_direction {
TextDirection::Rtl => Rect::from_ltrb(
secondary_offset.dx(),
track_rect.top,
thumb_center.dx(),
track_rect.bottom,
),
TextDirection::Ltr => Rect::from_ltrb(
thumb_center.dx(),
track_rect.top,
secondary_offset.dx(),
track_rect.bottom,
),
};
if !secondary_track_segment.is_empty() {
context
.canvas()
.draw_rect(secondary_track_segment, &secondary_track_paint);
}
}
}
fn is_rounded(&self) -> bool {
BaseSliderTrackShape::is_rounded(self)
}
fn as_any(&self) -> &dyn Any {
self
}
fn eq_shape(&self, other: &dyn SliderTrackShape) -> bool {
other.as_any().downcast_ref::<Self>() == Some(self)
}
}
#[derive(Clone, Copy)]
struct TrackSegment {
draw: bool,
left: f64,
right: f64,
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct RoundedRectSliderTrackShape;
impl RoundedRectSliderTrackShape {
pub const fn new() -> RoundedRectSliderTrackShape {
RoundedRectSliderTrackShape
}
#[expect(clippy::too_many_arguments, reason = "Dart's parameters, in its order")]
pub fn paint(
&self,
app: &mut App,
context: &mut PaintingContext,
offset: Offset,
parent_box: AnyRenderBox,
slider_theme: &SliderThemeData,
enable_animation: AnyAnimation<f64>,
text_direction: TextDirection,
thumb_center: Offset,
secondary_offset: Option<Offset>,
is_discrete: bool,
is_enabled: bool,
additional_active_track_height: f64,
) {
debug_assert!(slider_theme.disabled_active_track_color.is_some());
debug_assert!(slider_theme.disabled_inactive_track_color.is_some());
debug_assert!(slider_theme.active_track_color.is_some());
debug_assert!(slider_theme.inactive_track_color.is_some());
debug_assert!(slider_theme.thumb_shape.is_some());
let Some(track_height) = slider_theme.track_height.filter(|height| *height > 0.0) else {
return;
};
let active_paint = Paint::from_color(
evaluate_color_tween(
app,
slider_theme.disabled_active_track_color,
slider_theme.active_track_color,
enable_animation,
)
.expect("both track colors are set")
.into(),
);
let inactive_paint = Paint::from_color(
evaluate_color_tween(
app,
slider_theme.disabled_inactive_track_color,
slider_theme.inactive_track_color,
enable_animation,
)
.expect("both track colors are set")
.into(),
);
let track_rect = SliderTrackShape::get_preferred_rect(
self,
app,
parent_box,
offset,
slider_theme,
Some(is_enabled),
Some(is_discrete),
);
let track_radius = Radius::circular(track_rect.height() / 2.0);
let active_track_radius =
Radius::circular((track_rect.height() + additional_active_track_height) / 2.0);
let is_ltr = text_direction == TextDirection::Ltr;
let half_track_height = track_height / 2.0;
let left_track = TrackSegment {
draw: thumb_center.dx() > track_rect.left + half_track_height,
left: track_rect.left,
right: thumb_center.dx() + half_track_height,
};
let right_track = TrackSegment {
draw: thumb_center.dx() < track_rect.right - half_track_height,
left: thumb_center.dx() - half_track_height,
right: track_rect.right,
};
let (inactive_track, active_track) = if is_ltr {
(right_track, left_track)
} else {
(left_track, right_track)
};
if inactive_track.draw {
draw_rrect(
context.canvas(),
RRect::from_ltrbr(
inactive_track.left,
track_rect.top,
inactive_track.right,
track_rect.bottom,
track_radius,
),
&inactive_paint,
);
}
if active_track.draw {
draw_rrect(
context.canvas(),
RRect::from_ltrbr(
active_track.left,
track_rect.top - (additional_active_track_height / 2.0),
active_track.right,
track_rect.bottom + (additional_active_track_height / 2.0),
active_track_radius,
),
&active_paint,
);
}
let show_secondary_track = secondary_offset.is_some_and(|secondary_offset| {
if is_ltr {
secondary_offset.dx() > thumb_center.dx()
} else {
secondary_offset.dx() < thumb_center.dx()
}
});
if let Some(secondary_offset) = secondary_offset.filter(|_| show_secondary_track) {
let secondary_track_paint = Paint::from_color(
evaluate_color_tween(
app,
slider_theme.disabled_secondary_active_track_color,
slider_theme.secondary_active_track_color,
enable_animation,
)
.expect("both secondary track colors are set")
.into(),
);
if is_ltr {
draw_rrect(
context.canvas(),
RRect::from_ltrb_and_corners(
thumb_center.dx(),
track_rect.top,
secondary_offset.dx(),
track_rect.bottom,
Radius::ZERO,
track_radius,
track_radius,
Radius::ZERO,
),
&secondary_track_paint,
);
} else {
draw_rrect(
context.canvas(),
RRect::from_ltrb_and_corners(
secondary_offset.dx(),
track_rect.top,
thumb_center.dx(),
track_rect.bottom,
track_radius,
Radius::ZERO,
Radius::ZERO,
track_radius,
),
&secondary_track_paint,
);
}
}
}
}
impl BaseSliderTrackShape for RoundedRectSliderTrackShape {}
impl SliderTrackShape for RoundedRectSliderTrackShape {
fn get_preferred_rect(
&self,
app: &App,
parent_box: AnyRenderBox,
offset: Offset,
slider_theme: &SliderThemeData,
is_enabled: Option<bool>,
is_discrete: Option<bool>,
) -> Rect {
BaseSliderTrackShape::get_preferred_rect(
self,
app,
parent_box,
offset,
slider_theme,
is_enabled,
is_discrete,
)
}
fn paint(
&self,
app: &mut App,
context: &mut PaintingContext,
offset: Offset,
parent_box: AnyRenderBox,
slider_theme: &SliderThemeData,
enable_animation: AnyAnimation<f64>,
thumb_center: Offset,
secondary_offset: Option<Offset>,
is_enabled: Option<bool>,
is_discrete: Option<bool>,
text_direction: TextDirection,
) {
RoundedRectSliderTrackShape::paint(
self,
app,
context,
offset,
parent_box,
slider_theme,
enable_animation,
text_direction,
thumb_center,
secondary_offset,
is_discrete.unwrap_or(false),
is_enabled.unwrap_or(false),
2.0,
);
}
fn is_rounded(&self) -> bool {
true
}
fn as_any(&self) -> &dyn Any {
self
}
fn eq_shape(&self, other: &dyn SliderTrackShape) -> bool {
other.as_any().downcast_ref::<Self>() == Some(self)
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct RoundSliderTickMarkShape {
pub tick_mark_radius: Option<f64>,
}
impl RoundSliderTickMarkShape {
pub const fn new() -> RoundSliderTickMarkShape {
RoundSliderTickMarkShape {
tick_mark_radius: None,
}
}
pub const fn tick_mark_radius(mut self, tick_mark_radius: f64) -> RoundSliderTickMarkShape {
self.tick_mark_radius = Some(tick_mark_radius);
self
}
}
impl SliderTickMarkShape for RoundSliderTickMarkShape {
fn get_preferred_size(&self, slider_theme: &SliderThemeData, _is_enabled: bool) -> Size {
debug_assert!(slider_theme.track_height.is_some());
Size::from_radius(self.tick_mark_radius.unwrap_or_else(|| {
slider_theme
.track_height
.expect("a slider theme with a track height")
/ 4.0
}))
}
fn paint(
&self,
app: &mut App,
context: &mut PaintingContext,
center: Offset,
_parent_box: AnyRenderBox,
slider_theme: &SliderThemeData,
enable_animation: AnyAnimation<f64>,
thumb_center: Offset,
is_enabled: bool,
text_direction: TextDirection,
) {
debug_assert!(slider_theme.disabled_active_tick_mark_color.is_some());
debug_assert!(slider_theme.disabled_inactive_tick_mark_color.is_some());
debug_assert!(slider_theme.active_tick_mark_color.is_some());
debug_assert!(slider_theme.inactive_tick_mark_color.is_some());
let x_offset = center.dx() - thumb_center.dx();
let (begin, end) = match text_direction {
TextDirection::Ltr if x_offset > 0.0 => (
slider_theme.disabled_inactive_tick_mark_color,
slider_theme.inactive_tick_mark_color,
),
TextDirection::Rtl if x_offset < 0.0 => (
slider_theme.disabled_inactive_tick_mark_color,
slider_theme.inactive_tick_mark_color,
),
TextDirection::Ltr | TextDirection::Rtl => (
slider_theme.disabled_active_tick_mark_color,
slider_theme.active_tick_mark_color,
),
};
let paint = Paint::from_color(
evaluate_color_tween(app, begin, end, enable_animation)
.expect("both tick mark colors are set")
.into(),
);
let tick_mark_radius = self.get_preferred_size(slider_theme, is_enabled).width() / 2.0;
if tick_mark_radius > 0.0 {
context
.canvas()
.draw_circle(center, tick_mark_radius as f32, &paint);
}
}
fn as_any(&self) -> &dyn Any {
self
}
fn eq_shape(&self, other: &dyn SliderTickMarkShape) -> bool {
other.as_any().downcast_ref::<Self>() == Some(self)
}
}
#[derive(Debug)]
struct EmptySliderTickMarkShape;
impl SliderTickMarkShape for EmptySliderTickMarkShape {
fn get_preferred_size(&self, _slider_theme: &SliderThemeData, _is_enabled: bool) -> Size {
Size::ZERO
}
fn paint(
&self,
_app: &mut App,
_context: &mut PaintingContext,
_center: Offset,
_parent_box: AnyRenderBox,
_slider_theme: &SliderThemeData,
_enable_animation: AnyAnimation<f64>,
_thumb_center: Offset,
_is_enabled: bool,
_text_direction: TextDirection,
) {
}
fn as_any(&self) -> &dyn Any {
self
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct RoundSliderThumbShape {
pub enabled_thumb_radius: f64,
pub disabled_thumb_radius: Option<f64>,
pub elevation: f64,
pub pressed_elevation: f64,
}
impl RoundSliderThumbShape {
pub const fn new() -> RoundSliderThumbShape {
RoundSliderThumbShape {
enabled_thumb_radius: 10.0,
disabled_thumb_radius: None,
elevation: 1.0,
pressed_elevation: 6.0,
}
}
pub const fn enabled_thumb_radius(
mut self,
enabled_thumb_radius: f64,
) -> RoundSliderThumbShape {
self.enabled_thumb_radius = enabled_thumb_radius;
self
}
pub const fn disabled_thumb_radius(
mut self,
disabled_thumb_radius: f64,
) -> RoundSliderThumbShape {
self.disabled_thumb_radius = Some(disabled_thumb_radius);
self
}
pub const fn elevation(mut self, elevation: f64) -> RoundSliderThumbShape {
self.elevation = elevation;
self
}
pub const fn pressed_elevation(mut self, pressed_elevation: f64) -> RoundSliderThumbShape {
self.pressed_elevation = pressed_elevation;
self
}
fn effective_disabled_thumb_radius(&self) -> f64 {
self.disabled_thumb_radius
.unwrap_or(self.enabled_thumb_radius)
}
}
impl Default for RoundSliderThumbShape {
fn default() -> RoundSliderThumbShape {
RoundSliderThumbShape::new()
}
}
impl SliderComponentShape for RoundSliderThumbShape {
fn get_preferred_size(&self, is_enabled: bool, _is_discrete: bool) -> Size {
Size::from_radius(if is_enabled {
self.enabled_thumb_radius
} else {
self.effective_disabled_thumb_radius()
})
}
fn paint(
&self,
app: &mut App,
context: &mut PaintingContext,
center: Offset,
activation_animation: AnyAnimation<f64>,
enable_animation: AnyAnimation<f64>,
_is_discrete: bool,
_label_painter: &mut TextPainter,
parent_box: AnyRenderBox,
slider_theme: &SliderThemeData,
_text_direction: TextDirection,
_value: f64,
_text_scale_factor: f64,
_size_with_overflow: Size,
) {
debug_assert!(slider_theme.disabled_thumb_color.is_some());
debug_assert!(slider_theme.thumb_color.is_some());
let color = evaluate_color_tween(
app,
slider_theme.disabled_thumb_color,
slider_theme.thumb_color,
enable_animation,
)
.expect("both thumb colors are set");
let radius = evaluate_tween(
app,
self.effective_disabled_thumb_radius(),
self.enabled_thumb_radius,
enable_animation,
);
let evaluated_elevation = evaluate_tween(
app,
self.elevation,
self.pressed_elevation,
activation_animation,
);
let mut path = PathBuilder::new();
path.arc(center, radius as f32, 0.0, std::f32::consts::TAU);
let path = Path::new(path.build());
draw_shadow(
app,
context.canvas(),
parent_box,
&path,
Colors::BLACK,
evaluated_elevation,
true,
);
context
.canvas()
.draw_circle(center, radius as f32, &Paint::from_color(color.into()));
}
fn as_any(&self) -> &dyn Any {
self
}
fn eq_shape(&self, other: &dyn SliderComponentShape) -> bool {
other.as_any().downcast_ref::<Self>() == Some(self)
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct DropSliderValueIndicatorShape;
impl DropSliderValueIndicatorShape {
const PATH_PAINTER: DropSliderValueIndicatorPathPainter = DropSliderValueIndicatorPathPainter;
pub const fn new() -> DropSliderValueIndicatorShape {
DropSliderValueIndicatorShape
}
pub fn get_preferred_size(
&self,
_is_enabled: bool,
_is_discrete: bool,
label_painter: Option<&TextPainter>,
text_scale_factor: Option<f64>,
) -> Size {
debug_assert!(label_painter.is_some());
debug_assert!(text_scale_factor.is_some_and(|factor| factor >= 0.0));
Self::PATH_PAINTER.get_preferred_size(
label_painter.expect("a label painter"),
text_scale_factor.expect("a text scale factor"),
)
}
}
impl SliderComponentShape for DropSliderValueIndicatorShape {
fn get_preferred_size(&self, is_enabled: bool, is_discrete: bool) -> Size {
DropSliderValueIndicatorShape::get_preferred_size(self, is_enabled, is_discrete, None, None)
}
fn paint(
&self,
app: &mut App,
context: &mut PaintingContext,
center: Offset,
activation_animation: AnyAnimation<f64>,
_enable_animation: AnyAnimation<f64>,
_is_discrete: bool,
label_painter: &mut TextPainter,
parent_box: AnyRenderBox,
slider_theme: &SliderThemeData,
_text_direction: TextDirection,
_value: f64,
text_scale_factor: f64,
size_with_overflow: Size,
) {
let scale = activation_animation.value(app);
Self::PATH_PAINTER.paint(
app,
parent_box,
context.canvas(),
center,
scale,
label_painter,
text_scale_factor,
size_with_overflow,
slider_theme
.value_indicator_color
.expect("a slider theme with a value indicator color"),
slider_theme.value_indicator_stroke_color,
);
}
fn as_any(&self) -> &dyn Any {
self
}
fn eq_shape(&self, other: &dyn SliderComponentShape) -> bool {
other.as_any().downcast_ref::<Self>() == Some(self)
}
}
struct DropSliderValueIndicatorPathPainter;
impl DropSliderValueIndicatorPathPainter {
const TRIANGLE_HEIGHT: f64 = 10.0;
const LABEL_PADDING: f64 = 8.0;
const PREFERRED_HEIGHT: f64 = 32.0;
const MIN_LABEL_WIDTH: f64 = 20.0;
const MIN_RECT_HEIGHT: f64 = 28.0;
const RECT_Y_OFFSET: f64 = 6.0;
const BOTTOM_TIP_Y_OFFSET: f64 = 16.0;
const PREFERRED_HALF_HEIGHT: f64 = Self::PREFERRED_HEIGHT / 2.0;
const UPPER_RECT_RADIUS: f64 = 4.0;
fn get_preferred_size(&self, label_painter: &TextPainter, text_scale_factor: f64) -> Size {
let width = Self::MIN_LABEL_WIDTH.max(label_painter.width())
+ Self::LABEL_PADDING * 2.0 * text_scale_factor;
Size::new(width, Self::PREFERRED_HEIGHT * text_scale_factor)
}
#[expect(clippy::too_many_arguments, reason = "Dart's parameters, in its order")]
fn get_horizontal_shift(
&self,
app: &App,
parent_box: AnyRenderBox,
center: Offset,
label_painter: &TextPainter,
text_scale_factor: f64,
size_with_overflow: Size,
scale: f64,
) -> f64 {
debug_assert!(!size_with_overflow.is_empty());
const EDGE_PADDING: f64 = 8.0;
let rectangle_width = self.upper_rectangle_width(label_painter, scale);
let global_center = parent_box.local_to_global(app, center, None);
let overflow_left = 0.0_f64.max(rectangle_width / 2.0 - global_center.dx() + EDGE_PADDING);
let overflow_right = 0.0_f64.max(
rectangle_width / 2.0
- (size_with_overflow.width() - global_center.dx() - EDGE_PADDING),
);
if rectangle_width < size_with_overflow.width() {
overflow_left - overflow_right
} else if overflow_left - overflow_right > 0.0 {
overflow_left - (EDGE_PADDING * text_scale_factor)
} else {
-overflow_right + (EDGE_PADDING * text_scale_factor)
}
}
fn upper_rectangle_width(&self, label_painter: &TextPainter, scale: f64) -> f64 {
let unscaled_width = Self::MIN_LABEL_WIDTH.max(label_painter.width()) + Self::LABEL_PADDING;
unscaled_width * scale
}
fn adjust_border_radius(&self, rect: Rect) -> BorderRadius {
const RECTNESS: f64 = 0.0;
BorderRadius::lerp(
Some(BorderRadius::all(Radius::circular(Self::UPPER_RECT_RADIUS))),
Some(BorderRadius::all(Radius::circular(
rect.shortest_side() / 2.0,
))),
1.0 - RECTNESS,
)
.expect("both radii are set")
}
#[expect(clippy::too_many_arguments, reason = "Dart's parameters, in its order")]
fn paint(
&self,
app: &mut App,
parent_box: AnyRenderBox,
canvas: &mut Canvas,
center: Offset,
scale: f64,
label_painter: &mut TextPainter,
text_scale_factor: f64,
size_with_overflow: Size,
background_paint_color: Color,
stroke_paint_color: Option<Color>,
) {
if scale == 0.0 {
return;
}
debug_assert!(!size_with_overflow.is_empty());
let rectangle_width = self.upper_rectangle_width(label_painter, scale);
let horizontal_shift = self.get_horizontal_shift(
app,
parent_box,
center,
label_painter,
text_scale_factor,
size_with_overflow,
scale,
);
let upper_rect = Rect::from_ltwh(
-rectangle_width / 2.0 + horizontal_shift,
-Self::RECT_Y_OFFSET - Self::MIN_RECT_HEIGHT,
rectangle_width,
Self::MIN_RECT_HEIGHT,
);
let fill_paint = Paint::from_color(background_paint_color.into());
canvas.save();
canvas.translate(
center.dx() as f32,
(center.dy() - Self::BOTTOM_TIP_Y_OFFSET) as f32,
);
canvas.scale(scale as f32, scale as f32);
let adjusted_border_radius = self.adjust_border_radius(upper_rect);
let border_rect = adjusted_border_radius
.resolve(label_painter.text_direction())
.to_rrect(upper_rect);
let mut triangle_path = PathBuilder::new();
triangle_path.move_to((0.0, 0.0));
triangle_path
.line_to((-Self::TRIANGLE_HEIGHT as f32, -Self::TRIANGLE_HEIGHT as f32))
.line_to((Self::TRIANGLE_HEIGHT as f32, -Self::TRIANGLE_HEIGHT as f32))
.close();
triangle_path.rrect_radii_elliptical(
border_rect.outer_rect(),
rrect_radii_elliptical(border_rect),
);
let triangle_path = triangle_path.build();
if let Some(stroke_paint_color) = stroke_paint_color {
let stroke_paint = Paint {
color: stroke_paint_color.into(),
style: PaintStyle::Stroke(Stroke::new(1.0)),
..Paint::default()
};
canvas.draw_path(&triangle_path, FillRule::NonZero, &stroke_paint);
}
canvas.draw_path(&triangle_path, FillRule::NonZero, &fill_paint);
let bottom_tip_to_upper_rect_translate_y =
-Self::PREFERRED_HALF_HEIGHT / 2.0 - upper_rect.height();
canvas.translate(0.0, bottom_tip_to_upper_rect_translate_y as f32);
let box_center = Offset::new(horizontal_shift, upper_rect.height() / 1.75);
let half_label_painter_offset =
Offset::new(label_painter.width() / 2.0, label_painter.height() / 2.0);
let label_offset = box_center - half_label_painter_offset;
let fonts = PaintingBinding::instance(app).fonts(app);
label_painter.paint(app.get_mut(fonts), canvas, label_offset);
canvas.restore();
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct HandleThumbShape;
impl HandleThumbShape {
pub const fn new() -> HandleThumbShape {
HandleThumbShape
}
}
impl SliderComponentShape for HandleThumbShape {
fn get_preferred_size(&self, _is_enabled: bool, _is_discrete: bool) -> Size {
Size::new(4.0, 44.0)
}
fn paint(
&self,
app: &mut App,
context: &mut PaintingContext,
center: Offset,
_activation_animation: AnyAnimation<f64>,
enable_animation: AnyAnimation<f64>,
_is_discrete: bool,
_label_painter: &mut TextPainter,
_parent_box: AnyRenderBox,
slider_theme: &SliderThemeData,
_text_direction: TextDirection,
_value: f64,
_text_scale_factor: f64,
_size_with_overflow: Size,
) {
debug_assert!(slider_theme.disabled_thumb_color.is_some());
debug_assert!(slider_theme.thumb_color.is_some());
debug_assert!(slider_theme.thumb_size.is_some());
let color = evaluate_color_tween(
app,
slider_theme.disabled_thumb_color,
slider_theme.thumb_color,
enable_animation,
)
.expect("both thumb colors are set");
let thumb_size = slider_theme
.thumb_size
.as_ref()
.expect("a slider theme with a thumb size")
.resolve(&WidgetStates::new())
.expect("a thumb size for no states"); let rrect = RRect::from_rect_and_radius(
Rect::from_center(center, thumb_size.width(), thumb_size.height()),
Radius::circular(thumb_size.shortest_side() / 2.0),
);
draw_rrect(context.canvas(), rrect, &Paint::from_color(color.into()));
}
fn as_any(&self) -> &dyn Any {
self
}
fn eq_shape(&self, other: &dyn SliderComponentShape) -> bool {
other.as_any().downcast_ref::<Self>() == Some(self)
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct GappedSliderTrackShape;
impl GappedSliderTrackShape {
pub const fn new() -> GappedSliderTrackShape {
GappedSliderTrackShape
}
#[expect(clippy::too_many_arguments, reason = "Dart's parameters, in its order")]
pub fn paint(
&self,
app: &mut App,
context: &mut PaintingContext,
offset: Offset,
parent_box: AnyRenderBox,
slider_theme: &SliderThemeData,
enable_animation: AnyAnimation<f64>,
text_direction: TextDirection,
thumb_center: Offset,
secondary_offset: Option<Offset>,
is_discrete: bool,
is_enabled: bool,
_additional_active_track_height: f64,
) {
debug_assert!(slider_theme.disabled_active_track_color.is_some());
debug_assert!(slider_theme.disabled_inactive_track_color.is_some());
debug_assert!(slider_theme.active_track_color.is_some());
debug_assert!(slider_theme.inactive_track_color.is_some());
debug_assert!(slider_theme.thumb_shape.is_some());
debug_assert!(slider_theme.track_gap.is_some());
debug_assert!(
slider_theme
.track_gap
.is_some_and(|gap| !gap.is_sign_negative())
);
let Some(track_height) = slider_theme.track_height.filter(|height| *height > 0.0) else {
return;
};
let active_paint = Paint::from_color(
evaluate_color_tween(
app,
slider_theme.disabled_active_track_color,
slider_theme.active_track_color,
enable_animation,
)
.expect("both track colors are set")
.into(),
);
let inactive_paint = Paint::from_color(
evaluate_color_tween(
app,
slider_theme.disabled_inactive_track_color,
slider_theme.inactive_track_color,
enable_animation,
)
.expect("both track colors are set")
.into(),
);
let (left_track_paint, right_track_paint) = match text_direction {
TextDirection::Ltr => (&active_paint, &inactive_paint),
TextDirection::Rtl => (&inactive_paint, &active_paint),
};
let track_gap = slider_theme
.track_gap
.expect("a slider theme with a track gap");
let track_rect = SliderTrackShape::get_preferred_rect(
self,
app,
parent_box,
offset,
slider_theme,
Some(is_enabled),
Some(is_discrete),
);
let track_corner_radius = Radius::circular(track_rect.shortest_side() / 2.0);
const TRACK_INSIDE_CORNER_RADIUS: Radius = Radius::circular(2.0);
let track_rrect = RRect::from_rect_and_corners(
track_rect,
track_corner_radius,
track_corner_radius,
track_corner_radius,
track_corner_radius,
);
let left_rrect = RRect::from_ltrb_and_corners(
track_rect.left,
track_rect.top,
track_rect.left.max(thumb_center.dx() - track_gap),
track_rect.bottom,
track_corner_radius,
TRACK_INSIDE_CORNER_RADIUS,
TRACK_INSIDE_CORNER_RADIUS,
track_corner_radius,
);
let right_rrect = RRect::from_ltrb_and_corners(
thumb_center.dx() + track_gap,
track_rect.top,
track_rect.right,
track_rect.bottom,
TRACK_INSIDE_CORNER_RADIUS,
track_corner_radius,
track_corner_radius,
TRACK_INSIDE_CORNER_RADIUS,
);
let canvas = context.canvas();
canvas.save();
canvas.clip_rrect_radii_elliptical(
track_rrect.outer_rect(),
rrect_radii_elliptical(track_rrect),
ClipOp::Intersect,
true,
);
let draw_left_track = thumb_center.dx() > (left_rrect.left + (track_height / 2.0));
let draw_right_track = thumb_center.dx() < (right_rrect.right - (track_height / 2.0));
if draw_left_track {
draw_rrect(canvas, left_rrect, left_track_paint);
}
if draw_right_track {
draw_rrect(canvas, right_rrect, right_track_paint);
}
let is_ltr = text_direction == TextDirection::Ltr;
let show_secondary_track = secondary_offset.is_some_and(|secondary_offset| match is_ltr {
true => secondary_offset.dx() > thumb_center.dx() + track_gap,
false => secondary_offset.dx() < thumb_center.dx() - track_gap,
});
if let Some(secondary_offset) = secondary_offset.filter(|_| show_secondary_track) {
let secondary_track_paint = Paint::from_color(
evaluate_color_tween(
app,
slider_theme.disabled_secondary_active_track_color,
slider_theme.secondary_active_track_color,
enable_animation,
)
.expect("both secondary track colors are set")
.into(),
);
let canvas = context.canvas();
if is_ltr {
draw_rrect(
canvas,
RRect::from_ltrb_and_corners(
thumb_center.dx() + track_gap,
track_rect.top,
secondary_offset.dx(),
track_rect.bottom,
TRACK_INSIDE_CORNER_RADIUS,
track_corner_radius,
track_corner_radius,
TRACK_INSIDE_CORNER_RADIUS,
),
&secondary_track_paint,
);
} else {
draw_rrect(
canvas,
RRect::from_ltrb_and_corners(
secondary_offset.dx(),
track_rect.top,
thumb_center.dx() - track_gap,
track_rect.bottom,
track_corner_radius,
TRACK_INSIDE_CORNER_RADIUS,
TRACK_INSIDE_CORNER_RADIUS,
track_corner_radius,
),
&secondary_track_paint,
);
}
}
let canvas = context.canvas();
canvas.restore();
const STOP_INDICATOR_RADIUS: f64 = 2.0;
let stop_indicator_trailing_space = track_height / 2.0;
let stop_indicator_offset = Offset::new(
if text_direction == TextDirection::Ltr {
track_rect.center_right().dx() - stop_indicator_trailing_space
} else {
track_rect.center_left().dx() + stop_indicator_trailing_space
},
track_rect.center().dy(),
);
let show_stop_indicator = if text_direction == TextDirection::Ltr {
thumb_center.dx() < stop_indicator_offset.dx()
} else {
thumb_center.dx() > stop_indicator_offset.dx()
};
if show_stop_indicator && !is_discrete {
let stop_indicator_rect =
Rect::from_circle(stop_indicator_offset, STOP_INDICATOR_RADIUS);
canvas.draw_circle(
stop_indicator_rect.center(),
STOP_INDICATOR_RADIUS as f32,
&active_paint,
);
}
}
}
impl BaseSliderTrackShape for GappedSliderTrackShape {}
impl SliderTrackShape for GappedSliderTrackShape {
fn get_preferred_rect(
&self,
app: &App,
parent_box: AnyRenderBox,
offset: Offset,
slider_theme: &SliderThemeData,
is_enabled: Option<bool>,
is_discrete: Option<bool>,
) -> Rect {
BaseSliderTrackShape::get_preferred_rect(
self,
app,
parent_box,
offset,
slider_theme,
is_enabled,
is_discrete,
)
}
fn paint(
&self,
app: &mut App,
context: &mut PaintingContext,
offset: Offset,
parent_box: AnyRenderBox,
slider_theme: &SliderThemeData,
enable_animation: AnyAnimation<f64>,
thumb_center: Offset,
secondary_offset: Option<Offset>,
is_enabled: Option<bool>,
is_discrete: Option<bool>,
text_direction: TextDirection,
) {
GappedSliderTrackShape::paint(
self,
app,
context,
offset,
parent_box,
slider_theme,
enable_animation,
text_direction,
thumb_center,
secondary_offset,
is_discrete.unwrap_or(false),
is_enabled.unwrap_or(false),
2.0,
);
}
fn is_rounded(&self) -> bool {
true
}
fn as_any(&self) -> &dyn Any {
self
}
fn eq_shape(&self, other: &dyn SliderTrackShape) -> bool {
other.as_any().downcast_ref::<Self>() == Some(self)
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct RoundedRectSliderValueIndicatorShape;
impl RoundedRectSliderValueIndicatorShape {
const PATH_PAINTER: RoundedRectSliderValueIndicatorPathPainter =
RoundedRectSliderValueIndicatorPathPainter;
pub const fn new() -> RoundedRectSliderValueIndicatorShape {
RoundedRectSliderValueIndicatorShape
}
pub fn get_preferred_size(
&self,
_is_enabled: bool,
_is_discrete: bool,
label_painter: Option<&TextPainter>,
text_scale_factor: Option<f64>,
) -> Size {
debug_assert!(label_painter.is_some());
debug_assert!(text_scale_factor.is_some_and(|factor| factor >= 0.0));
Self::PATH_PAINTER.get_preferred_size(
label_painter.expect("a label painter"),
text_scale_factor.expect("a text scale factor"),
)
}
}
impl SliderComponentShape for RoundedRectSliderValueIndicatorShape {
fn get_preferred_size(&self, is_enabled: bool, is_discrete: bool) -> Size {
RoundedRectSliderValueIndicatorShape::get_preferred_size(
self,
is_enabled,
is_discrete,
None,
None,
)
}
fn paint(
&self,
app: &mut App,
context: &mut PaintingContext,
center: Offset,
activation_animation: AnyAnimation<f64>,
_enable_animation: AnyAnimation<f64>,
_is_discrete: bool,
label_painter: &mut TextPainter,
parent_box: AnyRenderBox,
slider_theme: &SliderThemeData,
_text_direction: TextDirection,
_value: f64,
text_scale_factor: f64,
size_with_overflow: Size,
) {
let scale = activation_animation.value(app);
Self::PATH_PAINTER.paint(
app,
parent_box,
context.canvas(),
center,
scale,
label_painter,
text_scale_factor,
size_with_overflow,
slider_theme
.value_indicator_color
.expect("a slider theme with a value indicator color"),
slider_theme.value_indicator_stroke_color,
);
}
fn as_any(&self) -> &dyn Any {
self
}
fn eq_shape(&self, other: &dyn SliderComponentShape) -> bool {
other.as_any().downcast_ref::<Self>() == Some(self)
}
}
struct RoundedRectSliderValueIndicatorPathPainter;
impl RoundedRectSliderValueIndicatorPathPainter {
const LABEL_PADDING: f64 = 10.0;
const PREFERRED_HEIGHT: f64 = 32.0;
const MIN_LABEL_WIDTH: f64 = 16.0;
const RECT_Y_OFFSET: f64 = 10.0;
const BOTTOM_TIP_Y_OFFSET: f64 = 16.0;
const PREFERRED_HALF_HEIGHT: f64 = Self::PREFERRED_HEIGHT / 2.0;
fn get_preferred_size(&self, label_painter: &TextPainter, text_scale_factor: f64) -> Size {
let width = Self::MIN_LABEL_WIDTH.max(label_painter.width())
+ (Self::LABEL_PADDING * 2.0) * text_scale_factor;
Size::new(width, Self::PREFERRED_HEIGHT * text_scale_factor)
}
#[expect(clippy::too_many_arguments, reason = "Dart's parameters, in its order")]
fn get_horizontal_shift(
&self,
app: &App,
parent_box: AnyRenderBox,
center: Offset,
label_painter: &TextPainter,
text_scale_factor: f64,
size_with_overflow: Size,
scale: f64,
) -> f64 {
debug_assert!(!size_with_overflow.is_empty());
const EDGE_PADDING: f64 = 8.0;
let rectangle_width = self.upper_rectangle_width(label_painter, scale);
let global_center = parent_box.local_to_global(app, center, None);
let overflow_left = 0.0_f64.max(rectangle_width / 2.0 - global_center.dx() + EDGE_PADDING);
let overflow_right = 0.0_f64.max(
rectangle_width / 2.0
- (size_with_overflow.width() - global_center.dx() - EDGE_PADDING),
);
if rectangle_width < size_with_overflow.width() {
overflow_left - overflow_right
} else if overflow_left - overflow_right > 0.0 {
overflow_left - (EDGE_PADDING * text_scale_factor)
} else {
-overflow_right + (EDGE_PADDING * text_scale_factor)
}
}
fn upper_rectangle_width(&self, label_painter: &TextPainter, scale: f64) -> f64 {
let unscaled_width =
Self::MIN_LABEL_WIDTH.max(label_painter.width()) + (Self::LABEL_PADDING * 2.0);
unscaled_width * scale
}
#[expect(clippy::too_many_arguments, reason = "Dart's parameters, in its order")]
fn paint(
&self,
app: &mut App,
parent_box: AnyRenderBox,
canvas: &mut Canvas,
center: Offset,
scale: f64,
label_painter: &mut TextPainter,
text_scale_factor: f64,
size_with_overflow: Size,
background_paint_color: Color,
stroke_paint_color: Option<Color>,
) {
if scale == 0.0 {
return;
}
debug_assert!(!size_with_overflow.is_empty());
let rectangle_width = self.upper_rectangle_width(label_painter, scale);
let horizontal_shift = self.get_horizontal_shift(
app,
parent_box,
center,
label_painter,
text_scale_factor,
size_with_overflow,
scale,
);
let upper_rect = Rect::from_ltwh(
-rectangle_width / 2.0 + horizontal_shift,
-Self::RECT_Y_OFFSET - Self::PREFERRED_HEIGHT,
rectangle_width,
Self::PREFERRED_HEIGHT,
);
let fill_paint = Paint::from_color(background_paint_color.into());
canvas.save();
canvas.translate(
center.dx() as f32,
(center.dy() - Self::BOTTOM_TIP_Y_OFFSET) as f32,
);
canvas.scale(scale as f32, scale as f32);
let rrect =
RRect::from_rect_and_radius(upper_rect, Radius::circular(upper_rect.height() / 2.0));
if let Some(stroke_paint_color) = stroke_paint_color {
let stroke_paint = Paint {
color: stroke_paint_color.into(),
style: PaintStyle::Stroke(Stroke::new(1.0)),
..Paint::default()
};
draw_rrect(canvas, rrect, &stroke_paint);
}
draw_rrect(canvas, rrect, &fill_paint);
let bottom_tip_to_upper_rect_translate_y =
-Self::PREFERRED_HALF_HEIGHT / 2.0 - upper_rect.height();
canvas.translate(0.0, bottom_tip_to_upper_rect_translate_y as f32);
let box_center = Offset::new(horizontal_shift, upper_rect.height() / 2.3);
let half_label_painter_offset =
Offset::new(label_painter.width() / 2.0, label_painter.height() / 2.0);
let label_offset = box_center - half_label_painter_offset;
let fonts = PaintingBinding::instance(app).fonts(app);
label_painter.paint(app.get_mut(fonts), canvas, label_offset);
canvas.restore();
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::slider_value_indicator_shape::{RoundSliderOverlayShape, SliderComponentShapeRef};
#[test]
fn track_shape_is_rounded_defaults() {
assert!(!SliderTrackShape::is_rounded(
&RectangularSliderTrackShape::new()
));
assert!(SliderTrackShape::is_rounded(
&RoundedRectSliderTrackShape::new()
));
assert!(SliderTrackShape::is_rounded(&GappedSliderTrackShape::new()));
}
#[test]
fn round_slider_thumb_shape_prefers_its_enabled_or_disabled_radius() {
let shape = RoundSliderThumbShape::new();
assert_eq!(shape.get_preferred_size(true, false), Size::new(20.0, 20.0));
assert_eq!(
shape.get_preferred_size(false, false),
Size::new(20.0, 20.0)
);
let shape = shape.enabled_thumb_radius(7.0).disabled_thumb_radius(4.0);
assert_eq!(shape.get_preferred_size(true, false), Size::new(14.0, 14.0));
assert_eq!(shape.get_preferred_size(false, false), Size::new(8.0, 8.0));
}
#[test]
fn handle_thumb_shape_prefers_four_by_forty_four() {
assert_eq!(
HandleThumbShape::new().get_preferred_size(true, true),
Size::new(4.0, 44.0)
);
}
#[test]
fn round_tick_mark_defaults_to_a_quarter_of_the_track_height() {
let theme = SliderThemeData::new().track_height(8.0);
assert_eq!(
RoundSliderTickMarkShape::new().get_preferred_size(&theme, true),
Size::new(4.0, 4.0)
);
assert_eq!(
RoundSliderTickMarkShape::new()
.tick_mark_radius(5.0)
.get_preferred_size(&theme, true),
Size::new(10.0, 10.0)
);
assert_eq!(
<dyn SliderTickMarkShape>::no_tick_mark().get_preferred_size(&theme, true),
Size::ZERO
);
}
#[test]
fn built_in_shapes_compare_by_value_and_the_empty_one_by_identity() {
let a: SliderTrackShapeRef = Rc::new(RoundedRectSliderTrackShape::new());
let b: SliderTrackShapeRef = Rc::new(RoundedRectSliderTrackShape::new());
let c: SliderTrackShapeRef = Rc::new(GappedSliderTrackShape::new());
assert!(*a == *b);
assert!(*a != *c);
let thumb: SliderComponentShapeRef =
Rc::new(RoundSliderThumbShape::new().enabled_thumb_radius(7.0));
let same: SliderComponentShapeRef =
Rc::new(RoundSliderThumbShape::new().enabled_thumb_radius(7.0));
let other: SliderComponentShapeRef = Rc::new(RoundSliderThumbShape::new());
let overlay: SliderComponentShapeRef = Rc::new(RoundSliderOverlayShape::new());
assert!(*thumb == *same);
assert!(*thumb != *other);
assert!(*thumb != *overlay);
let tick: SliderTickMarkShapeRef = Rc::new(RoundSliderTickMarkShape::new());
let same_tick: SliderTickMarkShapeRef = Rc::new(RoundSliderTickMarkShape::new());
assert!(*tick == *same_tick);
assert!(Rc::ptr_eq(
&<dyn SliderTickMarkShape>::no_tick_mark(),
&<dyn SliderTickMarkShape>::no_tick_mark()
));
assert!(*tick != *<dyn SliderTickMarkShape>::no_tick_mark());
}
}