-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add github icon and homepage toast * fix: online mode cant load size module * feat: add size module loading and reset * feat: add background * fix: background adapt * feat: add screen self-adaptation
- Loading branch information
1 parent
a1b6818
commit 9b98a35
Showing
7 changed files
with
115 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { useStore } from "@/contexts"; | ||
import { throttle } from "@/utils/throttle"; | ||
import React, { useEffect, useRef, useState } from "react"; | ||
|
||
function GridBackground() { | ||
const canvasRef = useRef(null); | ||
const { theme } = useStore((state) => state); | ||
const [innerWidth, setInnerWidth] = useState(window.innerWidth); | ||
const [innerHeight, setInnerHeight] = useState(window.innerHeight); | ||
|
||
useEffect(() => { | ||
window.addEventListener( | ||
"resize", | ||
throttle(() => { | ||
setInnerWidth(window.innerWidth); | ||
setInnerHeight(window.innerHeight); | ||
}), | ||
); | ||
|
||
const canvas = canvasRef.current; | ||
const ctx = canvas.getContext("2d"); | ||
|
||
// 设置Canvas的宽度和高度 | ||
canvas.width = innerWidth; | ||
canvas.height = innerHeight; | ||
|
||
// 定义格子的大小和间隔 | ||
const gridSpacing = 30; | ||
|
||
// 绘制格子背景 | ||
if (theme === "light") { | ||
ctx.strokeStyle = "#000000e0"; // 格子线的颜色 | ||
} else { | ||
ctx.strokeStyle = "#ffffffd9"; // 格子线的颜色 | ||
} | ||
ctx.lineWidth = 0.1; | ||
|
||
for (let x = 0; x < canvas.width; x += gridSpacing) { | ||
ctx.beginPath(); | ||
ctx.moveTo(x, 0); | ||
ctx.lineTo(x, canvas.height); | ||
ctx.stroke(); | ||
} | ||
|
||
for (let y = 0; y < canvas.height; y += gridSpacing) { | ||
ctx.beginPath(); | ||
ctx.moveTo(0, y); | ||
ctx.lineTo(canvas.width, y); | ||
ctx.stroke(); | ||
} | ||
}, [theme, innerWidth, innerHeight]); | ||
|
||
return ( | ||
<div> | ||
<canvas ref={canvasRef} /> | ||
</div> | ||
); | ||
} | ||
|
||
export default GridBackground; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const throttle = (func, delay = 500) => { | ||
let timer = null; | ||
return (...args) => { | ||
if (timer) return; | ||
timer = setTimeout(() => { | ||
func(...args); | ||
timer = null; | ||
}, delay); | ||
}; | ||
}; |