Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Add preview toolbar view options menu

Jonny Burgeraecbfee2be67
diff --git a/packages/studio-shared/src/keyboard-shortcuts.ts b/packages/studio-shared/src/keyboard-shortcuts.ts
index 9c66166139..08abd0b7ba 100644
--- a/packages/studio-shared/src/keyboard-shortcuts.ts
+++ b/packages/studio-shared/src/keyboard-shortcuts.ts
@@ -16,6 +16,7 @@ export const studioKeyboardShortcutActions = [
'toggleSnapping',
'toggleOutlines',
'toggleRulersAndGuides',
+ 'togglePixelGrid',
'previousComposition',
'nextComposition',
'showKeyboardShortcuts',
diff --git a/packages/studio/src/components/GlobalKeybindings.tsx b/packages/studio/src/components/GlobalKeybindings.tsx
index 7ce5d551be..4d8af9479e 100644
--- a/packages/studio/src/components/GlobalKeybindings.tsx
+++ b/packages/studio/src/components/GlobalKeybindings.tsx
@@ -11,6 +11,7 @@ import {useKeybinding} from '../helpers/use-keybinding';
import {CheckerboardContext} from '../state/checkerboard';
import {EditorShowGuidesContext} from '../state/editor-guides';
import {EditorShowOutlinesContext} from '../state/editor-outlines';
+import {EditorShowPixelGridContext} from '../state/editor-pixel-grid';
import {EditorShowRulersContext} from '../state/editor-rulers';
import {EditorSnappingContext} from '../state/editor-snapping';
import {SetSelectedModalContext} from '../state/modals';
@@ -43,6 +44,7 @@ export const GlobalKeybindings: React.FC = () => {
const {setEditorSnapping} = useContext(EditorSnappingContext);
const {canvasContent} = useContext(Internals.CompositionManager);
const {setEditorShowOutlines} = useContext(EditorShowOutlinesContext);
+ const {setEditorShowPixelGrid} = useContext(EditorShowPixelGridContext);
const {editorShowRulers, setEditorShowRulers} = useContext(
EditorShowRulersContext,
);
@@ -82,9 +84,20 @@ export const GlobalKeybindings: React.FC = () => {
triggerIfInputFieldFocused: false,
keepRegisteredWhenNotHighestContext: false,
});
+ const pixelGrid = keybindings.registerKeybinding({
+ event: 'keydown',
+ action: 'togglePixelGrid',
+ callback: (event) => {
+ if (!event.repeat) setEditorShowPixelGrid((current) => !current);
+ },
+ preventDefault: true,
+ triggerIfInputFieldFocused: false,
+ keepRegisteredWhenNotHighestContext: false,
+ });
return () => {
outlines?.unregister();
rulers.unregister();
+ pixelGrid.unregister();
};
}, [
keybindings,
@@ -93,6 +106,7 @@ export const GlobalKeybindings: React.FC = () => {
editorShowRulers,
editorShowGuides,
setEditorShowOutlines,
+ setEditorShowPixelGrid,
setEditorShowRulers,
setEditorShowGuides,
]);
diff --git a/packages/studio/src/components/PreviewToolbar.tsx b/packages/studio/src/components/PreviewToolbar.tsx
index d51ec03a9b..835554cde8 100644
--- a/packages/studio/src/components/PreviewToolbar.tsx
+++ b/packages/studio/src/components/PreviewToolbar.tsx
@@ -16,14 +16,13 @@ import {FullScreenToggle} from './FullscreenToggle';
import {Flex, Spacing} from './layout';
import {LoopToggle} from './LoopToggle';
import {MuteToggle} from './MuteToggle';
-import {OutlineToggle} from './OutlineToggle';
import {PlaybackKeyboardShortcutsManager} from './PlaybackKeyboardShortcutsManager';
import {PlaybackRatePersistor} from './PlaybackRatePersistor';
import {PlaybackRateSelector} from './PlaybackRateSelector';
import {PlayPause} from './PlayPause';
import {PreviewToolbarOverflowButton} from './PreviewToolbarOverflowButton';
+import {PreviewViewOptionsDropdown} from './PreviewViewOptionsDropdown';
import {RenderButton} from './RenderButton';
-import {RulersAndGuidesToggle} from './RulersAndGuidesToggle';
import {SizeSelector} from './SizeSelector';
import {SnappingToggle} from './SnappingToggle';
import {TimelineInOutPointToggle} from './TimelineInOutToggle';
@@ -168,8 +167,6 @@ export const PreviewToolbar: React.FC<{
) : null}
{isVideoComposition && !isMobileLayout ? (
<>
- <Spacing x={2} />
- {playPause}
<Spacing x={2} />
<PreviewToolbarControl>
<LoopToggle loop={loop} setLoop={setLoop} />
@@ -177,11 +174,13 @@ export const PreviewToolbar: React.FC<{
<PreviewToolbarControl>
<MuteToggle muted={playerMuted} setMuted={setPlayerMuted} />
</PreviewToolbarControl>
- <Spacing x={2} />
+ <Spacing x={1} />
<PreviewToolbarControl>
<TimelineInOutPointToggle />
</PreviewToolbarControl>
- <Spacing x={2} />
+ <Spacing x={3} />
+ {playPause}
+ <Spacing x={3} />
</>
) : null}
{showCanvasViewControls ? (
@@ -191,16 +190,6 @@ export const PreviewToolbar: React.FC<{
<CheckboardToggle />
</PreviewToolbarControl>
)}
- {isMobileLayout || !showCompositionControls ? null : (
- <PreviewToolbarControl>
- <OutlineToggle />
- </PreviewToolbarControl>
- )}
- {isMobileLayout ? null : (
- <PreviewToolbarControl>
- <RulersAndGuidesToggle showGuides={showCompositionControls} />
- </PreviewToolbarControl>
- )}
{readOnlyStudio ||
isMobileLayout ||
!showCompositionControls ? null : (
@@ -208,6 +197,13 @@ export const PreviewToolbar: React.FC<{
<SnappingToggle />
</PreviewToolbarControl>
)}
+ {isMobileLayout ? null : (
+ <PreviewToolbarControl>
+ <PreviewViewOptionsDropdown
+ showCompositionControls={showCompositionControls}
+ />
+ </PreviewToolbarControl>
+ )}
</>
) : null}
<Spacing x={2} />
diff --git a/packages/studio/src/components/PreviewToolbarOverflowButton.tsx b/packages/studio/src/components/PreviewToolbarOverflowButton.tsx
index 78813c3071..e9615c0e76 100644
--- a/packages/studio/src/components/PreviewToolbarOverflowButton.tsx
+++ b/packages/studio/src/components/PreviewToolbarOverflowButton.tsx
@@ -8,6 +8,7 @@ import {EllipsisIcon} from '../icons/ellipsis';
import {CheckerboardContext} from '../state/checkerboard';
import {EditorShowGuidesContext} from '../state/editor-guides';
import {EditorShowOutlinesContext} from '../state/editor-outlines';
+import {EditorShowPixelGridContext} from '../state/editor-pixel-grid';
import {EditorShowRulersContext} from '../state/editor-rulers';
import {ActionTooltip} from './ActionTooltip';
import type {RenderInlineAction} from './InlineAction';
@@ -46,6 +47,7 @@ export const PreviewToolbarOverflowButton: React.FC<{
const fullscreenShortcut = useKeyboardShortcutLabel('enterFullscreen');
const loopShortcut = useKeyboardShortcutLabel('toggleLoop');
const outlinesShortcut = useKeyboardShortcutLabel('toggleOutlines');
+ const pixelGridShortcut = useKeyboardShortcutLabel('togglePixelGrid');
const checkerboardShortcut = useKeyboardShortcutLabel('toggleCheckerboard');
const {checkerboard, setCheckerboard} = useContext(CheckerboardContext);
const {editorShowOutlines, setEditorShowOutlines} = useContext(
@@ -57,6 +59,9 @@ export const PreviewToolbarOverflowButton: React.FC<{
const {editorShowRulers, setEditorShowRulers} = useContext(
EditorShowRulersContext,
);
+ const {editorShowPixelGrid, setEditorShowPixelGrid} = useContext(
+ EditorShowPixelGridContext,
+ );
const {
items: previewSizeItems,
selectedId: selectedPreviewSize,
@@ -199,6 +204,20 @@ export const PreviewToolbarOverflowButton: React.FC<{
});
}
+ if (showCanvasViewControls) {
+ items.push({
+ type: 'item',
+ id: 'pixel-grid',
+ label: 'Pixel Grid',
+ value: 'pixel-grid',
+ onClick: () => setEditorShowPixelGrid((current) => !current),
+ keyHint: keyboardShortcutsDisabled ? null : pixelGridShortcut || null,
+ leftItem: editorShowPixelGrid ? <Checkmark /> : null,
+ subMenu: null,
+ quickSwitcherLabel: null,
+ });
+ }
+
if (showFullscreen) {
items.push({
type: 'item',
@@ -235,11 +254,14 @@ export const PreviewToolbarOverflowButton: React.FC<{
editorShowGuides,
editorShowOutlines,
outlinesShortcut,
+ pixelGridShortcut,
editorShowRulers,
+ editorShowPixelGrid,
setCheckerboard,
setEditorShowGuides,
setEditorShowOutlines,
setEditorShowRulers,
+ setEditorShowPixelGrid,
setLoop,
zoomable,
keyboardShortcutsDisabled,
diff --git a/packages/studio/src/components/PreviewViewOptionsDropdown.tsx b/packages/studio/src/components/PreviewViewOptionsDropdown.tsx
new file mode 100644
index 0000000000..659c0bac75
--- /dev/null
+++ b/packages/studio/src/components/PreviewViewOptionsDropdown.tsx
@@ -0,0 +1,118 @@
+import React, {useContext, useMemo} from 'react';
+import {WHITE_ALPHA_80} from '../helpers/colors';
+import {areKeyboardShortcutsDisabled} from '../helpers/use-keybinding';
+import {useKeyboardShortcutLabel} from '../helpers/use-keyboard-shortcut-label';
+import {CaretDown} from '../icons/caret';
+import {Checkmark} from '../icons/Checkmark';
+import {EditorShowGuidesContext} from '../state/editor-guides';
+import {EditorShowOutlinesContext} from '../state/editor-outlines';
+import {EditorShowPixelGridContext} from '../state/editor-pixel-grid';
+import {EditorShowRulersContext} from '../state/editor-rulers';
+import {ActionTooltip} from './ActionTooltip';
+import {InlineDropdown} from './InlineDropdown';
+import type {ComboboxValue} from './NewComposition/ComboBox';
+
+export const PreviewViewOptionsDropdown: React.FC<{
+ readonly showCompositionControls: boolean;
+}> = ({showCompositionControls}) => {
+ const {editorShowOutlines, setEditorShowOutlines} = useContext(
+ EditorShowOutlinesContext,
+ );
+ const {editorShowRulers, setEditorShowRulers} = useContext(
+ EditorShowRulersContext,
+ );
+ const {editorShowGuides, setEditorShowGuides} = useContext(
+ EditorShowGuidesContext,
+ );
+ const {editorShowPixelGrid, setEditorShowPixelGrid} = useContext(
+ EditorShowPixelGridContext,
+ );
+ const shortcutsDisabled = areKeyboardShortcutsDisabled();
+ const outlinesShortcut = useKeyboardShortcutLabel('toggleOutlines');
+ const rulersAndGuidesShortcut = useKeyboardShortcutLabel(
+ 'toggleRulersAndGuides',
+ );
+ const pixelGridShortcut = useKeyboardShortcutLabel('togglePixelGrid');
+
+ const values = useMemo((): ComboboxValue[] => {
+ const items: ComboboxValue[] = [];
+ if (showCompositionControls) {
+ items.push({
+ type: 'item',
+ id: 'outlines',
+ label: 'Outlines',
+ value: 'outlines',
+ onClick: () => setEditorShowOutlines((current) => !current),
+ keyHint: shortcutsDisabled ? null : outlinesShortcut || null,
+ leftItem: editorShowOutlines ? <Checkmark /> : null,
+ subMenu: null,
+ quickSwitcherLabel: null,
+ });
+ }
+
+ const rulersOrGuidesAreVisible =
+ editorShowRulers || (showCompositionControls && editorShowGuides);
+ items.push({
+ type: 'item',
+ id: 'rulers-and-guides',
+ label: showCompositionControls ? 'Rulers and Guides' : 'Rulers',
+ value: 'rulers-and-guides',
+ onClick: () => {
+ setEditorShowRulers(() => !rulersOrGuidesAreVisible);
+ if (showCompositionControls) {
+ setEditorShowGuides(() => !rulersOrGuidesAreVisible);
+ }
+ },
+ keyHint: shortcutsDisabled ? null : rulersAndGuidesShortcut || null,
+ leftItem: rulersOrGuidesAreVisible ? <Checkmark /> : null,
+ subMenu: null,
+ quickSwitcherLabel: null,
+ });
+
+ items.push({
+ type: 'item',
+ id: 'pixel-grid',
+ label: 'Pixel Grid',
+ value: 'pixel-grid',
+ onClick: () => setEditorShowPixelGrid((current) => !current),
+ keyHint: shortcutsDisabled ? null : pixelGridShortcut || null,
+ leftItem: editorShowPixelGrid ? <Checkmark /> : null,
+ subMenu: null,
+ quickSwitcherLabel: null,
+ });
+
+ return items;
+ }, [
+ editorShowGuides,
+ editorShowOutlines,
+ editorShowPixelGrid,
+ editorShowRulers,
+ outlinesShortcut,
+ pixelGridShortcut,
+ rulersAndGuidesShortcut,
+ setEditorShowGuides,
+ setEditorShowOutlines,
+ setEditorShowPixelGrid,
+ setEditorShowRulers,
+ shortcutsDisabled,
+ showCompositionControls,
+ ]);
+
+ return (
+ <ActionTooltip
+ label="View options"
+ shortcut={null}
+ delay={800}
+ dismissOnClick
+ >
+ <InlineDropdown
+ variant={null}
+ style={{width: 20}}
+ renderAction={(color) => <CaretDown color={color} />}
+ values={values}
+ aria-label="View options"
+ unhoveredColor={WHITE_ALPHA_80}
+ />
+ </ActionTooltip>
+ );
+};
diff --git a/packages/studio/src/components/keyboard-shortcuts.ts b/packages/studio/src/components/keyboard-shortcuts.ts
index dc078c76aa..7112b76001 100644
--- a/packages/studio/src/components/keyboard-shortcuts.ts
+++ b/packages/studio/src/components/keyboard-shortcuts.ts
@@ -51,6 +51,7 @@ export const defaultKeyboardShortcuts: Record<
toggleSnapping: [{key: 'm', shift: true}],
toggleOutlines: [{key: 'o', shift: true}],
toggleRulersAndGuides: [{key: 'r', shift: true}],
+ togglePixelGrid: [{key: 'p', shift: true}],
previousComposition: [{key: 'PageUp'}],
nextComposition: [{key: 'PageDown'}],
showKeyboardShortcuts: [{key: '?', shift: true}],
@@ -137,6 +138,7 @@ export const keyboardShortcutGroups: readonly KeyboardShortcutGroup[] = [
shortcut('Enable snapping', 'toggleSnapping'),
shortcut('Outlines', 'toggleOutlines'),
shortcut('Rulers and guides', 'toggleRulersAndGuides'),
+ shortcut('Pixel grid', 'togglePixelGrid'),
],
},
{
diff --git a/packages/studio/src/helpers/use-menu-structure.tsx b/packages/studio/src/helpers/use-menu-structure.tsx
index 29b9f26279..443d3917a1 100644
--- a/packages/studio/src/helpers/use-menu-structure.tsx
+++ b/packages/studio/src/helpers/use-menu-structure.tsx
@@ -324,6 +324,7 @@ export const useMenuStructure = (
const resetZoomShortcut = useKeyboardShortcutLabel('resetZoom');
const toggleSnappingShortcut = useKeyboardShortcutLabel('toggleSnapping');
const checkerboardShortcut = useKeyboardShortcutLabel('toggleCheckerboard');
+ const pixelGridShortcut = useKeyboardShortcutLabel('togglePixelGrid');
const quickSwitcherShortcut = useKeyboardShortcutLabel('quickSwitcher');
const setInPointShortcut = useKeyboardShortcutLabel('setInPoint');
const setOutPointShortcut = useKeyboardShortcutLabel('setOutPoint');
@@ -562,7 +563,9 @@ export const useMenuStructure = (
},
{
id: 'pixel-grid',
- keyHint: null,
+ keyHint: keyboardShortcutsDisabled
+ ? null
+ : pixelGridShortcut || null,
label: 'Pixel Grid',
onClick: () => {
closeMenu();
@@ -1193,6 +1196,7 @@ export const useMenuStructure = (
askAIShortcut,
colorPickerShortcut,
checkerboardShortcut,
+ pixelGridShortcut,
clearInOutPointsShortcut,
goToFrameShortcut,
quickSwitcherShortcut,