mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 00:34:25 +00:00
wip
This commit is contained in:
@@ -73,6 +73,14 @@ impl<'a> ColorArea<'a> {
|
||||
self.quantize.map(|levels| levels.max(2))
|
||||
}
|
||||
|
||||
/// The values the pointer at `at` picks in `rect`: the picker's own point-to-value mapping, then the settle and
|
||||
/// quantise steps. `ColorHud` drives it with the host's pointer.
|
||||
#[allow(dead_code)] // P3(panels-w7): pn.C32
|
||||
pub(crate) fn value_at(&self, rect: Rect, values: &ModelValues, at: egui::Pos2) -> ModelValues {
|
||||
let _ = (rect, values, at);
|
||||
todo!("pn.C32")
|
||||
}
|
||||
|
||||
/// The picker over `shown`, whose backdrop paints the field of `base`.
|
||||
fn picker<'c>(&self, shown: Option<&ModelValues>, field: bool) -> PointPicker<'c> {
|
||||
let model = self.mode.model();
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
//! [`ColorHud`]: the colour area and hue strip in a popover at a point, driven by the host's press.
|
||||
|
||||
use craft_behavior::EditEvents;
|
||||
use craft_theme::Srgba;
|
||||
use craft_ui::contract::{Bind, Pattern};
|
||||
use craft_ui::runtime::env::Label;
|
||||
use craft_ui::runtime::overlay::CloseReason;
|
||||
use egui::{Pos2, Response, Ui};
|
||||
|
||||
/// The area and hue strip in a popover at `at`, with the start colour under it, driven by the host's press: the pick
|
||||
/// maps `pointer` through `ColorArea` and the strip's `value_at`; no pick while `pointer` is still `at`; one gesture
|
||||
/// per open; Escape or `held(false)` commits and closes. Every input is a prop of the pass; the HUD keeps no state.
|
||||
#[must_use = "show the HUD with `show`"]
|
||||
#[derive(Pattern)]
|
||||
#[allow(dead_code)] // P3(panels-w7): pn.C31
|
||||
pub struct ColorHud<'a> {
|
||||
label: Label,
|
||||
at: Pos2,
|
||||
color: Bind<'a, Srgba>,
|
||||
pointer: Option<Pos2>,
|
||||
held: bool,
|
||||
}
|
||||
|
||||
impl<'a> ColorHud<'a> {
|
||||
/// A HUD named `label` at `at` over `color`.
|
||||
pub fn new(label: impl Into<Label>, at: Pos2, color: Bind<'a, Srgba>) -> Self {
|
||||
let _ = (label.into(), at, color);
|
||||
todo!("pn.C31")
|
||||
}
|
||||
|
||||
/// The host's pointer, or `None` while it has none.
|
||||
#[must_use]
|
||||
pub fn pointer(mut self, at: Option<Pos2>) -> Self {
|
||||
let _ = (&mut self, at);
|
||||
todo!("pn.C31")
|
||||
}
|
||||
|
||||
/// Whether the host's press is still held.
|
||||
#[must_use]
|
||||
pub fn held(mut self, held: bool) -> Self {
|
||||
let _ = (&mut self, held);
|
||||
todo!("pn.C31")
|
||||
}
|
||||
|
||||
/// Draws the HUD.
|
||||
pub fn show(self, ui: &mut Ui) -> ColorHudOutput {
|
||||
let _ = (self, ui);
|
||||
todo!("pn.C31")
|
||||
}
|
||||
}
|
||||
|
||||
/// What the HUD reports.
|
||||
#[derive(Debug)]
|
||||
#[non_exhaustive]
|
||||
pub struct ColorHudOutput {
|
||||
/// The popover's response.
|
||||
pub response: Response,
|
||||
/// The edit events of the colour.
|
||||
pub events: EditEvents<Srgba>,
|
||||
/// Why it closed this pass.
|
||||
pub closed: Option<CloseReason>,
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
//! [`InfoPanel`]: a read-only readout grid of the colour, position and size under the pointer.
|
||||
|
||||
use craft_cms::convert::CmykConverter;
|
||||
use craft_theme::Srgba;
|
||||
use craft_ui::contract::Pattern;
|
||||
use craft_ui::runtime::env::Label;
|
||||
use egui::{Response, Ui};
|
||||
|
||||
use super::SamplerReadout;
|
||||
|
||||
craft_ui::words! {
|
||||
/// The words of the Info panel, in the installed language unless set.
|
||||
pub struct InfoWords {
|
||||
r: "info.r" = "R";
|
||||
g: "info.g" = "G";
|
||||
b: "info.b" = "B";
|
||||
c: "info.c" = "C";
|
||||
m: "info.m" = "M";
|
||||
y: "info.y" = "Y";
|
||||
k: "info.k" = "K";
|
||||
x: "info.x" = "X";
|
||||
pos_y: "info.posY" = "Y";
|
||||
w: "info.w" = "W";
|
||||
h: "info.h" = "H";
|
||||
/// The document size template.
|
||||
document: "info.document" = "Doc: {width} x {height}";
|
||||
no_document: "info.noDocument" = "No document";
|
||||
}
|
||||
}
|
||||
|
||||
/// A colour in 8-bit sRGB and CMYK percent.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct InfoColor {
|
||||
/// The colour in 8-bit sRGB.
|
||||
pub rgb: [u8; 3],
|
||||
/// The colour in CMYK percent.
|
||||
pub cmyk: [u8; 4],
|
||||
}
|
||||
|
||||
impl InfoColor {
|
||||
/// `color` through the document's CMYK converter: the one sRGB-and-CMYK conversion, which `SamplerReadout::new` builds
|
||||
/// its `rgb` and `cmyk` through.
|
||||
pub fn new(color: Srgba, cmyk: &CmykConverter) -> Self {
|
||||
let _ = (color, cmyk);
|
||||
todo!("pn.C33")
|
||||
}
|
||||
}
|
||||
|
||||
/// What the Info panel shows.
|
||||
#[non_exhaustive]
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct InfoReadings<'a> {
|
||||
/// The colour under the pointer.
|
||||
pub color: Option<InfoColor>,
|
||||
/// The pointer's position.
|
||||
pub position: Option<[Label; 2]>,
|
||||
/// The selection's extent.
|
||||
pub extent: Option<[Label; 2]>,
|
||||
/// The document's size; `None` is the no-document state.
|
||||
pub document: Option<[u32; 2]>,
|
||||
/// The colour samplers' readouts with their position labels.
|
||||
pub samplers: &'a [(SamplerReadout, [Label; 2])],
|
||||
}
|
||||
|
||||
impl<'a> InfoReadings<'a> {
|
||||
/// Readings with nothing in them.
|
||||
pub fn new() -> Self {
|
||||
todo!("pn.C33")
|
||||
}
|
||||
|
||||
/// Sets the colour.
|
||||
#[must_use]
|
||||
pub fn color(mut self, color: Option<InfoColor>) -> Self {
|
||||
let _ = (&mut self, color);
|
||||
todo!("pn.C33")
|
||||
}
|
||||
|
||||
/// Sets the position.
|
||||
#[must_use]
|
||||
pub fn position(mut self, position: Option<[Label; 2]>) -> Self {
|
||||
let _ = (&mut self, position);
|
||||
todo!("pn.C33")
|
||||
}
|
||||
|
||||
/// Sets the extent.
|
||||
#[must_use]
|
||||
pub fn extent(mut self, extent: Option<[Label; 2]>) -> Self {
|
||||
let _ = (&mut self, extent);
|
||||
todo!("pn.C33")
|
||||
}
|
||||
|
||||
/// Sets the document size.
|
||||
#[must_use]
|
||||
pub fn document(mut self, document: Option<[u32; 2]>) -> Self {
|
||||
let _ = (&mut self, document);
|
||||
todo!("pn.C33")
|
||||
}
|
||||
|
||||
/// Sets the samplers.
|
||||
#[must_use]
|
||||
pub fn samplers(mut self, samplers: &'a [(SamplerReadout, [Label; 2])]) -> Self {
|
||||
let _ = (&mut self, samplers);
|
||||
todo!("pn.C33")
|
||||
}
|
||||
}
|
||||
|
||||
/// A read-only grid: RGB beside CMYK, X/Y beside W/H, the document size, then one row group per sampler; a dash for a
|
||||
/// missing value; `document: None` shows "No document" as a centred notice in place of the grid.
|
||||
#[must_use = "show the panel with `show`"]
|
||||
#[derive(Pattern)]
|
||||
#[allow(dead_code)] // P3(panels-w7): pn.C33
|
||||
pub struct InfoPanel<'a> {
|
||||
label: Label,
|
||||
readings: &'a InfoReadings<'a>,
|
||||
}
|
||||
|
||||
impl<'a> InfoPanel<'a> {
|
||||
/// A panel named `label` over `readings`.
|
||||
pub fn new(label: impl Into<Label>, readings: &'a InfoReadings<'a>) -> Self {
|
||||
let _ = (label.into(), readings);
|
||||
todo!("pn.C33")
|
||||
}
|
||||
|
||||
/// Draws the grid.
|
||||
pub fn show(self, ui: &mut Ui) -> Response {
|
||||
let _ = (self, ui);
|
||||
todo!("pn.C33")
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,8 @@ mod eyedropper;
|
||||
pub mod gradient;
|
||||
mod harmony;
|
||||
mod hex;
|
||||
mod hud;
|
||||
mod info;
|
||||
mod lut_picker;
|
||||
mod paint_chip;
|
||||
mod pair;
|
||||
@@ -53,7 +55,9 @@ pub use harmony::{
|
||||
HarmonyCommand, HarmonyMenu, HarmonyMenuAction, HarmonyPanel, HarmonyPanelOutput, HarmonyPanelState, HarmonyPicked, HarmonyWheel,
|
||||
HarmonyWheelOutput, HarmonyWords,
|
||||
};
|
||||
pub use hud::{ColorHud, ColorHudOutput};
|
||||
pub use hex::{HexPair, HexPairField, PairCodec};
|
||||
pub use info::{InfoColor, InfoPanel, InfoReadings, InfoWords};
|
||||
pub use lut_picker::{LutChoice, LutPicker, LutPickerOutput, LutWords};
|
||||
pub use paint_chip::{
|
||||
FillKind, GradientPreview, ImagePreview, Paint, PaintChip, PaintChipOutput, PaintEditor, PaintLink, PaintLinkKind, PaintList, PaintListEvent,
|
||||
|
||||
@@ -451,6 +451,12 @@ pub struct SamplerReadout {
|
||||
}
|
||||
|
||||
impl SamplerReadout {
|
||||
/// The readout of point number `number` at `position` with the given 8-bit `rgb` and CMYK percent: how a host whose
|
||||
/// colours come from its own engine fills the rows.
|
||||
pub fn from_values(number: usize, position: [i64; 2], rgb: [u8; 3], cmyk: [u8; 4]) -> SamplerReadout {
|
||||
SamplerReadout { number, position, rgb, cmyk }
|
||||
}
|
||||
|
||||
/// The readout of point `index` at `position` with `color`, CMYK through `cmyk`. A channel that is not finite
|
||||
/// reads as 0 and the rest is clamped.
|
||||
pub fn new(index: usize, position: [f64; 2], color: Srgba, cmyk: &CmykConverter) -> SamplerReadout {
|
||||
|
||||
@@ -255,3 +255,11 @@ impl Component for ColorStrip<'_> {
|
||||
cx.edit_response()
|
||||
}
|
||||
}
|
||||
|
||||
/// The values the pointer at `at` picks in the strip's `rect` for `mode`: the `ValueDrag` mapping of `update`, which
|
||||
/// `ColorHud` drives with the host's pointer.
|
||||
#[allow(dead_code)] // P3(panels-w7): pn.C32
|
||||
pub(crate) fn value_at(rect: Rect, mode: AreaMode, values: &ModelValues, at: Pos2) -> ModelValues {
|
||||
let _ = (rect, mode, values, at);
|
||||
todo!("pn.C32")
|
||||
}
|
||||
|
||||
@@ -135,6 +135,13 @@ pub struct PointPicker<'a> {
|
||||
}
|
||||
|
||||
impl<'a> PointPicker<'a> {
|
||||
/// The value pair at `pos` in `rect`: the plot, the two `ValueDrag`s and `point_at` in one function, which the drag
|
||||
/// then calls, so the picker and the colour HUD share one mapping. `None` when the picker has no area.
|
||||
pub fn value_at(&self, rect: Rect, pos: Pos2) -> Option<[f64; 2]> {
|
||||
let _ = (rect, pos);
|
||||
todo!("pn.C32")
|
||||
}
|
||||
|
||||
/// The well: a press on it moves the point there, and a drag from it follows the pointer.
|
||||
pub const WELL: PartKey = PartKey::new("well");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user