diff --git a/Cargo.lock b/Cargo.lock index 02fb728ff..c69ebc11e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/Cargo.toml b/Cargo.toml index a7b8713ab..5a038bd41 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } diff --git a/crates/craft/Cargo.toml b/crates/craft/Cargo.toml index d3593672c..884be6244 100644 --- a/crates/craft/Cargo.toml +++ b/crates/craft/Cargo.toml @@ -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"] diff --git a/crates/craft/src/lib.rs b/crates/craft/src/lib.rs index c71b03463..8b611e354 100644 --- a/crates/craft/src/lib.rs +++ b/crates/craft/src/lib.rs @@ -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")] diff --git a/crates/gpu/Cargo.toml b/crates/gpu/Cargo.toml new file mode 100644 index 000000000..fe0d75c04 --- /dev/null +++ b/crates/gpu/Cargo.toml @@ -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 diff --git a/crates/gpu/src/device.rs b/crates/gpu/src/device.rs new file mode 100644 index 000000000..c9dc383e3 --- /dev/null +++ b/crates/gpu/src/device.rs @@ -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") +} diff --git a/crates/gpu/src/device/drm.rs b/crates/gpu/src/device/drm.rs new file mode 100644 index 000000000..7197bc693 --- /dev/null +++ b/crates/gpu/src/device/drm.rs @@ -0,0 +1 @@ +//! Linux: the DRM render node the device pick reads. diff --git a/crates/gpu/src/device/linux.rs b/crates/gpu/src/device/linux.rs new file mode 100644 index 000000000..2c69f9d96 --- /dev/null +++ b/crates/gpu/src/device/linux.rs @@ -0,0 +1 @@ +//! Linux: the Vulkan and GL backends and the choice of device. diff --git a/crates/gpu/src/device/macos.rs b/crates/gpu/src/device/macos.rs new file mode 100644 index 000000000..aecccac72 --- /dev/null +++ b/crates/gpu/src/device/macos.rs @@ -0,0 +1 @@ +//! macOS: the Metal backend and its power preference. diff --git a/crates/gpu/src/device/windows.rs b/crates/gpu/src/device/windows.rs new file mode 100644 index 000000000..e93b439e1 --- /dev/null +++ b/crates/gpu/src/device/windows.rs @@ -0,0 +1 @@ +//! Windows: Direct3D 12 and Vulkan backends and the DX12 shader compiler. diff --git a/crates/gpu/src/lib.rs b/crates/gpu/src/lib.rs new file mode 100644 index 000000000..a219554ed --- /dev/null +++ b/crates/gpu/src/lib.rs @@ -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; diff --git a/crates/pages/Cargo.toml b/crates/pages/Cargo.toml index 3bce55f00..660275aea 100644 --- a/crates/pages/Cargo.toml +++ b/crates/pages/Cargo.toml @@ -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 } diff --git a/crates/pages/src/lib.rs b/crates/pages/src/lib.rs index b369fa26f..0052021e8 100644 --- a/crates/pages/src/lib.rs +++ b/crates/pages/src/lib.rs @@ -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")] diff --git a/crates/pages/src/setup.rs b/crates/pages/src/setup.rs index 6e2f24b16..829d2e9fa 100644 --- a/crates/pages/src/setup.rs +++ b/crates/pages/src/setup.rs @@ -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, +} + +/// 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, } } } diff --git a/crates/pages/src/ui/mod.rs b/crates/pages/src/ui/mod.rs index 4635178ce..481fa343e 100644 --- a/crates/pages/src/ui/mod.rs +++ b/crates/pages/src/ui/mod.rs @@ -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, }; diff --git a/crates/pages/src/ui/page_rulers.rs b/crates/pages/src/ui/page_rulers.rs new file mode 100644 index 000000000..ed0b0a0bc --- /dev/null +++ b/crates/pages/src/ui/page_rulers.rs @@ -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, +} + +/// 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