mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 02:09:00 +00:00
color-ui and draw stories bind through data.bind, value_at and pair_at, as upstream's do
This commit is contained in:
@@ -49,10 +49,10 @@ fn color_area_disabled(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
/// and edged.
|
||||
#[story(ColorArea<'static>, covers = [], drive = Drive::Never)]
|
||||
fn color_area_gamut(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let values = data.value("values", HsbModel.from_srgb(Srgba::rgb(0.2, 0.5, 0.8)));
|
||||
let values = data.bind("values", HsbModel.from_srgb(Srgba::rgb(0.2, 0.5, 0.8)));
|
||||
let pale_to_black = Gamut::new(|color: Srgba| {
|
||||
let (high, low) = (color.r.max(color.g).max(color.b), color.r.min(color.g).min(color.b));
|
||||
if high > 0.5 && low > high / 2.0 { Srgba::rgb(0.0, 0.0, 0.0) } else { color }
|
||||
});
|
||||
ColorArea::new("Saturation and brightness", AreaMode::Hue, Bind::bound(values)).shape(AreaShape::Square).gamut(pale_to_black).show(ui).into()
|
||||
ColorArea::new("Saturation and brightness", AreaMode::Hue, values).shape(AreaShape::Square).gamut(pale_to_black).show(ui).into()
|
||||
}
|
||||
|
||||
@@ -71,9 +71,8 @@ fn gradient_editor_combined(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
/// An Alt-drag of a colour stop onto another swaps their colours.
|
||||
#[story(GradientEditor<'static, u8>, covers = [], drive = Drive::Never, title = "Alt-drop swaps")]
|
||||
fn gradient_editor_alt_drop_swap(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let stops = data.value("stops", combined());
|
||||
let rules = StopRules::new(StopRows::Combined).alt_drop(AltDrop::Swap);
|
||||
let output = GradientEditor::new("Gradient", Bind::bound(stops)).rules(rules).show(ui);
|
||||
let output = GradientEditor::new("Gradient", data.bind("stops", combined())).rules(rules).show(ui);
|
||||
hinted(ui, data, output)
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ const SPOT: Srgba = Srgba::rgb(0.95, 0.65, 0.1);
|
||||
|
||||
#[story(HarmonyPanel<'static>, covers = [], drive = Drive::Never, title = "Host cell colors")]
|
||||
fn harmony_panel_host_cells(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let (state, picked) = data.value("guide", (triad(), HarmonyPicked::default()));
|
||||
HarmonyPanel::new(Bind::bound(&mut *state), Bind::bound(&mut *picked), BASE)
|
||||
let ((state, state_at), (picked, picked_at)) = data.pair_at(("guide", triad()), ("picked", HarmonyPicked::default()));
|
||||
HarmonyPanel::new(state_at.bind(state), picked_at.bind(picked), BASE)
|
||||
.cell_color(|cell| match cell.at {
|
||||
GuideCellAt::Strip(_) => SPOT,
|
||||
GuideCellAt::Grid { .. } => cell.color,
|
||||
|
||||
@@ -10,8 +10,8 @@ use egui::{Color32, Pos2, Rect, Shape, Ui, Vec2};
|
||||
const GRID: f32 = 16.0;
|
||||
|
||||
fn area(ui: &mut Ui, data: &mut StoryData, gamut: Gamut<'static>) -> StoryOutput {
|
||||
let values = data.value("values", HsbModel.from_srgb(Srgba::rgb(0.2, 0.5, 0.8)));
|
||||
ColorArea::new("Saturation and brightness", AreaMode::Hue, Bind::bound(values)).shape(AreaShape::Square).gamut(gamut).show(ui).into()
|
||||
let values = data.bind("values", HsbModel.from_srgb(Srgba::rgb(0.2, 0.5, 0.8)));
|
||||
ColorArea::new("Saturation and brightness", AreaMode::Hue, values).shape(AreaShape::Square).gamut(gamut).show(ui).into()
|
||||
}
|
||||
|
||||
/// Moves the pale colours of the top-left quarter (saturation under a half, brightness over a half) to black.
|
||||
|
||||
@@ -193,8 +193,8 @@ fn cycling_kinds_and_a_wide_angle_limit(ui: &mut Ui, data: &mut StoryData) -> St
|
||||
#[story(CornerWidgets<'static>, covers = [], drive = Drive::Never)]
|
||||
fn display_only_in_a_layer_colour(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let color = DataColor::new(accent(ui, 1.0));
|
||||
let targets = data.value("targets", targets());
|
||||
let (targets, targets_at) = data.value_at("targets", targets());
|
||||
on_canvas(ui, targets, |ui, at, targets| {
|
||||
CornerWidgets::new("Corner radius", Bind::bound(targets)).reach(TransformReach::Shown).color(color).show_at(ui, at)
|
||||
CornerWidgets::new("Corner radius", targets_at.bind(targets)).reach(TransformReach::Shown).color(color).show_at(ui, at)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -31,24 +31,24 @@ fn selected() -> PathSelection {
|
||||
|
||||
#[story(BezierOverlay<'static>, covers = [], drive = Drive::Never)]
|
||||
fn anchors_selected_in_two_paths(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let paths = data.value("paths", paths());
|
||||
let (paths, paths_at) = data.value_at("paths", paths());
|
||||
on_canvas(ui, |ui, at| {
|
||||
BezierOverlay::new("Paths", Bind::bound(&mut *paths), &selected().also(2, vec![KnotRef::new(0, 0), KnotRef::new(0, 1)])).show_at(ui, at)
|
||||
BezierOverlay::new("Paths", paths_at.bind(&mut *paths), &selected().also(2, vec![KnotRef::new(0, 0), KnotRef::new(0, 1)])).show_at(ui, at)
|
||||
})
|
||||
}
|
||||
|
||||
/// One anchor over both paths shows its handles; the second story's two anchors show none.
|
||||
#[story(BezierOverlay<'static>, covers = [], drive = Drive::Never)]
|
||||
fn one_anchor_shows_its_handles(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let paths = data.value("paths", paths());
|
||||
on_canvas(ui, |ui, at| BezierOverlay::new("Paths", Bind::bound(&mut *paths), &selected()).handles(HandlesShown::OneAnchor).show_at(ui, at))
|
||||
let (paths, paths_at) = data.value_at("paths", paths());
|
||||
on_canvas(ui, |ui, at| BezierOverlay::new("Paths", paths_at.bind(&mut *paths), &selected()).handles(HandlesShown::OneAnchor).show_at(ui, at))
|
||||
}
|
||||
|
||||
#[story(BezierOverlay<'static>, covers = [], drive = Drive::Never)]
|
||||
fn two_anchors_show_no_handles(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let paths = data.value("paths", paths());
|
||||
let (paths, paths_at) = data.value_at("paths", paths());
|
||||
on_canvas(ui, |ui, at| {
|
||||
BezierOverlay::new("Paths", Bind::bound(&mut *paths), &selected().also(2, vec![KnotRef::new(0, 0)]))
|
||||
BezierOverlay::new("Paths", paths_at.bind(&mut *paths), &selected().also(2, vec![KnotRef::new(0, 0)]))
|
||||
.handles(HandlesShown::OneAnchor)
|
||||
.show_at(ui, at)
|
||||
})
|
||||
@@ -56,17 +56,17 @@ fn two_anchors_show_no_handles(ui: &mut Ui, data: &mut StoryData) -> StoryOutput
|
||||
|
||||
#[story(BezierOverlay<'static>, covers = [], drive = Drive::Never)]
|
||||
fn curvature_anchors(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let paths = data.value("paths", paths());
|
||||
let (paths, paths_at) = data.value_at("paths", paths());
|
||||
on_canvas(ui, |ui, at| {
|
||||
BezierOverlay::new("Paths", Bind::bound(&mut *paths), &selected()).anchors(AnchorsShown::Curvature).show_at(ui, at)
|
||||
BezierOverlay::new("Paths", paths_at.bind(&mut *paths), &selected()).anchors(AnchorsShown::Curvature).show_at(ui, at)
|
||||
})
|
||||
}
|
||||
|
||||
#[story(BezierOverlay<'static>, covers = [], drive = Drive::Never)]
|
||||
fn anchors_in_the_users_size_and_style(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let paths = data.value("paths", paths());
|
||||
let (paths, paths_at) = data.value_at("paths", paths());
|
||||
let settings = PathOptionsSettings { anchor_size: Some(12.0), handles: HandleStyle::Large, ..PathOptionsSettings::default() };
|
||||
on_canvas(ui, |ui, at| BezierOverlay::new("Paths", Bind::bound(&mut *paths), &selected()).path_options(&settings).show_at(ui, at))
|
||||
on_canvas(ui, |ui, at| BezierOverlay::new("Paths", paths_at.bind(&mut *paths), &selected()).path_options(&settings).show_at(ui, at))
|
||||
}
|
||||
|
||||
#[story(BezierOverlay<'static>, covers = [Default], drive = Drive::Drag(Grip::part(ANCHOR.at(index(0, KnotRef { subpath: 0, knot: 0 }))).toward(Vec2::X)))]
|
||||
|
||||
@@ -42,8 +42,8 @@ fn panel_form(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
/// The panel form with X and W on the first row and Y and H on the second.
|
||||
#[story(TransformFields<'static>, covers = [], drive = Drive::Never)]
|
||||
fn panel_form_position_first(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let state = data.value("state", sample());
|
||||
TransformFields::new("Transform", Bind::bound(&mut state.0), START, Bind::bound(&mut state.1))
|
||||
let (state, state_at) = data.value_at("state", sample());
|
||||
TransformFields::new("Transform", state_at.bind(&mut state.0), START, state_at.bind(&mut state.1))
|
||||
.arrangement(FieldArrangement::PositionFirst)
|
||||
.show(ui)
|
||||
.into()
|
||||
|
||||
Reference in New Issue
Block a user