2024-10-03 04:02:59 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) Contributors to the Suwayomi project
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import Stack from '@mui/material/Stack';
|
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
import FitScreenIcon from '@mui/icons-material/FitScreen';
|
2025-08-16 02:48:46 +02:00
|
|
|
import { CustomTooltip } from '@/base/components/CustomTooltip.tsx';
|
|
|
|
|
import { ValueRotationButton } from '@/base/components/buttons/ValueRotationButton.tsx';
|
2024-11-04 18:00:35 +01:00
|
|
|
import {
|
|
|
|
|
IReaderSettings,
|
|
|
|
|
IReaderSettingsWithDefaultFlag,
|
|
|
|
|
ReaderPageScaleMode,
|
2025-08-16 02:02:13 +02:00
|
|
|
} from '@/features/reader/Reader.types.ts';
|
2024-11-04 18:00:35 +01:00
|
|
|
import {
|
|
|
|
|
PAGE_SCALE_VALUE_TO_DISPLAY_DATA,
|
|
|
|
|
READER_PAGE_SCALE_MODE_TO_SCALING_ALLOWED,
|
|
|
|
|
READER_PAGE_SCALE_MODE_VALUES,
|
2025-08-16 02:02:13 +02:00
|
|
|
} from '@/features/reader/settings/ReaderSettings.constants.tsx';
|
2025-08-16 02:48:46 +02:00
|
|
|
import { MultiValueButtonDefaultableProps } from '@/base/Base.types.ts';
|
|
|
|
|
import { CustomButtonIcon } from '@/base/components/buttons/CustomButtonIcon.tsx';
|
2024-10-03 04:02:59 +02:00
|
|
|
|
|
|
|
|
export const ReaderNavBarDesktopPageScale = ({
|
|
|
|
|
pageScaleMode,
|
2024-11-04 18:00:35 +01:00
|
|
|
shouldStretchPage,
|
2024-10-03 04:02:59 +02:00
|
|
|
updateSetting,
|
2024-11-04 18:00:35 +01:00
|
|
|
...buttonSelectInputProps
|
|
|
|
|
}: Pick<IReaderSettingsWithDefaultFlag, 'pageScaleMode' | 'shouldStretchPage'> &
|
|
|
|
|
Pick<MultiValueButtonDefaultableProps<ReaderPageScaleMode>, 'isDefaultable' | 'onDefault'> & {
|
|
|
|
|
updateSetting: <Setting extends keyof Pick<IReaderSettings, 'pageScaleMode' | 'shouldStretchPage'>>(
|
|
|
|
|
setting: Setting,
|
|
|
|
|
value: IReaderSettings[Setting],
|
|
|
|
|
) => void;
|
|
|
|
|
}) => {
|
2024-10-03 04:02:59 +02:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Stack sx={{ flexDirection: 'row', gap: 1 }}>
|
|
|
|
|
<ValueRotationButton
|
2024-11-04 18:00:35 +01:00
|
|
|
{...buttonSelectInputProps}
|
2024-12-09 16:24:32 +01:00
|
|
|
tooltip={t('reader.settings.page_scale.title')}
|
2024-11-04 18:00:35 +01:00
|
|
|
value={pageScaleMode.isDefault ? undefined : pageScaleMode.value}
|
2024-12-13 16:38:41 +01:00
|
|
|
defaultValue={pageScaleMode.isDefault ? pageScaleMode.value : undefined}
|
2024-10-03 04:02:59 +02:00
|
|
|
values={READER_PAGE_SCALE_MODE_VALUES}
|
|
|
|
|
setValue={(value) => updateSetting('pageScaleMode', value)}
|
2024-11-04 18:00:35 +01:00
|
|
|
valueToDisplayData={PAGE_SCALE_VALUE_TO_DISPLAY_DATA}
|
|
|
|
|
defaultIcon={PAGE_SCALE_VALUE_TO_DISPLAY_DATA[pageScaleMode.value].icon}
|
2024-10-03 04:02:59 +02:00
|
|
|
/>
|
2024-11-04 18:00:35 +01:00
|
|
|
{READER_PAGE_SCALE_MODE_TO_SCALING_ALLOWED[pageScaleMode.value] && (
|
2025-02-01 14:24:38 +01:00
|
|
|
<CustomTooltip title={t('reader.settings.page_scale.stretch')}>
|
2025-02-08 16:16:32 +01:00
|
|
|
<CustomButtonIcon
|
2024-11-04 18:00:35 +01:00
|
|
|
onClick={() => updateSetting('shouldStretchPage', !shouldStretchPage.value)}
|
2025-02-08 16:16:32 +01:00
|
|
|
sx={{ px: undefined }}
|
2024-10-03 04:02:59 +02:00
|
|
|
variant="contained"
|
2024-11-04 18:00:35 +01:00
|
|
|
color={shouldStretchPage.value ? 'secondary' : 'primary'}
|
2024-10-03 04:02:59 +02:00
|
|
|
>
|
|
|
|
|
<FitScreenIcon />
|
2025-02-08 16:16:32 +01:00
|
|
|
</CustomButtonIcon>
|
2025-02-01 14:24:38 +01:00
|
|
|
</CustomTooltip>
|
2024-10-03 04:02:59 +02:00
|
|
|
)}
|
|
|
|
|
</Stack>
|
|
|
|
|
);
|
|
|
|
|
};
|