Skip to content

Commit

Permalink
safety margins for sidebar resize
Browse files Browse the repository at this point in the history
  • Loading branch information
h908714124 committed Aug 15, 2024
1 parent 2c7b992 commit b5470ec
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/main/client/src/feature/game/Game.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const Game = () => {
let countingGroup = !gameHasEnded() && counting ? getCountingGroup(board, cursor_x, cursor_y) : undefined
let sidebarWidth = useLayoutStore(state => state.sidebarWidth)
let vw = useLayoutStore(state => state.vw)
let dragging = useLayoutStore(state => state.dragging)

let context = useMemo(() => {
let dim = board.length
Expand Down Expand Up @@ -128,6 +129,9 @@ export const Game = () => {
if (gameHasEnded()) {
return
}
if (dragging) {
return
}
if (!board.length) {
return
}
Expand All @@ -143,7 +147,7 @@ export const Game = () => {
setCursor_x(-1)
setCursor_y(-1)
}
}, [context, currentPlayer, auth, board.length, counting, gameHasEnded])
}, [context, currentPlayer, auth, board.length, counting, gameHasEnded, dragging])

let onClick = useCallback((e) => {
if (gameHasEnded()) {
Expand Down Expand Up @@ -253,9 +257,10 @@ export const Game = () => {

return (
<div
style={{width: (vw - sidebarWidth) + "px"}}>
<div className="grid justify-center mt-8">
<canvas ref={canvasRef}
style={{width: (vw - sidebarWidth) + "px"}}
className="h-full">
<div className="grid h-full">
<canvas className="place-self-center" ref={canvasRef}
onMouseLeave={() => {
setCursor_x(-1)
setCursor_y(-1)
Expand Down
7 changes: 7 additions & 0 deletions src/main/client/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
@tailwind utilities;

@layer base {
html {
@apply h-full;
}
body {
@apply bg-stone-800;
@apply font-sans;
@apply text-stone-100;
@apply h-full;
}
#root {
@apply h-full;
}
}
5 changes: 4 additions & 1 deletion src/main/client/src/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {

export const useLayoutStore = create(
persist(
(set) => ({
(set, get) => ({
dragging: false,
vw: Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0),
sidebarWidth: 24 * getPixelRem(),
Expand All @@ -20,6 +20,9 @@ export const useLayoutStore = create(
}))
},
setSidebarWidth: (width) => {
let vh = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0)
width = Math.max(200, width)
width = Math.min(Math.abs(get().vw - vh), width)
set(produce(state => {
state.sidebarWidth = width
}))
Expand Down

0 comments on commit b5470ec

Please sign in to comment.