add setting for pixelated rendering and update changeset

This commit is contained in:
7w1 committed 2026-05-18 17:40:18 -05:00
1 parent e97b02d707
commit d7912ec397
8 files changed
+94 -14

No files matched your search

+6 -6
View File
@@ -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.
@@ -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',
});
@@ -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<HTMLInputElement>(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}
>
<img
className={css.ImageViewerImg}
className={classNames(
css.ImageViewerImg,
isPixelatedViewerRendering(pixelatedImageRendering) && css.ImageViewerImgPixelated
)}
draggable={false}
data-gestures="ignore"
style={{
+18 -3
View File
@@ -1,10 +1,25 @@
import type { ImgHTMLAttributes } from 'react';
import { forwardRef } from 'react';
import classNames from 'classnames';
import { useSetting } from '$state/hooks/settings';
import { isPixelatedChatRendering, settingsAtom } from '$state/settings';
import * as css from './media.css';
export const Image = forwardRef<HTMLImageElement, ImgHTMLAttributes<HTMLImageElement>>(
({ className, alt, ...props }, ref) => (
<img className={classNames(css.Image, className)} alt={alt} {...props} ref={ref} />
)
({ className, alt, ...props }, ref) => {
const [pixelatedImageRendering] = useSetting(settingsAtom, 'pixelatedImageRendering');
return (
<img
className={classNames(
css.Image,
isPixelatedChatRendering(pixelatedImageRendering) && css.ImagePixelated,
className
)}
alt={alt}
{...props}
ref={ref}
/>
);
}
);
+4 -1
View File
@@ -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,
{
+26 -2
View File
@@ -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<PixelatedImageRenderingMode>[] = [
{ 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={<Switch variant="Primary" value={autoplayGifs} onChange={setAutoplayGifs} />}
/>
</SequenceCard>
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
<SettingTile
title="Pixelated image scaling"
focusId="pixelated-image-rendering"
description="Use crisp nearest-neighbor scaling where selected. Improves pixel art but makes normal images worse."
after={
<SettingMenuSelector
value={pixelatedImageRendering}
options={pixelatedImageRenderingOptions}
onSelect={setPixelatedImageRendering}
/>
}
/>
</SequenceCard>
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
<SettingTile
title="Autoplay Stickers"
@@ -99,6 +99,7 @@ const settingsLinkFocusIdsBySection: Record<SettingsSectionId, readonly string[]
'manual-theme',
'message-link-preview',
'page-zoom',
'pixelated-image-rendering',
'catalog-themes',
'catalog-tweaks',
'theme-browse-remote',
+28
View File
@@ -50,6 +50,17 @@ export type ThemeRemoteTweakFavorite = {
/** Custom profile card hero colors: which brightness schemes to honor. */
export type RenderUserCardsMode = 'both' | 'light' | 'dark' | 'none';
/** Where to use crisp nearest-neighbor (pixelated) image scaling. */
export type PixelatedImageRenderingMode = 'both' | 'chat' | 'viewer' | 'none';
export function isPixelatedChatRendering(mode: PixelatedImageRenderingMode): boolean {
return mode === 'both' || mode === 'chat';
}
export function isPixelatedViewerRendering(mode: PixelatedImageRenderingMode): boolean {
return mode === 'both' || mode === 'viewer';
}
export function shouldApplyUserHeroCards(
mode: RenderUserCardsMode,
brightness: string | undefined
@@ -146,6 +157,7 @@ export interface Settings {
autoplayGifs: boolean;
autoplayStickers: boolean;
autoplayEmojis: boolean;
pixelatedImageRendering: PixelatedImageRenderingMode;
incomingInlineImagesDefaultHeight: number;
incomingInlineImagesMaxHeight: number;
linkPreviewImageMaxHeight: number;
@@ -278,6 +290,7 @@ export const defaultSettings: Settings = {
autoplayGifs: true,
autoplayStickers: true,
autoplayEmojis: true,
pixelatedImageRendering: 'viewer',
incomingInlineImagesDefaultHeight: 32,
incomingInlineImagesMaxHeight: 64,
linkPreviewImageMaxHeight: 640,
@@ -352,6 +365,17 @@ function migrateParsedLocalStorage(parsed: Record<string, unknown>): 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