mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 05:37:04 +00:00
Merge branch 'red/rd-dialogs-w2' into area/dialogs-fw
This commit is contained in:
@@ -136,6 +136,7 @@ enum Title {
|
||||
/// the app takes the colour with [`take_add_to_swatches`](Self::take_add_to_swatches).
|
||||
/// - **Preview:** [`current`](Self::current) follows every edit, so an app that previews reads it each pass through
|
||||
/// `DialogHost::get_by_id` and shows it live; Cancel is the app's cue to put the old colour back.
|
||||
#[derive(craft_ui::contract::Pattern)]
|
||||
pub struct ColorPickerDialog {
|
||||
id: DialogId,
|
||||
/// Which of several pickers of the same key this is ([`instance`](Self::instance)).
|
||||
@@ -658,6 +659,14 @@ impl StackDialog for ColorPickerDialog {
|
||||
}
|
||||
});
|
||||
self.current = held.same().copied();
|
||||
if self.layout == ColorPickerDialogLayout::Tabbed {
|
||||
eprintln!(
|
||||
"DIAG the_tabbed_colors_dialog_opens_on_its_tab_and_answers_from_either_page: held same={} picked={:?} closed={:?}",
|
||||
self.current.is_some(),
|
||||
shown.output.picked,
|
||||
shown.output.closed
|
||||
);
|
||||
}
|
||||
|
||||
let (picked, closed) = (shown.output.picked, shown.output.closed);
|
||||
let ok = (picked == Some(0) || closed == Some(CloseReason::Enter)) && self.current.is_some();
|
||||
|
||||
@@ -210,7 +210,17 @@ fn the_tabbed_colors_dialog_opens_on_its_tab_and_answers_from_either_page() {
|
||||
assert_eq!(dialog_field(&dialogs, "model"), Some(serde_json::json!(RgbModel.id())), "the field names the model shown");
|
||||
assert!(fixture.by_label("Red").is_some(), "and the compact rows show that model's channels");
|
||||
|
||||
eprintln!(
|
||||
"DIAG the_tabbed_colors_dialog_opens_on_its_tab_and_answers_from_either_page: before typing current={:?} open={}",
|
||||
dialog_color(&dialogs),
|
||||
dialogs.borrow().get::<ColorPickerDialog>().is_some()
|
||||
);
|
||||
type_into(&mut fixture, "Hex color", "336699");
|
||||
eprintln!(
|
||||
"DIAG the_tabbed_colors_dialog_opens_on_its_tab_and_answers_from_either_page: after typing current={:?} open={}",
|
||||
dialog_color(&dialogs),
|
||||
dialogs.borrow().get::<ColorPickerDialog>().is_some()
|
||||
);
|
||||
assert_eq!(dialog_color(&dialogs).as_deref(), Some("#336699"), "a hex typed on Custom is the colour");
|
||||
|
||||
let set = dialogs.borrow_mut().set_json_field(&ctx, id, "tab", serde_json::json!("standard"));
|
||||
|
||||
@@ -4,23 +4,19 @@
|
||||
use super::radio::RadioKind;
|
||||
use super::words::ChoiceWords;
|
||||
use crate::contract::{
|
||||
Access, Activation, Common, Component, Cx, DisabledLook, GroupHandle, MeasureCx, Meta as _, Outcome, PaintUi, PartsCx, Pointer as _, Props as _,
|
||||
Role, Sizing, Styled as _, WordSetCx as _,
|
||||
Access, Activation, Common, Component, Cx, DisabledLook, GroupHandle, MeasureCx, Meta as _, Outcome, PaintUi, Pointer as _, Props as _, Role,
|
||||
Sizing, Styled as _, WordSetCx as _,
|
||||
};
|
||||
use crate::runtime::focus::FocusShape;
|
||||
use crate::primitives::{ContentPainterCx, Draw, PaintShape, StrokeWidth};
|
||||
use crate::runtime::requests::ColorRequest;
|
||||
use crate::style::{ComponentStyle, DataColor, Flags, FocusLook, State, StateMix, StateSet, StyleColor, StyleCx, UiTokens, resolve_style};
|
||||
use craft_behavior::{HitShape, Metrics, Mixed, PartKey, Sense, Value};
|
||||
use craft_behavior::{Metrics, Mixed, Sense, Value};
|
||||
use craft_theme::{Rgba, Srgba, Stateful, States, over};
|
||||
use egui::{Color32, CornerRadius, Pos2, Rect, Response, Vec2, pos2};
|
||||
|
||||
#[cfg(feature = "testing")]
|
||||
mod stories;
|
||||
|
||||
/// The face of a hexagon swatch: the part whose outline the focus ring follows.
|
||||
const FACE: PartKey = PartKey::new("face");
|
||||
|
||||
/// Opacity of the black or white ring that stands out from a well's colour.
|
||||
const INNER_EDGE_ALPHA: u8 = 0x80;
|
||||
|
||||
@@ -58,7 +54,8 @@ pub struct SwatchStyle {
|
||||
radius: CornerRadius,
|
||||
/// The ring on the well's outline, which separates the well from the panel.
|
||||
edge: Stateful<StyleColor>,
|
||||
/// The ring inside the outline of a selected or checked well; clear while it is off.
|
||||
/// The ring on the well's outline: the accent for a selected or checked well, the focus colour on the lead cell of
|
||||
/// a table (a member runs no focus step of its own, so its outline carries the ring); clear while it is off.
|
||||
ring: Stateful<StyleColor>,
|
||||
/// The thin edge just inside the outline of a marked well.
|
||||
mark: StyleColor,
|
||||
@@ -207,7 +204,7 @@ impl<T: Value + 'static> Swatch<T> {
|
||||
|
||||
impl<T: Value + 'static> Component for Swatch<T> {
|
||||
const ROLE: Role = Role::COLOR_WELL;
|
||||
const PARTS: bool = true;
|
||||
const PARTS: bool = false;
|
||||
const OVERLAYS: bool = false;
|
||||
const ALT_ROLES: &'static [Role] = &[Role::RADIO_BUTTON, Role::LIST_BOX_OPTION];
|
||||
const DISABLED: DisabledLook = DisabledLook::Faded;
|
||||
@@ -226,7 +223,7 @@ impl<T: Value + 'static> Component for Swatch<T> {
|
||||
side: if key.cell && !key.well { metrics.cell } else { metrics.side },
|
||||
radius: if key.cell && !key.well { CornerRadius::ZERO } else { metrics.radius },
|
||||
edge: Stateful::new(rest),
|
||||
ring: Stateful::new(clear).on(States::new(accent, accent, accent, accent)),
|
||||
ring: Stateful::new(clear).on(States::new(accent, accent, accent, accent)).when(Flags::LEAD, cx.color(colors.line.focus)),
|
||||
mark: cx.color(colors.text.normal),
|
||||
checker: [colors.overlay.checker_light, colors.overlay.checker_dark],
|
||||
mixed_rgba: colors.surface.sunken,
|
||||
@@ -281,14 +278,6 @@ impl<T: Value + 'static> Component for Swatch<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// A hexagon swatch declares its face as the focus stop, so the ring follows the hexagon and not its rect.
|
||||
fn parts(&mut self, rect: Rect, cx: &mut PartsCx<'_, Self>) {
|
||||
if self.shape == SwatchShape::Hexagon {
|
||||
let corners = hexagon(rect);
|
||||
cx.part(FACE, HitShape::Polygon(corners.clone())).focusable().focus_shape(FocusShape::Polygon(corners));
|
||||
}
|
||||
}
|
||||
|
||||
fn paint(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) {
|
||||
paint_face(&ui.draw(), cx.rect, cx.style, cx.state(), self.color, self.marked, self.shape);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user