Skip to content

Commit d7cef15

Browse files
review improvements
1 parent d672b50 commit d7cef15

7 files changed

Lines changed: 56 additions & 69 deletions

File tree

desktop/src/window.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ impl Window {
122122
pub(crate) fn toggle_fullscreen(&self) {
123123
if self.is_fullscreen() {
124124
self.winit_window.set_fullscreen(None);
125+
self.winit_window.set_maximized(true);
125126
} else {
127+
self.winit_window.set_maximized(false);
126128
self.winit_window.set_fullscreen(Some(Fullscreen::Borderless(None)));
127129
}
128130
}

editor/src/messages/input_mapper/input_mappings.rs

Lines changed: 16 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ use glam::DVec2;
1717
impl From<MappingVariant> for Mapping {
1818
fn from(value: MappingVariant) -> Self {
1919
match value {
20-
MappingVariant::Default => input_mappings(),
21-
MappingVariant::ZoomWithScroll => zoom_with_scroll(),
20+
MappingVariant::Default => input_mappings(false),
21+
MappingVariant::ZoomWithScroll => input_mappings(true),
2222
}
2323
}
2424
}
2525

26-
pub fn input_mappings() -> Mapping {
26+
pub fn input_mappings(zoom_with_scroll: bool) -> Mapping {
2727
use InputMapperMessage::*;
2828
use Key::*;
2929

30+
let keyboard_platform = GLOBAL_PLATFORM.get().copied().unwrap_or_default().as_keyboard_platform_layout();
31+
3032
// NOTICE:
3133
// If a new mapping you added here isn't working (and perhaps another lower-precedence one is instead), make sure to advertise
3234
// it as an available action in the respective message handler file (such as the bottom of `document_message_handler.rs`).
@@ -55,9 +57,9 @@ pub fn input_mappings() -> Mapping {
5557
entry!(KeyDown(KeyZ); modifiers=[Accel, MouseLeft], action_dispatch=DocumentMessage::Noop),
5658
//
5759
// AppWindowMessage
58-
entry!(KeyDown(F11); active=cfg!(not(target_os = "macos")), action_dispatch=AppWindowMessage::Fullscreen),
59-
entry!(KeyDown(KeyF); modifiers=[Accel, Meta], active=cfg!(target_os = "macos"), action_dispatch=AppWindowMessage::Fullscreen),
60-
entry!(KeyDown(KeyQ); modifiers=[Accel], active=cfg!(target_os = "macos"), action_dispatch=AppWindowMessage::Close),
60+
entry!(KeyDown(F11); disabled=cfg!(target_os = "macos"), action_dispatch=AppWindowMessage::Fullscreen),
61+
entry!(KeyDown(KeyF); modifiers=[Accel, Meta], disabled=cfg!(not(target_os = "macos")), action_dispatch=AppWindowMessage::Fullscreen),
62+
entry!(KeyDown(KeyQ); modifiers=[Accel], disabled=cfg!(not(target_os = "macos")), action_dispatch=AppWindowMessage::Close),
6163
//
6264
// ClipboardMessage
6365
entry!(KeyDown(KeyX); modifiers=[Accel], action_dispatch=ClipboardMessage::Cut),
@@ -421,10 +423,14 @@ pub fn input_mappings() -> Mapping {
421423
entry!(KeyDown(FakeKeyPlus); modifiers=[Accel], canonical, action_dispatch=NavigationMessage::CanvasZoomIncrease { center_on_mouse: false }),
422424
entry!(KeyDown(Equal); modifiers=[Accel], action_dispatch=NavigationMessage::CanvasZoomIncrease { center_on_mouse: false }),
423425
entry!(KeyDown(Minus); modifiers=[Accel], action_dispatch=NavigationMessage::CanvasZoomDecrease { center_on_mouse: false }),
424-
entry!(WheelScroll; modifiers=[Control], action_dispatch=NavigationMessage::CanvasZoomMouseWheel),
425-
entry!(WheelScroll; modifiers=[Command], action_dispatch=NavigationMessage::CanvasZoomMouseWheel),
426-
entry!(WheelScroll; modifiers=[Shift], action_dispatch=NavigationMessage::CanvasPanMouseWheel { use_y_as_x: true }),
427-
entry!(WheelScroll; action_dispatch=NavigationMessage::CanvasPanMouseWheel { use_y_as_x: false }),
426+
entry!(WheelScroll; modifiers=[Control], disabled=zoom_with_scroll, action_dispatch=NavigationMessage::CanvasZoomMouseWheel),
427+
entry!(WheelScroll; modifiers=[Command], disabled=zoom_with_scroll, action_dispatch=NavigationMessage::CanvasZoomMouseWheel),
428+
entry!(WheelScroll; modifiers=[Shift], disabled=zoom_with_scroll, action_dispatch=NavigationMessage::CanvasPanMouseWheel { use_y_as_x: true }),
429+
entry!(WheelScroll; disabled=zoom_with_scroll, action_dispatch=NavigationMessage::CanvasPanMouseWheel { use_y_as_x: false }),
430+
// On Mac, the OS already converts Shift+scroll into horizontal scrolling so we have to reverse the behavior from normal to produce the same outcome
431+
entry!(WheelScroll; modifiers=[Control], disabled=!zoom_with_scroll, action_dispatch=NavigationMessage::CanvasPanMouseWheel { use_y_as_x: keyboard_platform == KeyboardPlatformLayout::Mac }),
432+
entry!(WheelScroll; modifiers=[Shift], disabled=!zoom_with_scroll, action_dispatch=NavigationMessage::CanvasPanMouseWheel { use_y_as_x: keyboard_platform != KeyboardPlatformLayout::Mac }),
433+
entry!(WheelScroll; disabled=!zoom_with_scroll, action_dispatch=NavigationMessage::CanvasZoomMouseWheel),
428434
entry!(KeyDown(PageUp); modifiers=[Shift], action_dispatch=NavigationMessage::CanvasPanByViewportFraction { delta: DVec2::new(1., 0.) }),
429435
entry!(KeyDown(PageDown); modifiers=[Shift], action_dispatch=NavigationMessage::CanvasPanByViewportFraction { delta: DVec2::new(-1., 0.) }),
430436
entry!(KeyDown(PageUp); action_dispatch=NavigationMessage::CanvasPanByViewportFraction { delta: DVec2::new(0., 1.) }),
@@ -487,43 +493,3 @@ pub fn input_mappings() -> Mapping {
487493
pointer_shake,
488494
}
489495
}
490-
491-
/// Default mappings except that scrolling without modifier keys held down is bound to zooming instead of vertical panning
492-
pub fn zoom_with_scroll() -> Mapping {
493-
use InputMapperMessage::*;
494-
495-
// On Mac, the OS already converts Shift+scroll into horizontal scrolling so we have to reverse the behavior from normal to produce the same outcome
496-
let keyboard_platform = GLOBAL_PLATFORM.get().copied().unwrap_or_default().as_keyboard_platform_layout();
497-
498-
let mut mapping = input_mappings();
499-
500-
let remove = [
501-
entry!(WheelScroll; modifiers=[Control], action_dispatch=NavigationMessage::CanvasZoomMouseWheel),
502-
entry!(WheelScroll; modifiers=[Command], action_dispatch=NavigationMessage::CanvasZoomMouseWheel),
503-
entry!(WheelScroll; modifiers=[Shift], action_dispatch=NavigationMessage::CanvasPanMouseWheel { use_y_as_x: true }),
504-
entry!(WheelScroll; action_dispatch=NavigationMessage::CanvasPanMouseWheel { use_y_as_x: false }),
505-
];
506-
let add = [
507-
entry!(WheelScroll; modifiers=[Control], action_dispatch=NavigationMessage::CanvasPanMouseWheel { use_y_as_x: keyboard_platform == KeyboardPlatformLayout::Mac }),
508-
entry!(WheelScroll; modifiers=[Shift], action_dispatch=NavigationMessage::CanvasPanMouseWheel { use_y_as_x: keyboard_platform != KeyboardPlatformLayout::Mac }),
509-
entry!(WheelScroll; action_dispatch=NavigationMessage::CanvasZoomMouseWheel),
510-
];
511-
512-
apply_mapping_patch(&mut mapping, remove, add);
513-
514-
mapping
515-
}
516-
517-
fn apply_mapping_patch<'a, const N: usize, const M: usize, const X: usize, const Y: usize>(
518-
mapping: &mut Mapping,
519-
remove: impl IntoIterator<Item = &'a [&'a [MappingEntry; N]; M]>,
520-
add: impl IntoIterator<Item = &'a [&'a [MappingEntry; X]; Y]>,
521-
) {
522-
for entry in remove.into_iter().flat_map(|inner| inner.iter()).flat_map(|inner| inner.iter()) {
523-
mapping.remove(entry);
524-
}
525-
526-
for entry in add.into_iter().flat_map(|inner| inner.iter()).flat_map(|inner| inner.iter()) {
527-
mapping.add(entry.clone());
528-
}
529-
}

editor/src/messages/input_mapper/utility_types/macros.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ macro_rules! entry {
3030
$(modifiers=[$($modifier:ident),*],)?
3131
$(refresh_keys=[$($refresh:ident),* $(,)?],)?
3232
canonical,
33-
$(active=$active:expr,)?
33+
$(disabled=$disabled:expr,)?
3434
action_dispatch=$action_dispatch:expr_2021$(,)?
3535
) => {
3636
entry!(
@@ -39,7 +39,7 @@ macro_rules! entry {
3939
$($($refresh),*)?;
4040
$action_dispatch;
4141
true;
42-
true $( && $active )?
42+
true $( && $disabled )?
4343
)
4444
};
4545

@@ -48,7 +48,7 @@ macro_rules! entry {
4848
$input:expr_2021;
4949
$(modifiers=[$($modifier:ident),*],)?
5050
$(refresh_keys=[$($refresh:ident),* $(,)?],)?
51-
$(active=$active:expr,)?
51+
$(disabled=$disabled:expr,)?
5252
action_dispatch=$action_dispatch:expr_2021$(,)?
5353
) => {
5454
entry!(
@@ -57,12 +57,12 @@ macro_rules! entry {
5757
$($($refresh),*)?;
5858
$action_dispatch;
5959
false;
60-
true $( && $active )?
60+
true $( && $disabled )?
6161
)
6262
};
6363

6464
// Implementation macro to avoid code duplication
65-
($input:expr; $($modifier:ident),*; $($refresh:ident),*; $action_dispatch:expr; $canonical:expr; $active:expr) => {
65+
($input:expr; $($modifier:ident),*; $($refresh:ident),*; $action_dispatch:expr; $canonical:expr; $disabled:expr) => {
6666

6767
&[&[
6868
// Cause the `action_dispatch` message to be sent when the specified input occurs.
@@ -71,7 +71,7 @@ macro_rules! entry {
7171
input: $input,
7272
modifiers: modifiers!($($modifier),*),
7373
canonical: $canonical,
74-
active: $active,
74+
disabled: $disabled,
7575
},
7676

7777
$(
@@ -80,28 +80,28 @@ macro_rules! entry {
8080
input: InputMapperMessage::KeyDown(Key::$refresh),
8181
modifiers: modifiers!(),
8282
canonical: $canonical,
83-
active: $active,
83+
disabled: $disabled,
8484
},
8585
MappingEntry {
8686
action: $action_dispatch.into(),
8787
input: InputMapperMessage::KeyUp(Key::$refresh),
8888
modifiers: modifiers!(),
8989
canonical: $canonical,
90-
active: $active,
90+
disabled: $disabled,
9191
},
9292
MappingEntry {
9393
action: $action_dispatch.into(),
9494
input: InputMapperMessage::KeyDownNoRepeat(Key::$refresh),
9595
modifiers: modifiers!(),
9696
canonical: $canonical,
97-
active: $active,
97+
disabled: $disabled,
9898
},
9999
MappingEntry {
100100
action: $action_dispatch.into(),
101101
input: InputMapperMessage::KeyUpNoRepeat(Key::$refresh),
102102
modifiers: modifiers!(),
103103
canonical: $canonical,
104-
active: $active,
104+
disabled: $disabled,
105105
},
106106
)*
107107
]]
@@ -129,7 +129,7 @@ macro_rules! mapping {
129129
for entry_slice in $entry {
130130
// Each entry in the slice (usually just one, except when `refresh_keys` adds additional key entries)
131131
for entry in entry_slice.into_iter() {
132-
if !entry.active {
132+
if entry.disabled {
133133
continue;
134134
}
135135
let corresponding_list = match entry.input {

editor/src/messages/input_mapper/utility_types/misc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ pub struct MappingEntry {
125125
pub modifiers: KeyStates,
126126
/// True indicates that this takes priority as the labeled hotkey shown in UI menus and tooltips instead of an alternate binding for the same action
127127
pub canonical: bool,
128-
/// Whether this mapping is active
129-
pub active: bool,
128+
/// Whether this mapping is disabled
129+
pub disabled: bool,
130130
}
131131

132132
#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize, serde::Deserialize, specta::Type)]

editor/src/messages/menu_bar/menu_bar_message_handler.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,13 @@ impl LayoutHolder for MenuBarMessageHandler {
621621
.label("Window")
622622
.flush(true)
623623
.menu_list_children(vec![
624+
vec![
625+
MenuListEntry::new("Fullscreen")
626+
.label("Fullscreen")
627+
.icon("FullscreenEnter")
628+
.tooltip_shortcut(action_shortcut!(AppWindowMessageDiscriminant::Fullscreen))
629+
.on_commit(|_| AppWindowMessage::Fullscreen.into()),
630+
],
624631
vec![
625632
MenuListEntry::new("Properties")
626633
.label("Properties")
@@ -632,8 +639,6 @@ impl LayoutHolder for MenuBarMessageHandler {
632639
.icon(if self.layers_panel_open { "CheckboxChecked" } else { "CheckboxUnchecked" })
633640
.tooltip_shortcut(action_shortcut!(PortfolioMessageDiscriminant::ToggleLayersPanelOpen))
634641
.on_commit(|_| PortfolioMessage::ToggleLayersPanelOpen.into()),
635-
],
636-
vec![
637642
MenuListEntry::new("Data")
638643
.label("Data")
639644
.icon(if self.data_panel_open { "CheckboxChecked" } else { "CheckboxUnchecked" })

frontend/src/components/window/TitleBar.svelte

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import LayoutRow from "@graphite/components/layout/LayoutRow.svelte";
1212
import IconLabel from "@graphite/components/widgets/labels/IconLabel.svelte";
1313
import WidgetLayout from "@graphite/components/widgets/WidgetLayout.svelte";
14+
import { isDesktop } from "/src/utility-functions/platform";
1415
1516
const appWindow = getContext<AppWindowState>("appWindow");
1617
const editor = getContext<Editor>("editor");
@@ -19,7 +20,8 @@
1920
2021
let menuBarLayout: Layout = [];
2122
22-
$: showFullscreenButton = $appWindow.platform === "Web" || $fullscreen.windowFullscreen;
23+
$: showFullscreenButton = $appWindow.platform === "Web" || $fullscreen.windowFullscreen || (isDesktop() && $appWindow.fullscreen);
24+
$: isFullscreen = isDesktop() ? $appWindow.fullscreen : $fullscreen.windowFullscreen;
2325
// On Mac, the menu bar height needs to be scaled by the inverse of the UI scale to fit its native window buttons
2426
$: height = $appWindow.platform === "Mac" ? 28 * (1 / $appWindow.uiScale) : 28;
2527
@@ -45,14 +47,20 @@
4547
{#if $appWindow.platform !== "Mac"}
4648
{#if showFullscreenButton}
4749
<LayoutRow
48-
tooltipLabel={$fullscreen.windowFullscreen ? "Exit Fullscreen" : "Enter Fullscreen"}
50+
tooltipLabel={isFullscreen ? "Exit Fullscreen" : "Enter Fullscreen"}
4951
tooltipDescription={$appWindow.platform === "Web" && $fullscreen.keyboardLockApiSupported
5052
? "While fullscreen, keyboard shortcuts normally reserved by the browser become available."
5153
: undefined}
5254
tooltipShortcut={$tooltip.f11Shortcut}
53-
on:click={() => ($fullscreen.windowFullscreen ? fullscreen.exitFullscreen : fullscreen.enterFullscreen)()}
55+
on:click={() => {
56+
if (isDesktop()) {
57+
editor.handle.appWindowFullscreen();
58+
} else {
59+
($fullscreen.windowFullscreen ? fullscreen.exitFullscreen : fullscreen.enterFullscreen)();
60+
}
61+
}}
5462
>
55-
<IconLabel icon={$fullscreen.windowFullscreen ? "FullscreenExit" : "FullscreenEnter"} />
63+
<IconLabel icon={isFullscreen ? "FullscreenExit" : "FullscreenEnter"} />
5664
</LayoutRow>
5765
{:else}
5866
<LayoutRow tooltipLabel="Minimize" on:click={() => editor.handle.appWindowMinimize()}>

frontend/wasm/src/editor_api.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ impl EditorHandle {
295295
self.dispatch(message);
296296
}
297297

298+
#[wasm_bindgen(js_name = appWindowFullscreen)]
299+
pub fn app_window_fullscreen(&self) {
300+
let message = AppWindowMessage::Fullscreen;
301+
self.dispatch(message);
302+
}
303+
298304
/// Closes the application window
299305
#[wasm_bindgen(js_name = appWindowClose)]
300306
pub fn app_window_close(&self) {

0 commit comments

Comments
 (0)