Fix #578: a drag on the Color panel's spectrum no longer flickers near white
The Color panel shows the out-of-gamut and out-of-web warnings under its proxy only when the colour needs them, so the panel grew and shrank with the colour. Dragging on the spectrum's pale top edge, a colour out of gamut added a warning, the spectrum moved down under the pointer, the pointer then picked white (above the spectrum), the warning went away, the spectrum moved back up: the colour flipped every frame. The panel now keeps room for the warnings its mode can show, so its height no longer depends on the colour. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d066e0ddc0
commit
2e64786e8c
File diff suppressed because one or more lines are too long
|
|
@ -503,21 +503,33 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
|||
let mut new: Option<(Color, Live, Vec<f32>)> = None;
|
||||
let mut behind: Option<(Color, Live)> = None;
|
||||
let mut tinted: Option<(f32, Live)> = None;
|
||||
let gamut = color.filter(|_| matches!(mode, Mode::Rgb | Mode::Hsb)).and_then(|c| gamut_fix(app, ui.ctx(), "color-gamut", &c));
|
||||
// The warnings the mode shows: out of gamut in RGB and HSB, out of web colours but in Web Safe
|
||||
// RGB and Grayscale.
|
||||
let (shows_gamut, shows_web) = (matches!(mode, Mode::Rgb | Mode::Hsb), !matches!(mode, Mode::WebSafe | Mode::Grayscale));
|
||||
let gamut = color.filter(|_| shows_gamut).and_then(|c| gamut_fix(app, ui.ctx(), "color-gamut", &c));
|
||||
ui.horizontal(|ui| {
|
||||
// Left column: proxy, out-of-gamut and out-of-web warnings.
|
||||
ui.vertical(|ui| {
|
||||
ui.set_width(44.0);
|
||||
super::proxy(app, ui, 40.0);
|
||||
let web = color.filter(|c| !matches!(mode, Mode::WebSafe | Mode::Grayscale) && !is_web_safe(c)).map(|c| web_safe(&c));
|
||||
for (warning, fix) in [(GAMUT_WARNING, gamut), (WEB_WARNING, web)] {
|
||||
if let Some(fix) = fix {
|
||||
ui.add_space(6.0);
|
||||
if warning_chip(ui, warning, &fix) {
|
||||
new = Some((fix, Live::Released, components(mode, &fix)));
|
||||
}
|
||||
let web = color.filter(|c| shows_web && !is_web_safe(c)).map(|c| web_safe(&c));
|
||||
let warnings: Vec<_> = [(GAMUT_WARNING, gamut), (WEB_WARNING, web)].into_iter().filter_map(|(w, fix)| Some((w, fix?))).collect();
|
||||
for (warning, fix) in &warnings {
|
||||
ui.add_space(6.0);
|
||||
if warning_chip(ui, *warning, fix) {
|
||||
new = Some((*fix, Live::Released, components(mode, fix)));
|
||||
}
|
||||
}
|
||||
// Room for the mode's other warnings: the panel keeps its height as the colour changes,
|
||||
// else the spectrum below moves under a dragging pointer and the colour flips every
|
||||
// frame, e.g. between a pale colour out of gamut and white above the spectrum (#578).
|
||||
for _ in warnings.len()..usize::from(shows_gamut) + usize::from(shows_web) {
|
||||
ui.add_space(6.0);
|
||||
ui.scope(|ui| {
|
||||
ui.set_invisible();
|
||||
warning_chip(ui, WEB_WARNING, &Color::WHITE)
|
||||
});
|
||||
}
|
||||
});
|
||||
// Sliders (Shift-drag moves them in tandem).
|
||||
ui.vertical(|ui| {
|
||||
|
|
@ -705,6 +717,40 @@ mod tests {
|
|||
(f.color().map(|c| c.to_hex()).unwrap_or_default(), s.color().map(|c| c.to_hex()).unwrap_or_default())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_drag_on_the_spectrum_holds_still_near_white() {
|
||||
let mut app = app();
|
||||
let ctx = egui::Context::default();
|
||||
let none = egui::Modifiers::NONE;
|
||||
// White needs no warning, #fefefe the web one, a pale violet both: one panel height.
|
||||
let heights: Vec<f32> = ["#ffffff", "#fefefe", "#ded3ff"]
|
||||
.iter()
|
||||
.map(|c| {
|
||||
app.run("paint.setFill", json!({"color": c})).unwrap();
|
||||
frame(&mut app, &ctx, vec![], none);
|
||||
frame(&mut app, &ctx, vec![], none).1
|
||||
})
|
||||
.collect();
|
||||
assert!(heights.windows(2).all(|w| w[0] == w[1]), "{heights:?}");
|
||||
// Drag along the spectrum's top edge (pale colours, some out of gamut), stopping at each
|
||||
// point: the colour holds while the pointer does.
|
||||
let r = frame(&mut app, &ctx, vec![], none).0.expect("the spectrum is drawn");
|
||||
let at = |x: f32| egui::pos2(r.left() + x * r.width(), r.top() + 2.0);
|
||||
let button = |pressed| egui::Event::PointerButton { pos: at(0.02), button: egui::PointerButton::Primary, pressed, modifiers: none };
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(at(0.02)), button(true)], none);
|
||||
for i in 1..20 {
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(at(i as f32 * 0.05))], none);
|
||||
let fills: Vec<String> = (0..3)
|
||||
.map(|_| {
|
||||
frame(&mut app, &ctx, vec![], none);
|
||||
paints_hex(&app).0
|
||||
})
|
||||
.collect();
|
||||
assert!(fills.windows(2).all(|w| w[0] == w[1]), "at {}: {fills:?}", i as f32 * 0.05);
|
||||
}
|
||||
frame(&mut app, &ctx, vec![button(false)], none);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tandem_keeps_ratios() {
|
||||
let t = tandem(Mode::Rgb, &[100.0, 50.0, 25.0], 0, 200.0);
|
||||
|
|
|
|||
Loading…
Reference in New Issue