diff --git a/.changeset/feat_image_viewer_changes.md b/.changeset/feat_image_viewer_changes.md index 6910066a4..70a0eb579 100644 --- a/.changeset/feat_image_viewer_changes.md +++ b/.changeset/feat_image_viewer_changes.md @@ -4,11 +4,11 @@ default: minor Change Image Viewer to feel more natural to use. -#Changes to Image viewer: +# Changes to Image viewer -- Fixed Zoom Gestures generally not working on mobile. +- Fixed zoom gestures generally not working on mobile. - Changed the % number in the top right to reflect the zoom of the original image as opposed to the change from it fitting the container. -- Made Zoom Pill allow inputing custom values -- Added a button thta zooms you to the Original Size of the Image, and button to return to the Actual size of the image -- Made Images have the `pixelated` tag, and start zoomed in when smaller than container to enhance the experience of viewing pixelart, with the pixelated tag being applied to images in the chat aswell. -- Transitions are now disabled for manual panning to improve responsiveness +- Made the zoom pill allow entering custom values. +- Added a button that zooms you to the original size of the image, and a button to return to the size that fills the container. +- Added a pixelated image scaling setting: choose Both, Chat, Image viewer (default), or Neither for crisp nearest-neighbor rendering. +- Transitions are now disabled for manual panning to improve responsiveness. diff --git a/src/app/components/image-viewer/ImageViewer.css.ts b/src/app/components/image-viewer/ImageViewer.css.ts index 939198405..058c6ce68 100644 --- a/src/app/components/image-viewer/ImageViewer.css.ts +++ b/src/app/components/image-viewer/ImageViewer.css.ts @@ -45,7 +45,6 @@ export const ImageViewerImg = style([ userSelect: 'none', touchAction: 'none', display: 'block', - imageRendering: 'pixelated', // Possibly allow for a custom setting later? objectFit: 'contain', width: 'auto', height: 'auto', @@ -56,3 +55,7 @@ export const ImageViewerImg = style([ willChange: 'transform', }, ]); + +export const ImageViewerImgPixelated = style({ + imageRendering: 'pixelated', +}); diff --git a/src/app/components/image-viewer/ImageViewer.tsx b/src/app/components/image-viewer/ImageViewer.tsx index 4f2dda8af..214347b3d 100644 --- a/src/app/components/image-viewer/ImageViewer.tsx +++ b/src/app/components/image-viewer/ImageViewer.tsx @@ -3,6 +3,8 @@ import FileSaver from 'file-saver'; import classNames from 'classnames'; import { Box, Chip, Header, Icon, IconButton, Icons, Text, as } from 'folds'; import { useImageGestures } from '$hooks/useImageGestures'; +import { useSetting } from '$state/hooks/settings'; +import { isPixelatedViewerRendering, settingsAtom } from '$state/settings'; import { downloadMedia } from '$utils/matrix'; import * as css from './ImageViewer.css'; @@ -15,6 +17,7 @@ export type ImageViewerProps = { export const ImageViewer = as<'div', ImageViewerProps>( ({ className, alt, src, requestClose, ...props }, ref) => { const zoomInputRef = useRef(null); + const [pixelatedImageRendering] = useSetting(settingsAtom, 'pixelatedImageRendering'); const [isImageReady, setIsImageReady] = useState(false); const [isEditingZoom, setIsEditingZoom] = useState(false); @@ -222,7 +225,10 @@ export const ImageViewer = as<'div', ImageViewerProps>( onPointerDown={onPointerDown} > >( - ({ className, alt, ...props }, ref) => ( - {alt} - ) + ({ className, alt, ...props }, ref) => { + const [pixelatedImageRendering] = useSetting(settingsAtom, 'pixelatedImageRendering'); + + return ( + {alt} + ); + } ); diff --git a/src/app/components/media/media.css.ts b/src/app/components/media/media.css.ts index 3c2be3cda..4253b52d2 100644 --- a/src/app/components/media/media.css.ts +++ b/src/app/components/media/media.css.ts @@ -7,10 +7,13 @@ export const Image = style([ objectFit: 'contain', width: '100%', height: '100%', - imageRendering: 'pixelated', }, ]); +export const ImagePixelated = style({ + imageRendering: 'pixelated', +}); + export const Video = style([ DefaultReset, { diff --git a/src/app/features/settings/cosmetics/Themes.tsx b/src/app/features/settings/cosmetics/Themes.tsx index e00e5f425..7bf5300e6 100644 --- a/src/app/features/settings/cosmetics/Themes.tsx +++ b/src/app/features/settings/cosmetics/Themes.tsx @@ -18,7 +18,7 @@ import { } from 'folds'; import { isKeyHotkey } from 'is-hotkey'; -import { SettingMenuSelector } from '$components/setting-menu-selector'; +import { SettingMenuSelector, type SettingMenuOption } from '$components/setting-menu-selector'; import { SequenceCard } from '$components/sequence-card'; import { SettingTile } from '$components/setting-tile'; import { @@ -29,7 +29,7 @@ import { } from '$plugins/arborium'; import { ThemeKind, useActiveTheme } from '$hooks/useTheme'; import { useSetting } from '$state/hooks/settings'; -import type { ShowRoomIcon } from '$state/settings'; +import type { PixelatedImageRenderingMode, ShowRoomIcon } from '$state/settings'; import { settingsAtom } from '$state/settings'; import { SequenceCardStyle } from '$features/settings/styles.css'; import { ThemeAppearanceSection } from './ThemeAppearanceSection'; @@ -216,6 +216,16 @@ function ThemeVisualPreferences() { const [autoplayGifs, setAutoplayGifs] = useSetting(settingsAtom, 'autoplayGifs'); const [autoplayStickers, setAutoplayStickers] = useSetting(settingsAtom, 'autoplayStickers'); const [autoplayEmojis, setAutoplayEmojis] = useSetting(settingsAtom, 'autoplayEmojis'); + const [pixelatedImageRendering, setPixelatedImageRendering] = useSetting( + settingsAtom, + 'pixelatedImageRendering' + ); + const pixelatedImageRenderingOptions: SettingMenuOption[] = [ + { value: 'both', label: 'Both' }, + { value: 'chat', label: 'Chat' }, + { value: 'viewer', label: 'Image viewer' }, + { value: 'none', label: 'Neither' }, + ]; const [incomingInlineImagesDefaultHeight, setIncomingInlineImagesDefaultHeight] = useSetting( settingsAtom, 'incomingInlineImagesDefaultHeight' @@ -327,6 +337,20 @@ function ThemeVisualPreferences() { after={} /> + + + } + /> + ): void { parsed.renderUserCards = 'both'; } + if (typeof parsed.pixelatedImageRendering === 'boolean') { + parsed.pixelatedImageRendering = parsed.pixelatedImageRendering ? 'both' : 'none'; + } else if ( + parsed.pixelatedImageRendering !== 'both' && + parsed.pixelatedImageRendering !== 'chat' && + parsed.pixelatedImageRendering !== 'viewer' && + parsed.pixelatedImageRendering !== 'none' + ) { + delete parsed.pixelatedImageRendering; + } + if ( typeof parsed.themeChatAutoPreviewAnyUrl !== 'boolean' && typeof parsed.themeChatPreviewAnyUrl === 'boolean' @@ -475,6 +499,10 @@ function sanitizeSettingsKey(key: keyof Settings, val: unknown): unknown { return val === 'both' || val === 'light' || val === 'dark' || val === 'none' ? val : undefined; + case 'pixelatedImageRendering': + return val === 'both' || val === 'chat' || val === 'viewer' || val === 'none' + ? val + : undefined; case 'jumboEmojiSize': return typeof val === 'string' && JUMBO_EMOJI_VALUES.has(val as JumboEmojiSize) ? val