Skip to content

Commit 7e4ece4

Browse files
committed
rectangular chat
1 parent 6c7dee8 commit 7e4ece4

File tree

6 files changed

+46
-32
lines changed

6 files changed

+46
-32
lines changed

src/main/client/src/component/Chat.jsx

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
StompContext,
1616
tfetch,
1717
doTry,
18+
getRemInPixel,
1819
} from "src/util.js"
1920

2021
export const Chat = ({chatId}) => {
@@ -103,7 +104,7 @@ export const Chat = ({chatId}) => {
103104
/>
104105
<form className="flex-none mb-2" onSubmit={onSendMessage}>
105106
<input
106-
className="w-full rounded-lg p-2 border border-gray-500 bg-stone-800 text-stone-100 focus:outline-none"
107+
className="w-full px-1 py-2 border border-gray-500 bg-stone-800 text-stone-100 focus:outline-none"
107108
type="text"
108109
name="message"
109110
/>
@@ -124,7 +125,7 @@ function isLastChildVisible(container) {
124125

125126
function SplitPane({messageRef, topElement, bottomElement}) {
126127
let [dragging, setDragging] = useState(false)
127-
let [splitPos, setSplitPos] = useState(200.5)
128+
let [splitPos, setSplitPos] = useState(200)
128129
let draggingRef = useRef()
129130
let containerRef = useRef()
130131
draggingRef.current = dragging
@@ -133,13 +134,13 @@ function SplitPane({messageRef, topElement, bottomElement}) {
133134
if (!draggingRef.current) {
134135
return
135136
}
136-
setSplitPos(getSplitPos(e.clientY, containerRef))
137+
setSplitPos(getSplitPos(e.clientY, containerRef.current))
137138
}
138139
let mouseup = (e) => {
139140
if (!draggingRef.current) {
140141
return
141142
}
142-
setSplitPos(getSplitPos(e.clientY, containerRef))
143+
setSplitPos(getSplitPos(e.clientY, containerRef.current))
143144
setDragging(false)
144145
}
145146
window.document.addEventListener("mousemove", mousemove)
@@ -151,7 +152,7 @@ function SplitPane({messageRef, topElement, bottomElement}) {
151152
}, [draggingRef, setDragging])
152153
let onMouseDown = useCallback((e) => {
153154
e.preventDefault()
154-
setSplitPos(getSplitPos(e.clientY, containerRef))
155+
setSplitPos(getSplitPos(e.clientY, containerRef.current))
155156
setDragging(true)
156157
}, [setDragging, setSplitPos])
157158
let topElementHeight = Math.trunc(splitPos)
@@ -162,10 +163,17 @@ function SplitPane({messageRef, topElement, bottomElement}) {
162163
return (
163164
<div
164165
ref={(ref) => {
166+
if (!ref) {
167+
return
168+
}
169+
if (!containerRef.current) {
170+
let rect = ref.getBoundingClientRect()
171+
setSplitPos(getSplitPos(rect.top, ref))
172+
}
165173
containerRef.current = ref
166174
}}
167175
className={twJoin(
168-
"grow border border-gray-500 bg-gray-900 rounded-lg flex flex-col overflow-y-hidden",
176+
"grow border-t border-x border-gray-500 bg-gray-900 flex flex-col overflow-y-hidden",
169177
dragging && "cursor-row-resize",
170178
)}>
171179
<div
@@ -174,7 +182,7 @@ function SplitPane({messageRef, topElement, bottomElement}) {
174182
{topElement}
175183
</div>
176184
<SplitBar
177-
containerRef={containerRef}
185+
container={containerRef.current}
178186
splitPos={splitPos}
179187
dragging={dragging}
180188
onMouseDown={onMouseDown} />
@@ -185,35 +193,38 @@ function SplitPane({messageRef, topElement, bottomElement}) {
185193
)
186194
}
187195

188-
function SplitBar({splitPos, dragging, onMouseDown, containerRef}) {
189-
let width = 100, left = 10 // some default values
190-
if (containerRef.current) {
191-
let container = containerRef.current
192-
let rect = containerRef.current.getBoundingClientRect()
193-
let parentRect = container.parentNode.getBoundingClientRect()
194-
width = rect.width
195-
left = rect.left - parentRect.left
196+
function SplitBar({splitPos, dragging, onMouseDown, container}) {
197+
if (!container) {
198+
return <div />
196199
}
200+
let innerHeight = Math.trunc(getRemInPixel() * 0.5)
201+
let rect = container.getBoundingClientRect()
202+
let parentRect = container.parentNode.getBoundingClientRect()
203+
let width = rect.width
204+
let left = rect.left - parentRect.left
197205
return <>
198206
<div
199207
onMouseDown={dragging ? undefined : onMouseDown}
200-
style={{top: Math.trunc(splitPos - 1) + 0.5, width: width, left: left}}
208+
style={{top: Math.trunc(splitPos - 1) + 0.5, height: 1, width: width, left: left}}
201209
className="absolute h-[1px] bg-gray-500 z-20 cursor-row-resize" />
202210
<div
203211
onMouseDown={dragging ? undefined : onMouseDown}
204-
style={{top: Math.trunc(splitPos) + 0.5, width: width, left: left}}
205-
className="absolute h-[5px] bg-slate-800 z-20 cursor-row-resize" />
212+
style={{top: Math.trunc(splitPos) + 0.5, height: innerHeight, width: width, left: left}}
213+
className="absolute bg-slate-800 z-20 cursor-row-resize" />
206214
<div
207215
onMouseDown={dragging ? undefined : onMouseDown}
208-
style={{top: Math.trunc(splitPos + 5) + 0.5, width: width, left: left}}
216+
style={{top: Math.trunc(splitPos + innerHeight) + 0.5, height: 1, width: width, left: left}}
209217
className="absolute h-[1px] bg-gray-500 z-20 cursor-row-resize" />
210218
</>
211219
}
212220

213-
function getSplitPos(clientY, containerRef) {
214-
let rect = containerRef.current.getBoundingClientRect()
215-
let result = clientY
216-
result = Math.max(rect.top + 40, result)
217-
result = Math.min(rect.top + rect.height - 40, result)
221+
function getSplitPos(clientY, container) {
222+
if (!container) {
223+
return Math.trunc(clientY)
224+
}
225+
let rect = container.getBoundingClientRect()
226+
let safety = 4 * getRemInPixel()
227+
let result = Math.max(rect.top + safety, clientY)
228+
result = Math.min(rect.top + rect.height - safety, result)
218229
return Math.trunc(result)
219230
}

src/main/client/src/component/SideBar.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const SideBar = ({page, children}) => {
5454
return (
5555
<div
5656
style={{width: sidebarWidth + "px"}}
57-
className="fixed absolute top-0 right-0 h-full bg-slate-800">
57+
className="fixed top-0 right-0 h-full bg-slate-800">
5858
<div
5959
onMouseDown={onMouseDown}
6060
style={{right: sidebarWidth + "px"}}

src/main/client/src/feature/game/GamePanel.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import {
4444
export const GamePanel = () => {
4545
return (
4646
<SideBar page="game">
47-
<div className="pr-3 pt-4 pl-2 h-full flex flex-col gap-y-1">
47+
<div className="pr-3 pt-4 pl-2 h-full flex flex-col">
4848
<Panel />
4949
</div>
5050
</SideBar>

src/main/client/src/feature/lobby/LobbyPanel.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
export const LobbyPanel = () => {
1919
return (
2020
<SideBar page="lobby">
21-
<div className="pr-3 pt-2 pl-2 h-full flex flex-col gap-y-1">
21+
<div className="pr-3 pt-2 pl-2 h-full flex flex-col">
2222
<Panel />
2323
</div>
2424
</SideBar>

src/main/client/src/layout.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import {
77
import {
88
persist,
99
} from "zustand/middleware"
10+
import {
11+
getRemInPixel,
12+
} from "src/util.js"
1013

1114
const TINY = 0.0001220703125
1215

@@ -47,8 +50,3 @@ export const useLayoutStore = create(
4750
{name: "layout-storage"},
4851
),
4952
)
50-
51-
function getRemInPixel() {
52-
let fontSize = window.getComputedStyle(window.document.documentElement).fontSize
53-
return Math.trunc(parseFloat(fontSize))
54-
}

src/main/client/src/util.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,8 @@ export function vh() {
110110
export function sanitizeSidebarWidth(width) {
111111
return Math.min(Math.abs(vw() - vh()), Math.max(200, width))
112112
}
113+
114+
export function getRemInPixel() {
115+
let fontSize = window.getComputedStyle(document.documentElement).fontSize
116+
return parseFloat(fontSize)
117+
}

0 commit comments

Comments
 (0)