Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ libc.workspace = true
[target.'cfg(target_os = "macos")'.dependencies]
muda.workspace = true
objc2 = "0.6"
objc2-app-kit = { version = "0.3", default-features = false, features = ["std", "NSApplication", "NSColor", "NSColorSpace", "NSHapticFeedback", "NSWindow", "objc2-core-foundation"] }
objc2-app-kit = { version = "0.3", default-features = false, features = ["std", "NSAccessibility", "NSApplication", "NSColor", "NSColorSpace", "NSHapticFeedback", "NSWindow", "NSWorkspace", "objc2-core-foundation"] }
objc2-foundation = { version = "0.3", default-features = false, features = ["std", "NSObject", "NSAppleEventManager", "NSAppleEventDescriptor", "NSNotification", "NSString", "NSURL"] }

[target.'cfg(windows)'.build-dependencies]
Expand Down
18 changes: 7 additions & 11 deletions crates/app/src/ui/canvas/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ pub(crate) fn freeze_board_for_gesture(app: &mut PlotiumApp) {

/// Seed the fit springs from the live camera.
fn seed_board_fit_springs(app: &mut PlotiumApp, ctx: &egui::Context) {
crate::ui::switcher::seed_spring(
crate::ui::motion::seed_spring(
ctx,
viewport_local_id(ctx, FIT_ZOOM_ID),
app.session.board.zoom,
);
crate::ui::switcher::seed_spring(
crate::ui::motion::seed_spring(
ctx,
viewport_local_id(ctx, FIT_CENTER_X_ID),
app.session.board.world_center[0],
);
crate::ui::switcher::seed_spring(
crate::ui::motion::seed_spring(
ctx,
viewport_local_id(ctx, FIT_CENTER_Y_ID),
app.session.board.world_center[1],
Expand Down Expand Up @@ -153,19 +153,15 @@ pub(crate) fn drive_board_fit(
let ctx = ui.ctx();
let dt = ui.input(|i| i.stable_dt);
let before = app.session.board;
app.session.board.zoom = crate::ui::switcher::animate_spring(
ctx,
viewport_local_id(ctx, FIT_ZOOM_ID),
target.zoom,
dt,
);
app.session.board.world_center[0] = crate::ui::switcher::animate_spring(
app.session.board.zoom =
crate::ui::motion::spring(ctx, viewport_local_id(ctx, FIT_ZOOM_ID), target.zoom, dt);
app.session.board.world_center[0] = crate::ui::motion::spring(
ctx,
viewport_local_id(ctx, FIT_CENTER_X_ID),
target.world_center[0],
dt,
);
app.session.board.world_center[1] = crate::ui::switcher::animate_spring(
app.session.board.world_center[1] = crate::ui::motion::spring(
ctx,
viewport_local_id(ctx, FIT_CENTER_Y_ID),
target.world_center[1],
Expand Down
4 changes: 2 additions & 2 deletions crates/app/src/ui/command_exec_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn zoom_to_fit_command_seeds_springs_from_the_live_camera() {
("board_fit_center_y", -900.0),
] {
let key = crate::ui::viewport_local_id(&ctx, id);
crate::ui::switcher::animate_spring(&ctx, key, stale, 0.0);
crate::ui::motion::spring(&ctx, key, stale, 0.0);
}

execute_without_clipboard(CommandId::ZoomToFit, &mut app, &ctx);
Expand All @@ -59,7 +59,7 @@ fn zoom_to_fit_command_seeds_springs_from_the_live_camera() {
("board_fit_center_y", -40.0),
] {
let key = crate::ui::viewport_local_id(&ctx, id);
let seeded = crate::ui::switcher::animate_spring(&ctx, key, live, 0.0);
let seeded = crate::ui::motion::spring(&ctx, key, live, 0.0);
assert_eq!(seeded, live);
}
assert_eq!(app.session.status, "Fit all 1 board frame to view.");
Expand Down
78 changes: 70 additions & 8 deletions crates/app/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub(crate) mod file_dialogs;
pub(crate) mod file_drop;
pub(crate) mod import_feedback;
mod menus;
pub(crate) mod motion;
#[cfg(target_os = "macos")]
pub(crate) mod native_documents;
#[cfg(target_os = "macos")]
Expand Down Expand Up @@ -117,6 +118,7 @@ pub fn render(
*last_window_title = Some(title);
}
sync_chrome_theme(&ctx, app.settings.appearance.theme);
motion::sync(&ctx, app.settings.appearance.reduce_motion);
clipboard_table_paste.begin_frame(app, &ctx);
canvas::refresh_spotlight(app, &ctx);
file_dialogs::image_import::poll(app, &ctx);
Expand Down Expand Up @@ -553,25 +555,85 @@ pub(super) enum ModalKind {
Dialog,
}

/// Every modal goes through here so backdrop depth, anchoring, and future
/// theming decisions live in one place instead of at each call site.
pub(super) fn modal(ctx: &egui::Context, id: &str, kind: ModalKind) -> egui::Modal {
/// Every modal goes through here so backdrop depth, anchoring, and the
/// opening animation live in one place instead of at each call site.
pub(super) fn modal(ctx: &egui::Context, id: &str, kind: ModalKind) -> ChromeModal {
let id = egui::Id::new(id);
match kind {
ModalKind::Palette => egui::Modal::new(id)
.backdrop_color(Color32::TRANSPARENT)
.area(
let (modal, backdrop) = match kind {
ModalKind::Palette => (
egui::Modal::new(id).area(
egui::Modal::default_area(id)
.anchor(egui::Align2::CENTER_TOP, Vec2::new(0.0, 96.0)),
),
Color32::TRANSPARENT,
),
ModalKind::Dialog => {
let alpha = if ctx.theme() == egui::Theme::Dark {
100
} else {
48
};
egui::Modal::new(id).backdrop_color(Color32::from_black_alpha(alpha))
(egui::Modal::new(id), Color32::from_black_alpha(alpha))
}
};
ChromeModal {
id,
modal: modal
.backdrop_color(Color32::TRANSPARENT)
.frame(egui::Frame::NONE),
backdrop,
}
}

/// An `egui::Modal` that fades in and grows slightly from its centre when it
/// opens. The backdrop is painted here rather than by egui so it still covers
/// the window while the layer is scaled.
pub(super) struct ChromeModal {
id: egui::Id,
modal: egui::Modal,
backdrop: Color32,
}

impl ChromeModal {
pub(super) fn show<T>(
self,
ctx: &egui::Context,
content: impl FnOnce(&mut Ui) -> T,
) -> egui::ModalResponse<T> {
let Self {
id,
mut modal,
backdrop,
} = self;
modal.area = modal.area.fade_in(false);
let layer = modal.area.layer();
let t = motion::appear(ctx, id);
let rect_id = viewport_local_id(ctx, "modal_rect").with(id);
let pivot = ctx
.data(|data| data.get_temp::<Rect>(rect_id))
.map(|rect| rect.center());
let transform = match pivot {
Some(pivot) if t < 1.0 => {
motion::scale_about(pivot, egui::lerp(motion::APPEAR_SCALE_FROM..=1.0, t))
}
_ => egui::emath::TSTransform::IDENTITY,
};
ctx.set_transform_layer(layer, transform);
modal.show(ctx, |ui| {
if backdrop.a() > 0 {
let cover = transform.inverse() * ui.ctx().content_rect();
egui::Painter::new(ui.ctx().clone(), layer, cover).rect_filled(
cover,
0.0,
backdrop.gamma_multiply(t),
);
}
ui.multiply_opacity(t);
let shown = egui::Frame::popup(ui.style()).show(ui, content);
ui.ctx()
.data_mut(|data| data.insert_temp(rect_id, shown.response.rect));
shown.inner
})
}
}

Expand Down
Loading
Loading