fix(color picker): avoid 0 in color picker slider value
This commit is contained in:
parent
58902bf637
commit
7d417c20d1
1 changed files with 152 additions and 225 deletions
|
|
@ -289,10 +289,52 @@ where
|
|||
copy_to_clipboard_label: T,
|
||||
copied_to_clipboard_label: T,
|
||||
) -> ColorPicker<'a, Message> {
|
||||
fn rail_backgrounds(hue: f32) -> (Background, Background) {
|
||||
let pivot = hue * 7.0 / 360.;
|
||||
|
||||
let low_end = pivot.floor() as usize;
|
||||
let high_start = pivot.ceil() as usize;
|
||||
let pivot_color = palette::Hsv::new_srgb(RgbHue::new(hue), 1.0, 1.0);
|
||||
let low_range = HSV_RAINBOW[0..=low_end]
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, color)| ColorStop {
|
||||
color: *color,
|
||||
offset: i as f32 / pivot.max(0.0001),
|
||||
})
|
||||
.chain(iter::once(ColorStop {
|
||||
color: iced::Color::from(palette::Srgba::from_color(pivot_color)),
|
||||
offset: 1.,
|
||||
}))
|
||||
.collect::<Vec<_>>();
|
||||
let high_range = iter::once(ColorStop {
|
||||
color: iced::Color::from(palette::Srgba::from_color(pivot_color)),
|
||||
offset: 0.,
|
||||
})
|
||||
.chain(
|
||||
HSV_RAINBOW[high_start..]
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, color)| ColorStop {
|
||||
color: *color,
|
||||
offset: (i as f32 + (1. - pivot.fract())) / (7. - pivot).max(0.0001),
|
||||
}),
|
||||
)
|
||||
.collect::<Vec<_>>();
|
||||
(
|
||||
Background::Gradient(iced::Gradient::Linear(
|
||||
Linear::new(Radians(90.0)).add_stops(low_range),
|
||||
)),
|
||||
Background::Gradient(iced::Gradient::Linear(
|
||||
Linear::new(Radians(90.0)).add_stops(high_range),
|
||||
)),
|
||||
)
|
||||
}
|
||||
|
||||
let on_update = self.on_update;
|
||||
let spacing = THEME.lock().unwrap().cosmic().spacing;
|
||||
let mut inner =
|
||||
column![
|
||||
|
||||
let mut inner = column![
|
||||
// segmented buttons
|
||||
segmented_control::horizontal(self.model)
|
||||
.on_activate(Box::new(move |e| on_update(
|
||||
|
|
@ -306,7 +348,7 @@ where
|
|||
.width(self.width)
|
||||
.height(self.height),
|
||||
slider(
|
||||
0.0..=359.99,
|
||||
0.001..=359.99,
|
||||
self.active_color.hue.into_positive_degrees(),
|
||||
move |v| {
|
||||
let mut new = self.active_color;
|
||||
|
|
@ -320,47 +362,8 @@ where
|
|||
let cosmic = t.cosmic();
|
||||
let mut a =
|
||||
slider::Catalog::style(t, &Slider::default(), slider::Status::Active);
|
||||
|
||||
let hue = self.active_color.hue.into_positive_degrees();
|
||||
let pivot = hue * 7.0 / 360.;
|
||||
|
||||
let low_end = pivot.floor() as usize;
|
||||
let high_start = pivot.ceil() as usize;
|
||||
let pivot_color = palette::Hsv::new_srgb(RgbHue::new(hue), 1.0, 1.0);
|
||||
let low_range = HSV_RAINBOW[0..=low_end]
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, color)| ColorStop {
|
||||
color: *color,
|
||||
offset: i as f32 / pivot.max(0.0001),
|
||||
})
|
||||
.chain(iter::once(ColorStop {
|
||||
color: iced::Color::from(palette::Srgba::from_color(pivot_color)),
|
||||
offset: 1.,
|
||||
}))
|
||||
.collect::<Vec<_>>();
|
||||
let high_range =
|
||||
iter::once(ColorStop {
|
||||
color: iced::Color::from(palette::Srgba::from_color(pivot_color)),
|
||||
offset: 0.,
|
||||
})
|
||||
.chain(HSV_RAINBOW[high_start..].iter().enumerate().map(
|
||||
|(i, color)| ColorStop {
|
||||
color: *color,
|
||||
offset: (i as f32 + (1. - pivot.fract()))
|
||||
/ (7. - pivot).max(0.0001),
|
||||
},
|
||||
))
|
||||
.collect::<Vec<_>>();
|
||||
a.rail.backgrounds = (
|
||||
Background::Gradient(iced::Gradient::Linear(
|
||||
Linear::new(Radians(90.0)).add_stops(low_range),
|
||||
)),
|
||||
Background::Gradient(iced::Gradient::Linear(
|
||||
Linear::new(Radians(90.0)).add_stops(high_range),
|
||||
)),
|
||||
);
|
||||
|
||||
a.rail.backgrounds = rail_backgrounds(hue);
|
||||
a.rail.width = 8.0;
|
||||
a.handle.background = Color::TRANSPARENT.into();
|
||||
a.handle.shape = HandleShape::Circle { radius: 8.0 };
|
||||
|
|
@ -373,44 +376,7 @@ where
|
|||
let mut a =
|
||||
slider::Catalog::style(t, &Slider::default(), slider::Status::Active);
|
||||
let hue = self.active_color.hue.into_positive_degrees();
|
||||
let pivot = hue * 7.0 / 360.;
|
||||
|
||||
let low_end = pivot.floor() as usize;
|
||||
let high_start = pivot.ceil() as usize;
|
||||
let pivot_color = palette::Hsv::new_srgb(RgbHue::new(hue), 1.0, 1.0);
|
||||
let low_range = HSV_RAINBOW[0..=low_end]
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, color)| ColorStop {
|
||||
color: *color,
|
||||
offset: i as f32 / pivot.max(0.0001),
|
||||
})
|
||||
.chain(iter::once(ColorStop {
|
||||
color: iced::Color::from(palette::Srgba::from_color(pivot_color)),
|
||||
offset: 1.,
|
||||
}))
|
||||
.collect::<Vec<_>>();
|
||||
let high_range =
|
||||
iter::once(ColorStop {
|
||||
color: iced::Color::from(palette::Srgba::from_color(pivot_color)),
|
||||
offset: 0.,
|
||||
})
|
||||
.chain(HSV_RAINBOW[high_start..].iter().enumerate().map(
|
||||
|(i, color)| ColorStop {
|
||||
color: *color,
|
||||
offset: (i as f32 + (1. - pivot.fract()))
|
||||
/ (7. - pivot).max(0.0001),
|
||||
},
|
||||
))
|
||||
.collect::<Vec<_>>();
|
||||
a.rail.backgrounds = (
|
||||
Background::Gradient(iced::Gradient::Linear(
|
||||
Linear::new(Radians(90.0)).add_stops(low_range),
|
||||
)),
|
||||
Background::Gradient(iced::Gradient::Linear(
|
||||
Linear::new(Radians(90.0)).add_stops(high_range),
|
||||
)),
|
||||
);
|
||||
a.rail.backgrounds = rail_backgrounds(hue);
|
||||
a.rail.width = 8.0;
|
||||
a.handle.background = Color::TRANSPARENT.into();
|
||||
a.handle.shape = HandleShape::Circle { radius: 8.0 };
|
||||
|
|
@ -423,44 +389,7 @@ where
|
|||
let mut a =
|
||||
slider::Catalog::style(t, &Slider::default(), slider::Status::Active);
|
||||
let hue = self.active_color.hue.into_positive_degrees();
|
||||
let pivot = hue * 7.0 / 360.;
|
||||
|
||||
let low_end = pivot.floor() as usize;
|
||||
let high_start = pivot.ceil() as usize;
|
||||
let pivot_color = palette::Hsv::new_srgb(RgbHue::new(hue), 1.0, 1.0);
|
||||
let low_range = HSV_RAINBOW[0..=low_end]
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, color)| ColorStop {
|
||||
color: *color,
|
||||
offset: i as f32 / pivot.max(0.0001),
|
||||
})
|
||||
.chain(iter::once(ColorStop {
|
||||
color: iced::Color::from(palette::Srgba::from_color(pivot_color)),
|
||||
offset: 1.,
|
||||
}))
|
||||
.collect::<Vec<_>>();
|
||||
let high_range =
|
||||
iter::once(ColorStop {
|
||||
color: iced::Color::from(palette::Srgba::from_color(pivot_color)),
|
||||
offset: 0.,
|
||||
})
|
||||
.chain(HSV_RAINBOW[high_start..].iter().enumerate().map(
|
||||
|(i, color)| ColorStop {
|
||||
color: *color,
|
||||
offset: (i as f32 + (1. - pivot.fract()))
|
||||
/ (7. - pivot).max(0.0001),
|
||||
},
|
||||
))
|
||||
.collect::<Vec<_>>();
|
||||
a.rail.backgrounds = (
|
||||
Background::Gradient(iced::Gradient::Linear(
|
||||
Linear::new(Radians(90.0)).add_stops(low_range),
|
||||
)),
|
||||
Background::Gradient(iced::Gradient::Linear(
|
||||
Linear::new(Radians(90.0)).add_stops(high_range),
|
||||
)),
|
||||
);
|
||||
a.rail.backgrounds = rail_backgrounds(hue);
|
||||
a.rail.width = 8.0;
|
||||
a.handle.background = Color::TRANSPARENT.into();
|
||||
a.handle.shape = HandleShape::Circle { radius: 8.0 };
|
||||
|
|
@ -491,9 +420,7 @@ where
|
|||
.class(Button::Text);
|
||||
|
||||
match self.copied_at.take() {
|
||||
Some(t)
|
||||
if Instant::now().duration_since(t) > Duration::from_secs(2) =>
|
||||
{
|
||||
Some(t) if Instant::now().duration_since(t) > Duration::from_secs(2) => {
|
||||
button.into()
|
||||
}
|
||||
Some(_) => tooltip(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue