mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 09:08:11 +00:00
Merge pull request #3417 from dotCooCoo/fix/color-ui-spectrum-square-boxes
color-ui: the FillStroke Color panel's Spectrum keeps its end boxes square
This commit is contained in:
@@ -132,8 +132,8 @@ impl Body<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The Spectrum ramp (grey in Grayscale) with a tooltip naming the shown mode. A Cmd or Ctrl click recolours and
|
||||
/// picks nothing; a Shift click moves to the next mode.
|
||||
/// The Spectrum ramp (gray in Grayscale) with a tooltip naming the shown mode, at least as tall as its square end
|
||||
/// boxes. A Cmd or Ctrl click recolors and picks nothing; a Shift click moves to the next mode.
|
||||
fn spectrum(&mut self, ui: &mut Ui) {
|
||||
let mode = self.shown_mode();
|
||||
let kind = if mode == ColorPanelMode::GrayscaleSlider { RampKind::Grayscale } else { RampKind::Spectrum };
|
||||
@@ -146,6 +146,7 @@ impl Body<'_> {
|
||||
.gamut(gamut)
|
||||
.gamut_revision(revision)
|
||||
.web_safe(self.now.web_safe_ramp)
|
||||
.square_boxes(true)
|
||||
.sizing(Sizing::Fill)
|
||||
.show(ui);
|
||||
self.ramp_events(ramp.edit.events);
|
||||
|
||||
@@ -6,8 +6,8 @@ use craft_cms::convert::CmykConverter;
|
||||
use craft_theme::{Hsb, Srgba};
|
||||
use craft_ui::canvas::context_click;
|
||||
use craft_ui::contract::{
|
||||
Access, Bind, BindMut, Common, Component, Cx, DisabledLook, Edit as _, EditResponse, Focus as _, Input, Name, Outcome, PaintUi, PartsCx,
|
||||
Pointer as _, Props as _, Remember as _, Role, WordSetCx as _,
|
||||
Access, Bind, BindMut, Common, Component, Cx, DisabledLook, Edit as _, EditResponse, Focus as _, Input, MeasureCx, Name, Outcome, PaintUi,
|
||||
PartsCx, Pointer as _, Props as _, Remember as _, Role, WordSetCx as _,
|
||||
};
|
||||
use craft_ui::primitives::{Marker, PaintShape, StrokeWidth};
|
||||
use craft_ui::runtime::commands::FireSource;
|
||||
@@ -240,6 +240,11 @@ pub struct ColorRamp<'a> {
|
||||
/// Whether the white and black boxes follow the bar; on by default.
|
||||
#[prop]
|
||||
boxes: bool,
|
||||
/// Whether the ramp is at least as tall as its two end boxes stacked, each as tall as it is wide, in place of a
|
||||
/// color band; off by default. A ramp that takes the room under other rows keeps this height in a host sized by
|
||||
/// its content and in a short one.
|
||||
#[prop]
|
||||
square_boxes: bool,
|
||||
/// The ramp's kind as the host names it ("RGB Spectrum"), the bar's accessible value.
|
||||
#[prop(into)]
|
||||
kind_name: Option<Label>,
|
||||
@@ -265,6 +270,7 @@ impl<'a> ColorRamp<'a> {
|
||||
web_safe: false,
|
||||
recolor_clicks: false,
|
||||
boxes: true,
|
||||
square_boxes: false,
|
||||
kind_name: None,
|
||||
colors: Arc::default(),
|
||||
shown_ends: ends,
|
||||
@@ -416,6 +422,12 @@ impl Component for ColorRamp<'_> {
|
||||
Some(Axis::X)
|
||||
}
|
||||
|
||||
/// With [`square_boxes`](ColorRamp::square_boxes), as tall as its two end boxes stacked, each as tall as it is wide;
|
||||
/// else the style's least, a color band.
|
||||
fn measure(&mut self, cx: &MeasureCx<'_, Self>) -> Vec2 {
|
||||
if self.square_boxes { Vec2::new(0.0, cx.style.boxes * 2.0) } else { Vec2::ZERO }
|
||||
}
|
||||
|
||||
fn sense(&self) -> Sense {
|
||||
Sense::empty()
|
||||
}
|
||||
|
||||
@@ -16,7 +16,8 @@ use craft_theme::{ColorModel as _, HsbModel, Srgba};
|
||||
use craft_ui::choice::SwatchTable;
|
||||
use craft_ui::contract::Role;
|
||||
use craft_ui::contract::tooltip::DELAY;
|
||||
use craft_ui::contract::{Bind, Show as _};
|
||||
use craft_ui::contract::{Bind, Show as _, ShowContainer as _};
|
||||
use craft_ui::layout_components::Stack;
|
||||
use craft_ui::runtime::env::{Label, Scale};
|
||||
use craft_ui::runtime::requests::ColorRequest;
|
||||
use craft_ui::testing::focus::AccessActionKind;
|
||||
@@ -255,6 +256,36 @@ fn the_fill_stroke_spectrums_tooltip_names_the_shown_mode_and_shift_click_cycles
|
||||
assert!(edits.borrow().is_empty(), "a Shift click picks nothing: {:?}", edits.borrow());
|
||||
}
|
||||
|
||||
/// In a host sized by its content (a floating Color panel) the FillStroke spectrum is as tall as its end boxes stacked,
|
||||
/// each at least as tall as it is wide, not a thin band; in a short group it keeps that height and the body scrolls.
|
||||
#[trial]
|
||||
fn a_fill_stroke_spectrum_keeps_its_end_boxes_square_in_a_content_sized_host() {
|
||||
for (room, content_sized) in [(COLOR_ROOM, true), (Vec2::new(280.0, 96.0), false)] {
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let mut state = ColorPanelState::default();
|
||||
let show = |ui: &mut egui::Ui, state: &mut ColorPanelState| {
|
||||
let _ = ColorPanel::new(Bind::bound(state), [RED, BLUE]).layout(ColorPanelLayout::FillStroke).show(ui);
|
||||
};
|
||||
if content_sized {
|
||||
let _ = Stack::new().show(ui, |ui, _| show(ui, &mut state));
|
||||
} else {
|
||||
show(ui, &mut state);
|
||||
}
|
||||
});
|
||||
fixture.room(room).settle();
|
||||
let bar = fixture.by_label("Color Ramp").expect("the spectrum").rect;
|
||||
let ends: Vec<_> = fixture
|
||||
.by_role(Role::BUTTON)
|
||||
.into_iter()
|
||||
.filter(|button| button.rect.left() >= bar.right() - 0.5 && button.rect.y_range().intersects(bar.y_range()))
|
||||
.collect();
|
||||
assert_eq!(ends.len(), 2, "{room:?}: the white and black boxes beside the bar ({bar:?})");
|
||||
for end in ends {
|
||||
assert!(end.rect.height() >= end.rect.width() - 0.5, "{room:?}: an end box at least square ({:?} beside {bar:?})", end.rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const SWATCHES: [(&str, [f32; 3]); 6] = [
|
||||
("Red", [0.90, 0.28, 0.30]),
|
||||
("Orange", [0.97, 0.42, 0.08]),
|
||||
|
||||
Reference in New Issue
Block a user