mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 23:49:35 +00:00
gallery mock: the document's view is Tracked
The canvas, the Navigator and the status bar's zoom show and edit it, so they bind it by its source.
This commit is contained in:
@@ -13,12 +13,14 @@ use kurbo::{Affine, Point, Rect, Vec2};
|
||||
/// [`aspect`](Self::aspect) stretches it along its x axis and before
|
||||
/// [`flip_x`](Self::flip_x) mirrors the result, PhotoCraft's `ViewXform`. DesignCraft's quarter
|
||||
/// turns are `rotation = 90 × q`; VectorCraft's radians are converted to degrees.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, craft_ui_macros::PlainData)]
|
||||
#[non_exhaustive]
|
||||
pub struct CanvasView {
|
||||
/// The canvas on screen, inside the rulers.
|
||||
#[plain_data(assume = "screen geometry: plain numbers, no interior mutability")]
|
||||
pub rect: ScreenRect,
|
||||
/// The document point drawn at `rect.center()`.
|
||||
#[plain_data(assume = "document geometry: plain numbers, no interior mutability")]
|
||||
pub center: Point,
|
||||
/// Screen points per document unit. In PhotoCraft's model this is the view zoom over the
|
||||
/// pixels per point, so 100 % shows one device pixel per document pixel.
|
||||
|
||||
@@ -309,7 +309,7 @@ fn status_bar(ui: &mut Ui, state: &mut MockState) {
|
||||
Link::new(words.cpu_rendering.clone()).tone(Tone::Warn).show(ui);
|
||||
})
|
||||
.show(ui, |ui, _| {
|
||||
chosen = StatusReadout::new(Bind::bound(&mut document.view), document.size, *status_item, &values).show(ui).item;
|
||||
chosen = StatusReadout::new(craft_ui::contract::bind_tracked!(document.view), document.size, *status_item, &values).show(ui).item;
|
||||
Divider::vertical().show(ui);
|
||||
Text::new(words.color_mode.clone()).show(ui);
|
||||
Divider::vertical().show(ui);
|
||||
|
||||
@@ -8,7 +8,7 @@ use craft_behavior::{Axis, PixelSize};
|
||||
use craft_behavior::{CanvasView, Selection};
|
||||
use craft_ui::bars::{StatusItem, StatusMessage};
|
||||
use craft_ui::canvas::{Guide, GuideKey, PickStep, PixelRect, tool_pick};
|
||||
use craft_ui::contract::CommandSet;
|
||||
use craft_ui::contract::{CommandSet, Tracked};
|
||||
use craft_ui::rails::{LastUsed, RailTool, SlotId, ToolSlot};
|
||||
use craft_ui::runtime::env::UnitKind;
|
||||
use egui::{Color32, Rect};
|
||||
@@ -226,7 +226,7 @@ pub struct LayerMove {
|
||||
}
|
||||
|
||||
/// The open document.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[non_exhaustive]
|
||||
pub struct Document {
|
||||
/// The title of the window and the tab.
|
||||
@@ -239,8 +239,9 @@ pub struct Document {
|
||||
pub layers: Vec<Layer>,
|
||||
/// The selected layers; the lead is the current layer.
|
||||
pub selected: Selection<LayerId>,
|
||||
/// The canvas view. A view that was never shown opens fitted.
|
||||
pub view: CanvasView,
|
||||
/// The canvas view, which the canvas, the Navigator and the status bar show and edit. A view that was never shown
|
||||
/// opens fitted.
|
||||
pub view: Tracked<CanvasView>,
|
||||
/// The ruler zero point.
|
||||
pub zero: Point,
|
||||
/// The unit the rulers count in.
|
||||
@@ -277,7 +278,7 @@ impl Default for Document {
|
||||
size,
|
||||
selected: Selection::single(layers[0].id),
|
||||
layers,
|
||||
view,
|
||||
view: Tracked::new(view),
|
||||
zero: Point::ZERO,
|
||||
units: UnitKind::Pixels,
|
||||
guides: Vec::new(),
|
||||
@@ -398,7 +399,7 @@ impl Document {
|
||||
}
|
||||
|
||||
/// Everything the mock edits.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[non_exhaustive]
|
||||
pub struct MockState {
|
||||
/// The dock's panels and where they sit.
|
||||
|
||||
@@ -77,7 +77,7 @@ impl Panels<'_> {
|
||||
/// The document tab's title: the name, the zoom of the device and the current layer.
|
||||
fn tab_title(&self, ui: &Ui, cx: &BodyCx<'_>) -> String {
|
||||
let document = &self.document;
|
||||
let zoom = CanvasSpace::new(document.view, ui.pixels_per_point()).zoom_device() * 100.0;
|
||||
let zoom = CanvasSpace::new(*document.view, ui.pixels_per_point()).zoom_device() * 100.0;
|
||||
let layer = document.current_layer().map_or("", |layer| layer.name.as_str());
|
||||
cx.words::<MockWords>().tab_title.fill(&[("name", &document.title), ("zoom", &cx.format().integer(zoom.round() as i64)), ("layer", layer)])
|
||||
}
|
||||
@@ -115,7 +115,7 @@ impl DockPanels<Panel> for Panels<'_> {
|
||||
fn body(&mut self, panel: &Panel, ui: &mut Ui, cx: &mut BodyCx<'_>) {
|
||||
match panel {
|
||||
Panel::Navigator => {
|
||||
let props = NavigatorProps { view: Bind::bound(&mut self.document.view), size: self.document.size };
|
||||
let props = NavigatorProps { view: craft_ui::contract::bind_tracked!(self.document.view), size: self.document.size };
|
||||
let _ = MemoView::new("navigator", props, navigator).show(ui);
|
||||
}
|
||||
Panel::Layers => layers(ui, cx, self.document),
|
||||
@@ -209,7 +209,7 @@ fn canvas(ui: &mut Ui, document: &mut Document, tool: Tool, tools: &mut Tools) {
|
||||
let page = DocRect::new(0.0, 0.0, document.size.width, document.size.height);
|
||||
let pages = [PageFrame::new(page)];
|
||||
let pixels = document.pixel_size();
|
||||
let (view, show_rulers) = (document.view, document.rulers);
|
||||
let (view, show_rulers) = (*document.view, document.rulers);
|
||||
let editing = matches!(tool, Tool::Move | Tool::Marquee);
|
||||
let canvas_id = ui.scope_id().with("mock document canvas");
|
||||
// What the host reported; none in a measuring run, where it does not run.
|
||||
@@ -262,7 +262,7 @@ fn canvas(ui: &mut Ui, document: &mut Document, tool: Tool, tools: &mut Tools) {
|
||||
);
|
||||
let reported: craft_ui::canvas::ToolHostResponse = reported.unwrap_or_default();
|
||||
if let Some(next) = scrolled.or(reported.view) {
|
||||
document.view = next;
|
||||
*document.view = next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user