Skip to content

Commit

Permalink
feat: support zoom in/out (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
Okabe-Rintarou-0 committed Jun 25, 2024
1 parent 3cddca3 commit dce333a
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sjtu_canvas_helper"
version = "1.3.11"
version = "1.3.12"
description = "SJTU Canvas Helper"
authors = ["Okabe"]
edition = "2021"
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"package": {
"productName": "SJTU Canvas Helper",
"version": "1.3.11"
"version": "1.3.12"
},
"tauri": {
"allowlist": {
Expand Down
6 changes: 6 additions & 0 deletions src/components/change_log_modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ export function ChangeLogModal({ open, onCancel, onOk }: {
overflow: "scroll",
}}>
<Typography>
<Title level={4}>v1.3.12 2024/6/25</Title>
<Paragraph>
<ul>
<li>[Enhancement] 支持按 `ctrl`(`command`) + `=` 和 `ctrl`(`command`) + `-` 进行缩放(源自 Issue: <a target="_blank" href="https://github.com/Okabe-Rintarou-0/SJTU-Canvas-Helper/issues/31">https://github.com/Okabe-Rintarou-0/SJTU-Canvas-Helper/issues/31</a>)</li>
</ul>
</Paragraph>
<Title level={4}>v1.3.11 2024/6/18</Title>
<Paragraph>
<ul>
Expand Down
19 changes: 19 additions & 0 deletions src/components/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { BsQrCode } from 'react-icons/bs';
import { GoDiscussionOutdated } from 'react-icons/go';
import { ChangeLogModal } from './change_log_modal';
import { LuBookOpenCheck } from 'react-icons/lu';
import { useKeyPress } from '../lib/hooks';

const { Content, Footer, Sider } = Layout;

Expand Down Expand Up @@ -67,6 +68,20 @@ export default function BasicLayout({ children }: React.PropsWithChildren) {
token: { colorBgContainer, borderRadiusLG },
} = theme.useToken();

const [scale, setScale] = useState(1);

const zoomIn = () => {
console.log("zoom in")
setScale(prevScale => prevScale + 0.1);
};

const zoomOut = () => {
setScale(prevScale => Math.max(0.1, prevScale - 0.1));
};

useKeyPress('=', zoomIn);
useKeyPress('-', zoomOut);

return <Layout style={{ minHeight: "100vh" }}>
<Sider theme="light" style={{ position: 'fixed', height: '100%' }}>
<Menu theme="light" mode="inline" defaultSelectedKeys={selectedKeys} items={items} />
Expand All @@ -79,6 +94,10 @@ export default function BasicLayout({ children }: React.PropsWithChildren) {
minHeight: 360,
background: colorBgContainer,
borderRadius: borderRadiusLG,
zoom: scale,
transformOrigin: 'top left',
width: '100%',
height: '100%',
}}
>
{children}
Expand Down
18 changes: 17 additions & 1 deletion src/lib/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -512,4 +512,20 @@ export function useCourseFolders(courseId?: number) {
}, [courseId]);
const shouldFetch = courseId != undefined;
return useData<Folder[]>("list_course_folders", shouldFetch, args);
}
}
export const useKeyPress = (targetKey: string, action: () => void) => {
useEffect(() => {
const keyHandler = (event: KeyboardEvent) => {
if ((event.ctrlKey || event.metaKey) && event.key === targetKey) {
event.preventDefault();
action();
}
};

window.addEventListener('keydown', keyHandler);

return () => {
window.removeEventListener('keydown', keyHandler);
};
}, [targetKey, action]);
};

0 comments on commit dce333a

Please sign in to comment.