mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 02:09:00 +00:00
Contract stubs: craft-text craft-pages craft-gpu craft-ui-gallery craft
This commit is contained in:
Generated
+10
@@ -1776,6 +1776,7 @@ dependencies = [
|
||||
"craft-gainmap",
|
||||
"craft-gcode",
|
||||
"craft-gif",
|
||||
"craft-gpu",
|
||||
"craft-gridcraft-format",
|
||||
"craft-gzip",
|
||||
"craft-hdr",
|
||||
@@ -2651,6 +2652,14 @@ dependencies = [
|
||||
"image",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-gpu"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"egui-wgpu",
|
||||
"pollster 0.4.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-gridcraft-format"
|
||||
version = "0.1.0"
|
||||
@@ -3197,6 +3206,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"craft-behavior",
|
||||
"craft-i18n",
|
||||
"craft-keymap",
|
||||
"craft-text",
|
||||
"craft-theme",
|
||||
"craft-ui",
|
||||
|
||||
@@ -173,6 +173,7 @@ craft-dds = { path = "crates/dds" }
|
||||
craft-psd = { path = "crates/psd" }
|
||||
craft-pst = { path = "crates/pst" }
|
||||
craft-quit = { path = "crates/quit" }
|
||||
craft-gpu = { path = "crates/gpu" }
|
||||
craft-rtf = { path = "crates/rtf" }
|
||||
craft-raw = { path = "crates/raw" }
|
||||
craft-sheet = { path = "crates/sheet" }
|
||||
|
||||
@@ -94,6 +94,7 @@ craft-flow = { workspace = true, optional = true }
|
||||
craft-gainmap = { workspace = true, optional = true }
|
||||
craft-gcode = { workspace = true, optional = true }
|
||||
craft-gif = { workspace = true, optional = true }
|
||||
craft-gpu = { workspace = true, optional = true }
|
||||
craft-hdr = { workspace = true, optional = true }
|
||||
craft-heif = { workspace = true, optional = true }
|
||||
craft-html = { workspace = true, optional = true }
|
||||
@@ -415,6 +416,8 @@ gcode = ["dep:craft-gcode"]
|
||||
gif = ["dep:craft-gif"]
|
||||
gif-frames = ["gif", "craft-gif/frames"]
|
||||
|
||||
gpu = ["dep:craft-gpu"]
|
||||
|
||||
gridcraft-format = ["dep:craft-gridcraft-format"]
|
||||
|
||||
gzip = ["dep:craft-gzip"]
|
||||
|
||||
@@ -129,6 +129,8 @@ pub use craft_gainmap as gainmap;
|
||||
pub use craft_gcode as gcode;
|
||||
#[cfg(feature = "gif")]
|
||||
pub use craft_gif as gif;
|
||||
#[cfg(feature = "gpu")]
|
||||
pub use craft_gpu as gpu;
|
||||
#[cfg(feature = "gridcraft-format")]
|
||||
pub use craft_gridcraft_format as gridcraft_format;
|
||||
#[cfg(feature = "gzip")]
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
[package]
|
||||
name = "craft-gpu"
|
||||
description = "GPU start-up choices per platform for Craft apps on eframe's wgpu backend: backends, power preference, DX12 compiler and the Linux DRM device pick."
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
rust-version.workspace = true
|
||||
repository.workspace = true
|
||||
|
||||
[dependencies]
|
||||
# A `[patch.crates-io]` row at the framework root points egui-wgpu at the pinned egui fork; it is not a workspace dependency.
|
||||
egui-wgpu = "0.37"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
pollster = "0.4"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
@@ -0,0 +1,17 @@
|
||||
//! The GPU start-up choices, one module per platform.
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
mod drm;
|
||||
#[cfg(target_os = "linux")]
|
||||
mod linux;
|
||||
#[cfg(target_os = "macos")]
|
||||
mod macos;
|
||||
#[cfg(windows)]
|
||||
mod windows;
|
||||
|
||||
/// Sets the GPU start-up choices of the running platform on `setup`: the backends, the power preference, the DX12
|
||||
/// shader compiler and, on Linux, the DRM device to render on.
|
||||
pub fn configure(setup: &mut egui_wgpu::WgpuSetupCreateNew) {
|
||||
let _ = setup;
|
||||
todo!("pf.C-G1")
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
//! Linux: the DRM render node the device pick reads.
|
||||
@@ -0,0 +1 @@
|
||||
//! Linux: the Vulkan and GL backends and the choice of device.
|
||||
@@ -0,0 +1 @@
|
||||
//! macOS: the Metal backend and its power preference.
|
||||
@@ -0,0 +1 @@
|
||||
//! Windows: Direct3D 12 and Vulkan backends and the DX12 shader compiler.
|
||||
@@ -0,0 +1,10 @@
|
||||
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
|
||||
|
||||
//! GPU start-up choices per platform for apps on eframe's wgpu backend: which backends to try, the power preference,
|
||||
//! the DX12 shader compiler and, on Linux, which DRM device to render on. An app calls [`configure`] on the
|
||||
//! `WgpuSetupCreateNew` it hands to eframe.
|
||||
#![warn(missing_docs)]
|
||||
|
||||
mod device;
|
||||
|
||||
pub use device::configure;
|
||||
@@ -19,7 +19,7 @@ workspace = true
|
||||
[features]
|
||||
default = []
|
||||
# The page widgets (`craft_pages::ui`), on craft-ui.
|
||||
ui = ["dep:craft-behavior", "dep:craft-ui", "dep:craft-theme", "dep:egui"]
|
||||
ui = ["dep:craft-behavior", "dep:craft-keymap", "dep:craft-ui", "dep:craft-theme", "dep:egui", "craft-text/ui"]
|
||||
# The stories and the integration tests (`tests/it`).
|
||||
screen-testing = ["ui", "craft-ui/testing"]
|
||||
|
||||
@@ -29,6 +29,7 @@ craft-text = { path = "../text", default-features = false }
|
||||
kurbo = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
craft-behavior = { workspace = true, optional = true }
|
||||
craft-keymap = { workspace = true, optional = true }
|
||||
craft-ui = { workspace = true, optional = true }
|
||||
craft-theme = { workspace = true, optional = true }
|
||||
egui = { workspace = true, optional = true }
|
||||
|
||||
@@ -37,7 +37,10 @@ pub use layout::{
|
||||
};
|
||||
pub use numbering::{NumberStyle, PAGE_NUMBER_STYLES, PageNumbering};
|
||||
pub use range::{PageRange, PageRangeError, Subset, format_pages, parse_pages};
|
||||
pub use setup::{MARGIN_PRESETS, MarginPreset, Margins, Orientation, PAPER_SIZES, PageSetup, PageVerticalAlign, PaperSize, paper_named};
|
||||
pub use setup::{
|
||||
DocumentGrid, GridKind, MARGIN_PRESETS, MAX_GRID_COUNT, MarginPreset, Margins, Orientation, PAPER_SIZES, PageSetup, PageVerticalAlign, PaperSize,
|
||||
paper_named,
|
||||
};
|
||||
|
||||
/// The stories and trials this crate registers.
|
||||
#[cfg(feature = "screen-testing")]
|
||||
|
||||
@@ -206,6 +206,58 @@ pub struct PageSetup {
|
||||
pub different_odd_even: bool,
|
||||
/// Section direction right-to-left (Word).
|
||||
pub right_to_left: bool,
|
||||
/// Word's Document Grid; `None` where the app shows no grid section.
|
||||
#[serde(default)]
|
||||
pub grid: Option<DocumentGrid>,
|
||||
}
|
||||
|
||||
/// The most lines per page or characters per line the Document Grid takes.
|
||||
pub const MAX_GRID_COUNT: u32 = 1000;
|
||||
|
||||
/// Word's four Document Grid kinds.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
#[non_exhaustive]
|
||||
pub enum GridKind {
|
||||
/// No grid.
|
||||
#[default]
|
||||
None,
|
||||
/// A line grid only.
|
||||
Lines,
|
||||
/// A line and a character grid.
|
||||
LinesAndChars,
|
||||
/// Characters snap to the grid.
|
||||
SnapToChars,
|
||||
}
|
||||
|
||||
impl GridKind {
|
||||
/// Whether the characters-per-line count applies (`LinesAndChars` and `SnapToChars`).
|
||||
pub fn chars_enabled(self) -> bool {
|
||||
todo!("dg.F18")
|
||||
}
|
||||
|
||||
/// Whether the lines-per-page count applies (every kind but `None`).
|
||||
pub fn lines_enabled(self) -> bool {
|
||||
todo!("dg.F18")
|
||||
}
|
||||
}
|
||||
|
||||
/// A page's Document Grid.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
#[non_exhaustive]
|
||||
pub struct DocumentGrid {
|
||||
/// The kind of grid.
|
||||
pub kind: GridKind,
|
||||
/// Lines per page, up to [`MAX_GRID_COUNT`].
|
||||
pub lines_per_page: u32,
|
||||
/// Characters per line, up to [`MAX_GRID_COUNT`].
|
||||
pub chars_per_line: u32,
|
||||
}
|
||||
|
||||
impl DocumentGrid {
|
||||
/// A grid of `kind` with `lines_per_page` lines and `chars_per_line` characters.
|
||||
pub const fn new(kind: GridKind, lines_per_page: u32, chars_per_line: u32) -> Self {
|
||||
DocumentGrid { kind, lines_per_page, chars_per_line }
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for PageSetup {
|
||||
@@ -223,6 +275,7 @@ impl Default for PageSetup {
|
||||
different_first: false,
|
||||
different_odd_even: false,
|
||||
right_to_left: false,
|
||||
grid: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ pub mod header_footer;
|
||||
pub mod list;
|
||||
pub mod margins;
|
||||
pub mod marks;
|
||||
pub mod page_rulers;
|
||||
pub mod preview;
|
||||
pub mod range;
|
||||
pub mod reading;
|
||||
@@ -44,16 +45,19 @@ pub use header_footer::{HeaderFooterPage, HeaderFooterZones, HeaderFooterZonesOu
|
||||
pub use list::{PageList, PageListEvent, PageListOutput, PageListRow, PageListWords};
|
||||
pub use margins::{MarginChange, MarginEdge, MarginHandles, MarginHandlesOutput, MarginRules, PageEdges, clamp_margin, dragged_margin, margin_range};
|
||||
pub use marks::{FrameExtras, HiddenMark, PlacedMark, TextFrameMarks};
|
||||
pub use page_rulers::{PageRulers, PageRulersOutput, RowDrag, VerticalRuler, VerticalRulerOutput};
|
||||
pub use preview::{PagePreview, PagePreviewCommands, PagePreviewOutput, PagePreviewWords};
|
||||
pub use range::{PageRangeCodec, PageRangeField, PageRangeFieldOutput, PageRangeOptions, PageRangeOptionsOutput, PageSelection};
|
||||
pub use reading::{ReadingNav, ReadingNavOutput, ReadingState, ReadingView, ReadingViewOutput};
|
||||
pub use setup::{PageLayoutChoice, PageLayoutMenus, PageSetupDialog};
|
||||
pub use sync_views::{Lead, SyncedViews, SyncedViewsOutput, SyncedViewsState};
|
||||
pub use table::{
|
||||
BorderEdges, BorderPreset, CellAlign, CellSelectionOverlay, EdgeKey, EdgePicker, RowHeight, TableChange, TableGeometry, TableProperties,
|
||||
TablePropertiesOutput, TableSizePicker, TableSizePickerOutput, TableValues, TextDirection,
|
||||
BorderEdges, BorderPreset, CellAlign, CellSelectionOverlay, EdgeKey, EdgeLook, EdgePicker, RowHeight, SampleArea, TableChange, TableGeometry,
|
||||
TableProperties, TablePropertiesOutput, TableSizePicker, TableSizePickerOutput, TableValues, TextDirection,
|
||||
};
|
||||
pub use text_selection::{
|
||||
MarkArea, MarkKind, PageTextSource, PageTexts, TextMark, TextMarks, TextSelectState, TextSelectTool, TextSelection, TextSpan,
|
||||
};
|
||||
pub use text_selection::{PageTextSource, PageTexts, TextMark, TextMarks, TextSelectState, TextSelectTool, TextSelection, TextSpan};
|
||||
pub use thumbnails::{
|
||||
PageThumbnails, PageThumbnailsOutput, THUMBNAIL_ZOOM, ThumbnailEvent, ThumbnailMarks, ThumbnailSection, ThumbnailWords, moved_page,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
//! The rulers around one page of a [`PageView`](super::PageView): [`VerticalRuler`] with table row grips, and
|
||||
//! [`PageRulers`], which joins a [`TextRuler`](craft_text::ui::ruler::TextRuler), a [`VerticalRuler`] and
|
||||
//! [`MarginHandles`](super::MarginHandles) around the page.
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use craft_behavior::GesturePhase;
|
||||
use craft_keymap::Mods;
|
||||
use craft_text::ui::DocUnit;
|
||||
use craft_text::ui::ruler::{RulerValues, TabAlign, TextRulerOutput};
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::runtime::env::Label;
|
||||
use egui::{Rangef, Rect, Response, Ui};
|
||||
|
||||
use super::margins::{MarginHandlesOutput, PageEdges};
|
||||
use super::view::PlacedPage;
|
||||
|
||||
/// A table row grip dragged on a vertical ruler: one gesture per drag, reported with its phase.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub struct RowDrag {
|
||||
/// Where the gesture stands.
|
||||
pub phase: GesturePhase,
|
||||
/// The row whose bottom border the grip moves.
|
||||
pub index: usize,
|
||||
/// The position the pointer gives the border, points from the page's top.
|
||||
pub position: f32,
|
||||
/// The drag pass's modifiers.
|
||||
pub mods: Mods,
|
||||
}
|
||||
|
||||
/// What a [`VerticalRuler`] did this pass.
|
||||
#[non_exhaustive]
|
||||
pub struct VerticalRulerOutput {
|
||||
/// The ruler's response.
|
||||
pub response: Response,
|
||||
/// A table row grip dragged ([`VerticalRuler::rows`]).
|
||||
pub row: Option<RowDrag>,
|
||||
}
|
||||
|
||||
/// The vertical ruler of one page, with grips on the bottom borders of the caret row's table rows: the page's span is
|
||||
/// shaded as margin and the text range filled, and a drag of a grip is one gesture.
|
||||
#[must_use = "show the ruler with `show_at`"]
|
||||
pub struct VerticalRuler<'a> {
|
||||
stub: PhantomData<&'a PlacedPage>,
|
||||
}
|
||||
|
||||
impl<'a> VerticalRuler<'a> {
|
||||
/// The ruler named `label` along `page`.
|
||||
pub fn new(label: impl Into<Label>, page: &'a PlacedPage) -> Self {
|
||||
let _ = (label.into(), page);
|
||||
todo!("cv.K21")
|
||||
}
|
||||
|
||||
/// The range the text occupies, points from the page's top.
|
||||
pub fn text(self, text: Rangef) -> Self {
|
||||
let _ = (self, text);
|
||||
todo!("cv.K21")
|
||||
}
|
||||
|
||||
/// The unit the ticks and numbers show.
|
||||
pub fn unit(self, unit: DocUnit) -> Self {
|
||||
let _ = (self, unit);
|
||||
todo!("cv.K21")
|
||||
}
|
||||
|
||||
/// The table row bottoms, points from the page's top, each a grip.
|
||||
pub fn rows(self, rows: &'a [f32]) -> Self {
|
||||
let _ = (self, rows);
|
||||
todo!("cv.K21")
|
||||
}
|
||||
|
||||
/// Shows the ruler over `canvas_rect`.
|
||||
pub fn show_at(self, ui: &mut Ui, canvas_rect: Rect) -> VerticalRulerOutput {
|
||||
let _ = (self, ui, canvas_rect);
|
||||
todo!("cv.K21")
|
||||
}
|
||||
}
|
||||
|
||||
/// What [`PageRulers`] did this pass.
|
||||
#[non_exhaustive]
|
||||
pub struct PageRulersOutput {
|
||||
/// The horizontal ruler's output.
|
||||
pub ruler: TextRulerOutput,
|
||||
/// The margin handles' output.
|
||||
pub margins: MarginHandlesOutput,
|
||||
/// A table row grip dragged on the vertical ruler.
|
||||
pub row: Option<RowDrag>,
|
||||
}
|
||||
|
||||
/// The rulers around a page: the text ruler over the top band, the vertical ruler and the margin handles last, so
|
||||
/// their edges win. It shows no guides, no zero point and no units menu; `Rulers` is unchanged.
|
||||
#[must_use = "show the rulers with `show_at`"]
|
||||
pub struct PageRulers<'a> {
|
||||
stub: PhantomData<(&'a PlacedPage, &'a mut PageEdges, &'a mut RulerValues)>,
|
||||
}
|
||||
|
||||
impl<'a> PageRulers<'a> {
|
||||
/// The rulers named `label` around `page`, editing its margin `edges` and the paragraph's `ruler` values.
|
||||
pub fn new(label: impl Into<Label>, page: &'a PlacedPage, edges: Bind<'a, PageEdges>, ruler: Bind<'a, RulerValues>) -> Self {
|
||||
let _ = (label.into(), page, edges, ruler);
|
||||
todo!("cv.K22")
|
||||
}
|
||||
|
||||
/// The text column's start and end, points from the page's left.
|
||||
pub fn column(self, column: (f32, f32)) -> Self {
|
||||
let _ = (self, column);
|
||||
todo!("cv.K22")
|
||||
}
|
||||
|
||||
/// The unit the ticks and numbers show.
|
||||
pub fn unit(self, unit: DocUnit) -> Self {
|
||||
let _ = (self, unit);
|
||||
todo!("cv.K22")
|
||||
}
|
||||
|
||||
/// Shows the tab selector in the corner, with the kind a click sets.
|
||||
pub fn kind(self, kind: Option<TabAlign>) -> Self {
|
||||
let _ = (self, kind);
|
||||
todo!("cv.K22")
|
||||
}
|
||||
|
||||
/// The paragraph's direction is right to left (`true`) or left to right (`false`).
|
||||
pub fn right_to_left(self, right_to_left: Option<bool>) -> Self {
|
||||
let _ = (self, right_to_left);
|
||||
todo!("cv.K22")
|
||||
}
|
||||
|
||||
/// The caret row's table column borders, points from the column's start edge.
|
||||
pub fn columns(self, columns: &'a [f32]) -> Self {
|
||||
let _ = (self, columns);
|
||||
todo!("cv.K22")
|
||||
}
|
||||
|
||||
/// The text column gaps as (start, end) points.
|
||||
pub fn gaps(self, gaps: &'a [(f32, f32)]) -> Self {
|
||||
let _ = (self, gaps);
|
||||
todo!("cv.K22")
|
||||
}
|
||||
|
||||
/// The table row bottoms, points from the page's top.
|
||||
pub fn rows(self, rows: &'a [f32]) -> Self {
|
||||
let _ = (self, rows);
|
||||
todo!("cv.K22")
|
||||
}
|
||||
|
||||
/// Binding room added to the inside margin, points.
|
||||
pub fn gutter(self, gutter: f64) -> Self {
|
||||
let _ = (self, gutter);
|
||||
todo!("cv.K22")
|
||||
}
|
||||
|
||||
/// The page is an even page of mirrored margins.
|
||||
pub fn mirrored_even(self, mirrored_even: bool) -> Self {
|
||||
let _ = (self, mirrored_even);
|
||||
todo!("cv.K22")
|
||||
}
|
||||
|
||||
/// Shows the rulers over the canvas at `canvas_rect`.
|
||||
pub fn show_at(self, ui: &mut Ui, canvas_rect: Rect) -> PageRulersOutput {
|
||||
let _ = (self, ui, canvas_rect);
|
||||
todo!("cv.K22")
|
||||
}
|
||||
}
|
||||
@@ -442,6 +442,8 @@ pub struct ReadingNavOutput {
|
||||
pub response: Response,
|
||||
/// The state's column changed: a button turned the screen.
|
||||
pub turned: bool,
|
||||
/// The trailing button ([`ReadingNav::action`]) was clicked.
|
||||
pub action: bool,
|
||||
}
|
||||
|
||||
impl Outcome for ReadingNavOutput {
|
||||
@@ -459,12 +461,30 @@ impl Outcome for ReadingNavOutput {
|
||||
pub struct ReadingNav<'a> {
|
||||
state: &'a mut ReadingState,
|
||||
count: usize,
|
||||
#[allow(dead_code)] // P3(canvas-w5): cv.K16
|
||||
position: bool,
|
||||
#[allow(dead_code)] // P3(canvas-w5): cv.K16
|
||||
action: Option<craft_ui::runtime::env::Label>,
|
||||
}
|
||||
|
||||
impl<'a> ReadingNav<'a> {
|
||||
/// The buttons for a view of `count` columns in `state`.
|
||||
pub fn new(state: &'a mut ReadingState, count: usize) -> Self {
|
||||
ReadingNav { state, count }
|
||||
ReadingNav { state, count, position: false, action: None }
|
||||
}
|
||||
|
||||
/// Shows the "n / m" position between the buttons.
|
||||
#[must_use]
|
||||
pub fn position(mut self, shown: bool) -> Self {
|
||||
self.position = shown;
|
||||
self
|
||||
}
|
||||
|
||||
/// Adds one trailing button named `label`, reported as [`ReadingNavOutput::action`].
|
||||
#[must_use]
|
||||
pub fn action(mut self, label: impl Into<craft_ui::runtime::env::Label>) -> Self {
|
||||
self.action = Some(label.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Shows the row.
|
||||
@@ -478,6 +498,6 @@ impl<'a> ReadingNav<'a> {
|
||||
by = i32::from(clicked(&next)) - i32::from(clicked(&previous));
|
||||
});
|
||||
self.state.turn(by, count);
|
||||
ReadingNavOutput { response: row.output, turned: by != 0 }
|
||||
ReadingNavOutput { response: row.output, turned: by != 0, action: false }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -474,17 +474,30 @@ pub struct PageSetupDialog<'a> {
|
||||
/// Binds the open state to `open`.
|
||||
#[prop(name = "opened")]
|
||||
open: Option<Bind<'a, bool>>,
|
||||
/// OK files the setup in the held answer and the dialog stays open until the app answers it (`FormDialog::held`).
|
||||
#[prop(into)]
|
||||
#[allow(dead_code)] // P3(dialogs-w6): dg.F18
|
||||
held: Option<&'a mut craft_ui::dialog::HeldAnswer<PageSetup>>,
|
||||
}
|
||||
|
||||
impl<'a> PageSetupDialog<'a> {
|
||||
/// A dialog that edits `setup`, with every paper size, in inches and with no layout group.
|
||||
pub fn new(setup: Bind<'a, PageSetup>) -> Self {
|
||||
PageSetupDialog { setup, papers: PAPER_SIZES, unit: UnitKind::Inches, document_setup: false, layout: false, direction: false, open: None }
|
||||
PageSetupDialog {
|
||||
setup,
|
||||
papers: PAPER_SIZES,
|
||||
unit: UnitKind::Inches,
|
||||
document_setup: false,
|
||||
layout: false,
|
||||
direction: false,
|
||||
open: None,
|
||||
held: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Shows the dialog.
|
||||
pub fn show(self, ui: &mut Ui) -> FormOutput<PageSetup> {
|
||||
let PageSetupDialog { setup, papers, unit, document_setup, layout, direction, open } = self;
|
||||
let PageSetupDialog { setup, papers, unit, document_setup, layout, direction, open, .. } = self;
|
||||
let env = Env::of(ui);
|
||||
let words = env.words::<PageSetupDialogWords>();
|
||||
let rows = Rows { words: &words, units: env.units(), unit };
|
||||
|
||||
@@ -194,6 +194,37 @@ pub struct EdgePicker<'a> {
|
||||
#[style_key]
|
||||
#[prop(flag)]
|
||||
paragraph: bool,
|
||||
/// How the picture is drawn: the proxy diagram, or a sample of the borders on text, a paragraph or a page.
|
||||
#[prop]
|
||||
#[allow(dead_code)] // P3(dialogs-w6): dg.F19
|
||||
look: EdgeLook,
|
||||
}
|
||||
|
||||
/// How the borders preview is drawn.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub enum EdgeLook {
|
||||
/// The six-line proxy diagram.
|
||||
#[default]
|
||||
Proxy,
|
||||
/// The borders drawn as a sample.
|
||||
Sample {
|
||||
/// What the sample's borders surround.
|
||||
area: SampleArea,
|
||||
/// The fill inside the borders; none leaves the area unfilled.
|
||||
fill: Option<craft_theme::Srgba>,
|
||||
},
|
||||
}
|
||||
|
||||
/// What a sample of borders surrounds.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum SampleArea {
|
||||
/// A run of text.
|
||||
Text,
|
||||
/// A paragraph.
|
||||
Paragraph,
|
||||
/// A page.
|
||||
Page,
|
||||
}
|
||||
|
||||
/// The click run on the picker: the line the last click hit and the choice before the run's first click.
|
||||
@@ -206,7 +237,7 @@ struct ClickRun {
|
||||
impl<'a> EdgePicker<'a> {
|
||||
/// A picker named `label` editing `edges`.
|
||||
pub fn new(label: impl Into<Label>, edges: Bind<'a, BorderEdges>) -> Self {
|
||||
EdgePicker { common: Common::new(), edges, paragraph: false }.label(label).ltr_axis()
|
||||
EdgePicker { common: Common::new(), edges, paragraph: false, look: EdgeLook::default() }.label(label).ltr_axis()
|
||||
}
|
||||
|
||||
/// The name of `edge`.
|
||||
|
||||
@@ -9,7 +9,7 @@ pub mod size_picker;
|
||||
#[cfg(feature = "screen-testing")]
|
||||
mod stories;
|
||||
|
||||
pub use edges::{BorderEdges, BorderPreset, EdgeKey, EdgePicker, EdgePickerStyle, EdgePickerWords};
|
||||
pub use edges::{BorderEdges, BorderPreset, EdgeKey, EdgeLook, EdgePicker, EdgePickerStyle, EdgePickerWords, SampleArea};
|
||||
pub use properties::{CellAlign, RowHeight, TableChange, TableProperties, TablePropertiesOutput, TablePropertiesWords, TableValues, TextDirection};
|
||||
pub use selection::{CellSelectionOverlay, CellSelectionStyle, TableGeometry};
|
||||
pub use size_picker::{TableSizePicker, TableSizePickerOutput, TableSizePickerStyle, TableSizePickerWords};
|
||||
|
||||
@@ -501,12 +501,55 @@ pub struct TextMarks<'a> {
|
||||
/// The text selection to paint with the marks.
|
||||
#[prop]
|
||||
selection: Option<TextSelection>,
|
||||
/// The areas to mark, in page points: selection, find and Read Aloud marks that are not glyph ranges.
|
||||
#[prop]
|
||||
areas: &'a [MarkArea],
|
||||
}
|
||||
|
||||
/// What a [`MarkArea`] marks; each kind has its [`MarkLook`] fill.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub enum MarkKind {
|
||||
/// A selection.
|
||||
Selection,
|
||||
/// A find match.
|
||||
Found,
|
||||
/// The current find match.
|
||||
Current,
|
||||
/// The text Read Aloud speaks.
|
||||
Spoken,
|
||||
}
|
||||
|
||||
/// A rectangle of a page to mark, in page points.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub struct MarkArea {
|
||||
/// The page index, 0-based.
|
||||
pub page: usize,
|
||||
/// The area in page points.
|
||||
pub rect: craft_behavior::kurbo::Rect,
|
||||
/// What it marks.
|
||||
pub kind: MarkKind,
|
||||
}
|
||||
|
||||
impl MarkArea {
|
||||
/// The area `rect` of `page`, marking `kind`.
|
||||
pub fn new(page: usize, rect: craft_behavior::kurbo::Rect, kind: MarkKind) -> Self {
|
||||
let _ = (page, rect, kind);
|
||||
todo!("cv.K17")
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TextMarks<'a> {
|
||||
/// The `marks` over the placed `pages`, whose text `texts` gives.
|
||||
pub fn new(pages: &'a [PlacedPage], texts: &'a dyn PageTexts, marks: &'a [TextMark]) -> Self {
|
||||
TextMarks { common: Common::new(), pages, texts, marks, selection: None }
|
||||
TextMarks { common: Common::new(), pages, texts, marks, selection: None, areas: &[] }
|
||||
}
|
||||
|
||||
/// Marks for [`areas`](Self::areas) alone over the placed `pages`, with no text source.
|
||||
pub fn over(pages: &'a [PlacedPage]) -> Self {
|
||||
let _ = pages;
|
||||
todo!("cv.K17")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,10 +30,11 @@ use crate::layout::{
|
||||
use craft_behavior::kurbo::{Point, Rect as DocRect, Size};
|
||||
use craft_behavior::{CanvasView, MoveMods, NavMove, PressPhase, WheelNotch, ZoomLadder};
|
||||
use craft_ui::canvas::{
|
||||
BodyKeys, Canvas, CanvasOutput, CanvasScrollbars, NavigationOptions, PageFrame, PageKey, Pasteboard, PasteboardOutput, ToolPass, canvas_space,
|
||||
tool_pass,
|
||||
BodyKeys, Canvas, CanvasOutput, CanvasScrollbars, NavigationOptions, PageFrame, PageKey, Pasteboard, PasteboardOutput, Snap, ToolPass,
|
||||
ToolRegion, canvas_space, tool_pass,
|
||||
};
|
||||
use craft_ui::contract::{Bind, BodyCx, Held, Props as _, Show as _, ShowContainer as _};
|
||||
use craft_ui::primitives::EditorPurpose;
|
||||
use craft_ui::primitives::textures::ThumbSource;
|
||||
use craft_ui::runtime::env::{Env, Label};
|
||||
use craft_ui::runtime::memory::Remember as _;
|
||||
@@ -167,6 +168,18 @@ impl PlacedPage {
|
||||
pub fn to_page(&self, p: egui::Pos2) -> Point {
|
||||
Point::new(f64::from(p.x - self.rect.min.x) / self.scale, f64::from(p.y - self.rect.min.y) / self.scale)
|
||||
}
|
||||
|
||||
/// Page point `p` to document coordinates of `view`.
|
||||
pub fn to_doc(&self, view: &CanvasView, p: Point) -> Point {
|
||||
let _ = (view, p);
|
||||
todo!("cv.K19")
|
||||
}
|
||||
|
||||
/// Document point `d` of `view` to page coordinates.
|
||||
pub fn from_doc(&self, view: &CanvasView, d: Point) -> Point {
|
||||
let _ = (view, d);
|
||||
todo!("cv.K19")
|
||||
}
|
||||
}
|
||||
|
||||
/// What the page view's canvas body hands the app's canvas controls (margins, zones, marks, grids, cell overlay,
|
||||
@@ -185,6 +198,14 @@ pub struct PageBody<'b> {
|
||||
pub pass: Option<&'b ToolPass>,
|
||||
}
|
||||
|
||||
impl PageBody<'_> {
|
||||
/// The page under document point `d` and the point in its coordinates; the nearest page when `d` is outside all.
|
||||
pub fn page_at_doc(&self, d: Point) -> Option<(&PlacedPage, Point)> {
|
||||
let _ = d;
|
||||
todo!("cv.K19")
|
||||
}
|
||||
}
|
||||
|
||||
/// What the view did this pass.
|
||||
#[derive(Debug)]
|
||||
#[non_exhaustive]
|
||||
@@ -251,6 +272,14 @@ pub struct PageView<'a> {
|
||||
bodies: Option<&'a [(f64, f64)]>,
|
||||
describer: Option<&'a dyn AccessDescriber>,
|
||||
paper: DataColor,
|
||||
#[allow(dead_code)] // P3(canvas-w5): cv.K14
|
||||
editor: Option<EditorPurpose>,
|
||||
#[allow(dead_code)] // P3(canvas-w5): cv.K18
|
||||
snap: Option<Snap>,
|
||||
#[allow(dead_code)] // P3(canvas-w5): cv.K18
|
||||
tool_regions: Vec<ToolRegion>,
|
||||
#[allow(dead_code)] // P3(canvas-w5): cv.K20
|
||||
rulers: bool,
|
||||
}
|
||||
|
||||
impl<'a> PageView<'a> {
|
||||
@@ -266,6 +295,10 @@ impl<'a> PageView<'a> {
|
||||
bodies: None,
|
||||
describer: None,
|
||||
paper,
|
||||
editor: None,
|
||||
snap: None,
|
||||
tool_regions: Vec::new(),
|
||||
rulers: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,6 +330,33 @@ impl<'a> PageView<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Registers the canvas's editor part of `purpose`; the view's keys give it none.
|
||||
#[must_use]
|
||||
pub fn editor(mut self, purpose: EditorPurpose) -> Self {
|
||||
self.editor = Some(purpose);
|
||||
self
|
||||
}
|
||||
|
||||
/// The snapping of the coordinates the pointer sets on the view, passed to the inner canvas.
|
||||
#[must_use]
|
||||
pub fn snap(mut self, snap: Option<Snap>) -> Self {
|
||||
self.snap = snap;
|
||||
self
|
||||
}
|
||||
|
||||
/// The areas where the active tool takes a press over the canvas controls, passed to the inner canvas.
|
||||
#[must_use]
|
||||
pub fn tool_regions(mut self, regions: Vec<ToolRegion>) -> Self {
|
||||
self.tool_regions = regions;
|
||||
self
|
||||
}
|
||||
|
||||
/// Shows the rulers along the top and left edges: the inner canvas's `show_rulers`, which insets the view.
|
||||
pub fn rulers(mut self, on: bool) -> Self {
|
||||
self.rulers = on;
|
||||
self
|
||||
}
|
||||
|
||||
/// Shows the view in the room left in `ui`, and runs `body` for the app's canvas controls (margins, zones,
|
||||
/// marks, grids), which it shows with `show_at(ui, body.rect)`, and its tool host, which runs on `body.pass`.
|
||||
/// `body` runs on every run of the canvas body (the measuring run and the real one), so it builds what it shows
|
||||
@@ -312,7 +372,7 @@ impl<'a> PageView<'a> {
|
||||
}
|
||||
|
||||
fn run(self, ui: &mut Ui, rect: Rect, take_room: bool, mut body: impl FnMut(&mut Ui, &PageBody<'_>)) -> PageViewOutput {
|
||||
let PageView { label, source, state, options, navigation, bodies, describer, paper } = self;
|
||||
let PageView { label, source, state, options, navigation, bodies, describer, paper, .. } = self;
|
||||
let spacing = PageMetrics::new().show_at(ui, Rect::from_min_size(rect.min, Vec2::ZERO)).spacing;
|
||||
let count = source.page_count();
|
||||
let sizes: Vec<Size> = (0..count).map(|page| source.page_size(page)).collect();
|
||||
@@ -650,6 +710,8 @@ craft_ui::words! {
|
||||
scroll_bars: "pageView.scrollBars" = "Scroll bars";
|
||||
edit: "pageView.edit" = "Change view";
|
||||
text: "pageView.text" = "Page text";
|
||||
/// The tip beside the vertical scroll bar's thumb while it is dragged.
|
||||
page_of: template "pageView.pageOf" = "Page {page} of {count}";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,8 +38,8 @@ mod style_options;
|
||||
|
||||
pub use paragraph::{ParagraphChange, ParagraphControls, ParagraphControlsOutput, ParagraphDirection, ParagraphValues, ParagraphWords, TextAlign};
|
||||
pub use paragraph_dialog::{
|
||||
LineSpacing, ParagraphAlign, ParagraphAnswer, ParagraphDialog, ParagraphDialogWords, ParagraphFormat, ParagraphPreview, ParagraphPreviewStyle,
|
||||
SpacingKind, SpecialIndent,
|
||||
AsianTypography, LineBreakOptions, LineSpacing, ParagraphAlign, ParagraphAnswer, ParagraphDialog, ParagraphDialogWords, ParagraphFormat,
|
||||
ParagraphPreview, ParagraphPreviewStyle, ParagraphTab, SpacingKind, SpecialIndent,
|
||||
};
|
||||
use rows::{
|
||||
LengthRow, Lengths, PlainRow, Toggle, agree, family_field, hidden_side, leading_menu, leading_row, mark, mixed, number_change, number_presets,
|
||||
|
||||
@@ -77,7 +77,7 @@ impl TextAlign {
|
||||
}
|
||||
|
||||
/// A paragraph's direction.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
#[non_exhaustive]
|
||||
pub enum ParagraphDirection {
|
||||
/// From the paragraph's first strong character.
|
||||
|
||||
@@ -158,6 +158,62 @@ pub struct ParagraphFormat {
|
||||
pub space_after_kind: SpacingKind,
|
||||
/// The line spacing rule and its value.
|
||||
pub line_spacing: Option<LineSpacing>,
|
||||
/// The paragraph's direction. The outer `None` hides the row; `Some(None)` shows it empty, for paragraphs that
|
||||
/// differ.
|
||||
pub direction: Option<Option<super::ParagraphDirection>>,
|
||||
/// Mirror indents: Left and Right read Inside and Outside when on. The outer `None` hides it; `Some(None)` is mixed.
|
||||
pub mirror_indents: Option<Option<bool>>,
|
||||
/// The Line and Page Breaks check boxes. `None` hides the page.
|
||||
pub breaks: Option<LineBreakOptions>,
|
||||
/// The Asian Typography check boxes. `None` hides the page.
|
||||
pub asian: Option<AsianTypography>,
|
||||
}
|
||||
|
||||
/// The Line and Page Breaks check boxes of Word's Paragraph dialog; `None` is a box whose paragraphs differ, shown
|
||||
/// mixed, and a click makes it checked.
|
||||
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct LineBreakOptions {
|
||||
/// Widow/orphan control.
|
||||
pub widow_control: Option<bool>,
|
||||
/// Keep with next.
|
||||
pub keep_with_next: Option<bool>,
|
||||
/// Keep lines together.
|
||||
pub keep_lines_together: Option<bool>,
|
||||
/// Page break before.
|
||||
pub page_break_before: Option<bool>,
|
||||
/// Suppress line numbers.
|
||||
pub suppress_line_numbers: Option<bool>,
|
||||
/// Don't hyphenate.
|
||||
pub dont_hyphenate: Option<bool>,
|
||||
}
|
||||
|
||||
/// The Asian Typography check boxes of Word's Paragraph dialog, mixed as [`LineBreakOptions`] is.
|
||||
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct AsianTypography {
|
||||
/// Apply East Asian line-break rules (kinsoku).
|
||||
pub kinsoku: Option<bool>,
|
||||
/// Allow Latin text to wrap in the middle of a word.
|
||||
pub word_wrap: Option<bool>,
|
||||
/// Allow punctuation to hang past the margin.
|
||||
pub overflow_punct: Option<bool>,
|
||||
/// Allow punctuation at the start of a line.
|
||||
pub top_line_punct: Option<bool>,
|
||||
/// Automatically space East Asian and Latin text.
|
||||
pub auto_space_de: Option<bool>,
|
||||
/// Automatically space East Asian text and numbers.
|
||||
pub auto_space_dn: Option<bool>,
|
||||
}
|
||||
|
||||
/// The page of Word's Paragraph dialog the dialog opens on.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub enum ParagraphTab {
|
||||
/// Indents and Spacing.
|
||||
#[default]
|
||||
IndentsAndSpacing,
|
||||
/// Line and Page Breaks.
|
||||
LineAndPageBreaks,
|
||||
/// Asian Typography.
|
||||
AsianTypography,
|
||||
}
|
||||
|
||||
/// OK's answer: the format, and whether Tabs… was pressed (the app applies the format, then opens
|
||||
@@ -193,12 +249,27 @@ pub struct ParagraphDialog {
|
||||
word: bool,
|
||||
/// The format the dialog opened with: a spacing that returns to its value takes its kind back.
|
||||
opened: ParagraphFormat,
|
||||
#[allow(dead_code)] // P3(dialogs-w3): dg.F9
|
||||
tab: ParagraphTab,
|
||||
}
|
||||
|
||||
impl ParagraphDialog {
|
||||
/// A dialog editing `format`, with lengths in inches.
|
||||
pub fn new(format: ParagraphFormat) -> Self {
|
||||
ParagraphDialog { opened: format.clone(), format, unit: DocUnit::new(UnitKind::Inches, UnitKind::POINTS_PER_INCH), word: false }
|
||||
ParagraphDialog {
|
||||
opened: format.clone(),
|
||||
format,
|
||||
unit: DocUnit::new(UnitKind::Inches, UnitKind::POINTS_PER_INCH),
|
||||
word: false,
|
||||
tab: ParagraphTab::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens the dialog on `tab`; Word's form with line-break and Asian typography options shows the three pages.
|
||||
#[must_use]
|
||||
pub fn tab(mut self, tab: ParagraphTab) -> Self {
|
||||
self.tab = tab;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the unit the length fields show.
|
||||
@@ -580,6 +651,25 @@ impl ParagraphDialog {
|
||||
}
|
||||
}
|
||||
|
||||
impl ParagraphDialog {
|
||||
/// OK files its answer for the app to accept or refuse before the dialog closes.
|
||||
#[must_use]
|
||||
pub fn held_ok(self) -> Self {
|
||||
todo!("dg.F12")
|
||||
}
|
||||
|
||||
/// The answer OK filed, once, for the app to judge.
|
||||
pub fn take_ok(&mut self) -> Option<ParagraphAnswer> {
|
||||
todo!("dg.F12")
|
||||
}
|
||||
|
||||
/// The app's answer to the filed answer: `Ok` closes the dialog with it, `Err` shows the reason and enables OK.
|
||||
pub fn answer_ok(&mut self, answer: Result<(), Label>) {
|
||||
let _ = answer;
|
||||
todo!("dg.F12")
|
||||
}
|
||||
}
|
||||
|
||||
impl StackDialog for ParagraphDialog {
|
||||
type Result = ParagraphAnswer;
|
||||
|
||||
|
||||
@@ -593,6 +593,25 @@ fn bare(caption: &str) -> &str {
|
||||
caption.trim_end_matches([':', '\u{ff1a}'])
|
||||
}
|
||||
|
||||
impl TextColumnsDialog {
|
||||
/// OK files its result for the app to accept or refuse before the dialog closes.
|
||||
#[must_use]
|
||||
pub fn held_ok(self) -> Self {
|
||||
todo!("dg.F12")
|
||||
}
|
||||
|
||||
/// The result OK filed, once, for the app to judge.
|
||||
pub fn take_ok(&mut self) -> Option<Option<TextColumns>> {
|
||||
todo!("dg.F12")
|
||||
}
|
||||
|
||||
/// The app's answer to the filed result: `Ok` closes the dialog with it, `Err` shows the reason and enables OK.
|
||||
pub fn answer_ok(&mut self, answer: Result<(), Label>) {
|
||||
let _ = answer;
|
||||
todo!("dg.F12")
|
||||
}
|
||||
}
|
||||
|
||||
impl StackDialog for TextColumnsDialog {
|
||||
/// The fields that changed; `None` when none did (OK applies nothing).
|
||||
type Result = Option<TextColumns>;
|
||||
|
||||
@@ -10,7 +10,7 @@ mod bar;
|
||||
mod dialog;
|
||||
|
||||
pub use bar::{FindBar, FindBarOutput, FindBarState, FindStep};
|
||||
pub use dialog::{FindReplaceDialog, FindRequest, FindTab};
|
||||
pub use dialog::{FindReplaceDialog, FindRequest, FindTab, GoToKind, GoToTarget};
|
||||
|
||||
use crate::find::{FindError, MAX_COUNT, MAX_PATTERN, RegexError, WildcardError};
|
||||
|
||||
|
||||
@@ -82,6 +82,60 @@ pub enum FindRequest {
|
||||
/// The typed target, such as a page number.
|
||||
target: String,
|
||||
},
|
||||
/// Next or Previous on an empty Go To target of a [`GoToTarget::Typed`] kind that steps.
|
||||
#[non_exhaustive]
|
||||
GoToStep {
|
||||
/// Index into the Go To kinds.
|
||||
kind: usize,
|
||||
/// `true` for Next, `false` for Previous.
|
||||
forward: bool,
|
||||
},
|
||||
}
|
||||
|
||||
/// One Go To kind and its target.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub struct GoToKind {
|
||||
/// The kind's name in the Go to what list.
|
||||
pub label: String,
|
||||
/// What the target field is.
|
||||
pub target: GoToTarget,
|
||||
}
|
||||
|
||||
impl GoToKind {
|
||||
/// A kind whose target is typed, with `hint` as the field's help line; with `steps`, an empty field turns the
|
||||
/// accept button into Next and adds Previous.
|
||||
pub fn typed(label: impl Into<String>, hint: impl Into<Label>, steps: bool) -> Self {
|
||||
let _ = (label.into(), hint.into(), steps);
|
||||
todo!("dg.F25")
|
||||
}
|
||||
|
||||
/// A kind whose target is picked from `names`; with none, `empty` shows as the help line and Go To is disabled.
|
||||
pub fn named(label: impl Into<String>, names: Vec<String>, empty: impl Into<Label>) -> Self {
|
||||
let _ = (label.into(), names, empty.into());
|
||||
todo!("dg.F25")
|
||||
}
|
||||
}
|
||||
|
||||
/// What a Go To kind's target is.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub enum GoToTarget {
|
||||
/// A text field with `hint` as its help line; with `steps`, an empty field turns the accept button into Next and
|
||||
/// adds Previous.
|
||||
Typed {
|
||||
/// The help line.
|
||||
hint: Label,
|
||||
/// Whether an empty target steps.
|
||||
steps: bool,
|
||||
},
|
||||
/// A `Select` over `names`; with none, `empty` shows as the help line and Go To is disabled.
|
||||
Named {
|
||||
/// The names to pick from.
|
||||
names: Vec<String>,
|
||||
/// The help line when there are no names.
|
||||
empty: Label,
|
||||
},
|
||||
}
|
||||
|
||||
impl FindRequest {
|
||||
@@ -109,6 +163,11 @@ impl FindRequest {
|
||||
pub fn go_to(kind: usize, target: impl Into<String>) -> Self {
|
||||
FindRequest::GoTo { kind, target: target.into() }
|
||||
}
|
||||
|
||||
/// Step Go To to the next (`forward`) or previous target of the kind at index `kind`.
|
||||
pub fn go_to_step(kind: usize, forward: bool) -> Self {
|
||||
FindRequest::GoToStep { kind, forward }
|
||||
}
|
||||
}
|
||||
|
||||
/// The two text fields of the Find and Replace tabs.
|
||||
@@ -146,7 +205,9 @@ pub struct FindReplaceDialog {
|
||||
tab: FindTab,
|
||||
word: bool,
|
||||
more: bool,
|
||||
go_to_kinds: Vec<String>,
|
||||
go_to_kinds: Vec<GoToKind>,
|
||||
#[allow(dead_code)] // P3(dialogs-w4): dg.F25
|
||||
highlighted: bool,
|
||||
message: String,
|
||||
request: Option<FindRequest>,
|
||||
/// The field that last had the keyboard: where Special inserts.
|
||||
@@ -168,6 +229,7 @@ impl FindReplaceDialog {
|
||||
word: false,
|
||||
more: false,
|
||||
go_to_kinds: Vec::new(),
|
||||
highlighted: false,
|
||||
message: String::new(),
|
||||
request: None,
|
||||
last_field: Field::Find,
|
||||
@@ -194,11 +256,18 @@ impl FindReplaceDialog {
|
||||
|
||||
/// Go To's kinds (Page, Section, Line, Bookmark, Comment, …), the app's.
|
||||
#[must_use]
|
||||
pub fn go_to_kinds(mut self, kinds: Vec<String>) -> Self {
|
||||
pub fn go_to_kinds(mut self, kinds: Vec<GoToKind>) -> Self {
|
||||
self.go_to_kinds = kinds;
|
||||
self
|
||||
}
|
||||
|
||||
/// The Find tab opens with Reading Highlight on (Clear highlight enabled); the app passes its session state.
|
||||
#[must_use]
|
||||
pub fn highlighted(mut self, on: bool) -> Self {
|
||||
self.highlighted = on;
|
||||
self
|
||||
}
|
||||
|
||||
/// The request the user made since the last call, if any.
|
||||
pub fn take_request(&mut self) -> Option<FindRequest> {
|
||||
self.request.take()
|
||||
@@ -217,6 +286,19 @@ impl StackDialog for FindReplaceDialog {
|
||||
dialog_id("find-replace")
|
||||
}
|
||||
|
||||
fn modeless(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn json_fields(&self) -> Option<serde_json::Value> {
|
||||
todo!("dg.F25")
|
||||
}
|
||||
|
||||
fn set_json_field(&mut self, _: &egui::Context, field: &str, value: serde_json::Value) -> Result<(), String> {
|
||||
let _ = (field, value);
|
||||
todo!("dg.F25")
|
||||
}
|
||||
|
||||
fn show(&mut self, ui: &mut Ui, _stack: &DialogStack) -> Option<DialogResult<()>> {
|
||||
let words = Env::of(ui).words::<FindLabels>();
|
||||
let (word, tab) = (self.word, self.tab);
|
||||
@@ -271,7 +353,7 @@ impl StackDialog for FindReplaceDialog {
|
||||
}
|
||||
if tab == FindTab::GoTo {
|
||||
Text::new(words.go_to_what.clone()).show(ui);
|
||||
let entries: Vec<Entry<usize>> = kinds.iter().enumerate().map(|(at, kind)| Entry::new(at, kind.clone())).collect();
|
||||
let entries: Vec<Entry<usize>> = kinds.iter().enumerate().map(|(at, kind)| Entry::new(at, kind.label.clone())).collect();
|
||||
let edit = Select::new(words.go_to_what.clone(), Bind::given(go_kind.min(kinds.len().saturating_sub(1))), &entries).show(ui);
|
||||
if let Some(value) = edit.events.value() {
|
||||
go_kind = *value;
|
||||
@@ -336,7 +418,7 @@ impl StackDialog for FindReplaceDialog {
|
||||
check(ui, &words.ignore_punctuation.clone(), &mut options.ignore_punctuation, free);
|
||||
check(ui, &words.ignore_space.clone(), &mut options.ignore_space, free);
|
||||
check(ui, &words.regular_expressions.clone(), &mut options.regex, true);
|
||||
let entries = special_entries(&words, tab == FindTab::Replace);
|
||||
let entries = special_entries(&words, tab == FindTab::Replace, options.wildcards);
|
||||
let button = Button::new(words.special.clone()).show(ui);
|
||||
if let Some(code) = Menu::new(words.special.clone()).opened_by(&button, Trigger::Press).pick(ui, &entries).picked {
|
||||
let field = if last_field == Field::With && tab == FindTab::Replace { Field::With } else { Field::Find };
|
||||
@@ -382,7 +464,8 @@ impl StackDialog for FindReplaceDialog {
|
||||
}
|
||||
|
||||
/// The Special menu: the `^` codes of Find what, or of Replace with.
|
||||
fn special_entries(words: &FindLabels, replacing: bool) -> Vec<Entry<&'static str>> {
|
||||
fn special_entries(words: &FindLabels, replacing: bool, wildcards: bool) -> Vec<Entry<&'static str>> {
|
||||
let _ = wildcards; // P3(dialogs-w4): dg.F25
|
||||
let find: [(&str, &'static str); 14] = [
|
||||
(words.paragraph_mark.as_str(), "^p"),
|
||||
(words.tab_character.as_str(), "^t"),
|
||||
|
||||
@@ -4,7 +4,7 @@ use craft_ui::dialog::{DialogStack, StackDialog as _};
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
|
||||
use super::{FindBar, FindReplaceDialog, FindTab};
|
||||
use super::{FindBar, FindReplaceDialog, FindTab, GoToKind, GoToTarget};
|
||||
use crate::find::{FindMatches, FindOptions, FindPattern, MAX_COUNT};
|
||||
|
||||
fn matches(text: &str, query: &str) -> FindMatches {
|
||||
@@ -42,7 +42,9 @@ fn refused_pattern(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
/// The Word layout of the dialog on `tab`, with "craft" in Find what, while `open`. The dialog keeps what is typed
|
||||
/// in it until it closes; the card's Show dialog opens a fresh one.
|
||||
fn dialog(ui: &mut Ui, data: &mut StoryData, tab: FindTab) -> StoryOutput {
|
||||
let fresh = || FindReplaceDialog::new("craft", tab).word(true).go_to_kinds(vec!["Page".into(), "Line".into()]);
|
||||
// P3(dialogs-w4): dg.F25 (`GoToKind::typed` is a `todo!`, so the kinds are built as the struct)
|
||||
let kind = |label: &str| GoToKind { label: label.to_owned(), target: GoToTarget::Typed { hint: "".into(), steps: false } };
|
||||
let fresh = || FindReplaceDialog::new("craft", tab).word(true).go_to_kinds(vec![kind("Page"), kind("Line")]);
|
||||
if !*data.value("open", true) {
|
||||
return StoryOutput::default();
|
||||
}
|
||||
|
||||
@@ -308,6 +308,55 @@ pub struct HyperlinkDialog {
|
||||
given: Given,
|
||||
form: Form,
|
||||
open: bool,
|
||||
#[allow(dead_code)] // P3(dialogs-w4): dg.F24
|
||||
parts: HyperlinkParts,
|
||||
}
|
||||
|
||||
/// One place in the document a link may go to.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub struct LinkPlace {
|
||||
/// The place's name.
|
||||
pub name: String,
|
||||
/// How deep it is nested under its group's title; the list indents each level.
|
||||
pub level: u8,
|
||||
}
|
||||
|
||||
impl LinkPlace {
|
||||
/// A place named `name` at nesting `level`.
|
||||
pub fn new(name: impl Into<String>, level: u8) -> Self {
|
||||
let _ = (name.into(), level);
|
||||
todo!("dg.F24")
|
||||
}
|
||||
}
|
||||
|
||||
/// Places under a heading row in the Place in This Document list (Headings, Bookmarks).
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub struct LinkPlaceGroup {
|
||||
/// The heading row.
|
||||
pub title: Label,
|
||||
/// The group's places.
|
||||
pub places: Vec<LinkPlace>,
|
||||
}
|
||||
|
||||
impl LinkPlaceGroup {
|
||||
/// A group of `places` under `title`.
|
||||
pub fn new(title: impl Into<Label>, places: Vec<LinkPlace>) -> Self {
|
||||
let _ = (title.into(), places);
|
||||
todo!("dg.F24")
|
||||
}
|
||||
}
|
||||
|
||||
/// Which parts of the hyperlink dialog show.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub enum HyperlinkParts {
|
||||
/// Every part.
|
||||
#[default]
|
||||
All,
|
||||
/// Without the ScreenTip row.
|
||||
NoScreenTip,
|
||||
}
|
||||
|
||||
impl HyperlinkDialog {
|
||||
@@ -315,7 +364,12 @@ impl HyperlinkDialog {
|
||||
/// the field: a shape's click action).
|
||||
pub fn new(current: CurrentLink, text: Option<String>) -> Self {
|
||||
let form = Form::of(¤t, text.as_deref());
|
||||
HyperlinkDialog { given: Given { current, text, places: Vec::new(), highlight: false, seed: form.clone() }, form, open: true }
|
||||
HyperlinkDialog {
|
||||
given: Given { current, text, places: Vec::new(), highlight: false, seed: form.clone() },
|
||||
form,
|
||||
open: true,
|
||||
parts: HyperlinkParts::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The places in the document a link may go to, after Top of the Document (which the dialog always lists, as
|
||||
@@ -326,6 +380,21 @@ impl HyperlinkDialog {
|
||||
self
|
||||
}
|
||||
|
||||
/// The places in the document a link may go to, in groups under a heading each, after Top of the Document.
|
||||
/// [`LinkTarget::Place`] indexes the places in group order.
|
||||
#[must_use]
|
||||
pub fn place_groups(self, groups: Vec<LinkPlaceGroup>) -> Self {
|
||||
let _ = groups;
|
||||
todo!("dg.F24")
|
||||
}
|
||||
|
||||
/// Which parts of the dialog show.
|
||||
#[must_use]
|
||||
pub fn parts(mut self, parts: HyperlinkParts) -> Self {
|
||||
self.parts = parts;
|
||||
self
|
||||
}
|
||||
|
||||
/// Shows the Highlight click option.
|
||||
#[must_use]
|
||||
pub fn highlight_click(mut self, on: bool) -> Self {
|
||||
@@ -335,7 +404,7 @@ impl HyperlinkDialog {
|
||||
|
||||
/// Shows the dialog.
|
||||
pub fn show(&mut self, ui: &mut Ui) -> HyperlinkOutput {
|
||||
let HyperlinkDialog { given, form, open } = self;
|
||||
let HyperlinkDialog { given, form, open, .. } = self;
|
||||
let env = Env::of(ui);
|
||||
let words = env.words::<HyperlinkWords>();
|
||||
let common = env.words::<CommonWords>();
|
||||
@@ -427,6 +496,25 @@ fn place_list(ui: &mut Ui, given: &Given, form: &mut Form, words: &HyperlinkWord
|
||||
});
|
||||
}
|
||||
|
||||
impl HyperlinkDialog {
|
||||
/// OK files its answer for the app to accept or refuse before the dialog closes.
|
||||
#[must_use]
|
||||
pub fn held_ok(self) -> Self {
|
||||
todo!("dg.F12")
|
||||
}
|
||||
|
||||
/// The answer OK filed, once, for the app to judge.
|
||||
pub fn take_ok(&mut self) -> Option<HyperlinkAnswer> {
|
||||
todo!("dg.F12")
|
||||
}
|
||||
|
||||
/// The app's answer to the filed answer: `Ok` closes the dialog with it, `Err` shows the reason and enables OK.
|
||||
pub fn answer_ok(&mut self, answer: Result<(), Label>) {
|
||||
let _ = answer;
|
||||
todo!("dg.F12")
|
||||
}
|
||||
}
|
||||
|
||||
impl StackDialog for HyperlinkDialog {
|
||||
type Result = HyperlinkAnswer;
|
||||
|
||||
|
||||
@@ -204,6 +204,31 @@ pub struct ColumnDrag {
|
||||
pub phase: GesturePhase,
|
||||
/// The border and the position the pointer gives it.
|
||||
pub border: ColumnBorder,
|
||||
/// The drag pass's modifiers.
|
||||
pub mods: craft_keymap::Mods,
|
||||
}
|
||||
|
||||
/// Which edge of a column gap a [`GapDrag`] moves.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum GapEdge {
|
||||
/// The end edge of the column before the gap.
|
||||
End,
|
||||
/// The start edge of the column after the gap.
|
||||
Start,
|
||||
}
|
||||
|
||||
/// A column gap edge drag: one gesture per drag, reported with its phase.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub struct GapDrag {
|
||||
/// Where the gesture stands.
|
||||
pub phase: GesturePhase,
|
||||
/// The gap in [`TextRuler::gaps`] being dragged.
|
||||
pub index: usize,
|
||||
/// The edge of the gap the pointer moves.
|
||||
pub edge: GapEdge,
|
||||
/// The position the pointer gives the edge, points from the column's start edge.
|
||||
pub position: f32,
|
||||
}
|
||||
|
||||
/// What the ruler did this pass.
|
||||
@@ -217,6 +242,8 @@ pub struct TextRulerOutput {
|
||||
pub open_tabs_dialog: bool,
|
||||
/// A table column border dragged ([`TextRuler::columns`]).
|
||||
pub column: Option<ColumnDrag>,
|
||||
/// A column gap edge dragged ([`TextRuler::gaps`]).
|
||||
pub gap: Option<GapDrag>,
|
||||
/// The kind the tab selector was clicked to: the next kind, the previous one for a secondary click.
|
||||
pub kind: Option<TabAlign>,
|
||||
}
|
||||
@@ -240,6 +267,7 @@ pub(super) struct Report {
|
||||
pub(super) picked: Option<usize>,
|
||||
pub(super) open_tabs_dialog: bool,
|
||||
pub(super) column: Option<ColumnDrag>,
|
||||
pub(super) gap: Option<GapDrag>,
|
||||
pub(super) kind: Option<TabAlign>,
|
||||
}
|
||||
|
||||
@@ -325,6 +353,16 @@ pub struct TextRuler<'a> {
|
||||
/// the right edge of each cell. Empty (the default) when the caret is not in a table.
|
||||
#[prop]
|
||||
columns: &'a [f32],
|
||||
/// The column gaps as (start, end) points from the column's start edge, painted and dragged by their edges.
|
||||
#[prop]
|
||||
gaps: &'a [(f32, f32)],
|
||||
/// Where the ruler's zero sits, points from the strip's start edge: a page-wide ruler is measured from the page's
|
||||
/// text origin.
|
||||
#[prop]
|
||||
origin: f32,
|
||||
/// The part of the strip the ruler covers, points from the strip's start edge; the ruler is cut to it.
|
||||
#[prop]
|
||||
extent: Option<egui::Rangef>,
|
||||
/// The unit the markers' values and the ticks show.
|
||||
#[prop]
|
||||
unit: DocUnit,
|
||||
@@ -353,6 +391,9 @@ impl<'a> TextRuler<'a> {
|
||||
value,
|
||||
width: if width.is_finite() { width.max(0.0) } else { 0.0 },
|
||||
columns: &[],
|
||||
gaps: &[],
|
||||
origin: 0.0,
|
||||
extent: None,
|
||||
unit: DocUnit::points(),
|
||||
kind: None,
|
||||
scale: None,
|
||||
@@ -545,7 +586,7 @@ impl Component for TextRuler<'_> {
|
||||
}
|
||||
|
||||
fn finish(self, cx: Cx<'_, Self>) -> TextRulerOutput {
|
||||
let Report { picked, open_tabs_dialog, column, kind } = self.report;
|
||||
TextRulerOutput { edit: cx.edit_response(), picked, open_tabs_dialog, column, kind }
|
||||
let Report { picked, open_tabs_dialog, column, gap, kind } = self.report;
|
||||
TextRulerOutput { edit: cx.edit_response(), picked, open_tabs_dialog, column, gap, kind }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,7 +260,8 @@ impl TextRuler<'_> {
|
||||
let (lo, hi) = g.span();
|
||||
for (index, position) in self.columns.iter().copied().enumerate() {
|
||||
let press = cx.part(COLUMN.at(index as u64)).press;
|
||||
let report = |phase: GesturePhase, position: f32| Some(ColumnDrag { phase, border: ColumnBorder { index, position } });
|
||||
let report =
|
||||
|phase: GesturePhase, position: f32| Some(ColumnDrag { phase, border: ColumnBorder { index, position }, mods: Default::default() });
|
||||
match press.phase {
|
||||
PressPhase::DragStart { start, .. } if start.button == PointerButton::Primary => {
|
||||
held.columns = Some(self.columns.to_vec());
|
||||
@@ -296,7 +297,7 @@ impl TextRuler<'_> {
|
||||
fn step_column(&mut self, cx: &mut Cx<'_, Self>, g: &super::Geometry, index: usize, to: f32) {
|
||||
let (lo, hi) = g.span();
|
||||
let border = ColumnBorder { index, position: snap_within(to, 0.0, (lo, hi), true) };
|
||||
self.report.column = Some(ColumnDrag { phase: GesturePhase::Commit, border });
|
||||
self.report.column = Some(ColumnDrag { phase: GesturePhase::Commit, border, mods: Default::default() });
|
||||
cx.focus_part(COLUMN.at(index as u64));
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,8 @@ craft_ui::words! {
|
||||
clear: "tabs.clear" = "Clear";
|
||||
clear_all: "tabs.clearAll" = "Clear All";
|
||||
to_be_cleared: "tabs.toBeCleared" = "Tab stops to be cleared:";
|
||||
/// The empty tab stop list's text.
|
||||
no_stops: "tabStops.none" = "(none)";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,6 +245,25 @@ impl DisplayOrder<usize> for Stops<'_> {
|
||||
|
||||
impl ItemSource<usize> for Stops<'_> {}
|
||||
|
||||
impl TabStopsDialog {
|
||||
/// OK files its result for the app to accept or refuse before the dialog closes.
|
||||
#[must_use]
|
||||
pub fn held_ok(self) -> Self {
|
||||
todo!("dg.F12")
|
||||
}
|
||||
|
||||
/// The result OK filed, once, for the app to judge.
|
||||
pub fn take_ok(&mut self) -> Option<TabStopsResult> {
|
||||
todo!("dg.F12")
|
||||
}
|
||||
|
||||
/// The app's answer to the filed result: `Ok` closes the dialog with it, `Err` shows the reason and enables OK.
|
||||
pub fn answer_ok(&mut self, answer: Result<(), craft_ui::runtime::env::Label>) {
|
||||
let _ = answer;
|
||||
todo!("dg.F12")
|
||||
}
|
||||
}
|
||||
|
||||
impl StackDialog for TabStopsDialog {
|
||||
type Result = TabStopsResult;
|
||||
|
||||
|
||||
@@ -69,10 +69,13 @@ pub(super) const SURFACES: &[(&str, &str, Surface)] = &[
|
||||
("craft_pages", "MarginHandles", Canvas),
|
||||
("craft_pages", "PageGrids", Canvas),
|
||||
("craft_pages", "PagePictures", Canvas),
|
||||
("craft_pages", "PageRulers", Canvas),
|
||||
("craft_pages", "TextFrameMarks", Canvas),
|
||||
("craft_pages", "TextMarks", Canvas),
|
||||
("craft_pages", "VerticalRuler", Canvas),
|
||||
("craft_print", "PrintDialog", Own),
|
||||
("craft_review", "AnnotationOverlay", Canvas),
|
||||
("craft_review", "CommentBalloons", Canvas),
|
||||
("craft_review", "CommentPins", Canvas),
|
||||
("craft_review", "RemoteCursor", Canvas),
|
||||
("craft_review", "RemoteCursors", Canvas),
|
||||
|
||||
Reference in New Issue
Block a user