Skip to content

Commit ab3d557

Browse files
committed
Panel resizing
1 parent 40e3c75 commit ab3d557

File tree

5 files changed

+59
-23
lines changed

5 files changed

+59
-23
lines changed

ui/arduino/main.css

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,18 @@ button.small .icon {
269269
transition: height 0.15s;
270270
}
271271

272-
#panel.closed {
273-
height: 45px;
272+
#panel {
273+
min-height: 45px;
274274
}
275275

276-
#panel.open {
277-
height: 320px;
276+
#panel #drag-handle {
277+
width: 100%;
278+
height: 100%;
279+
cursor: grab;
280+
}
281+
282+
#panel #drag-handle:active {
283+
cursor: grabbing;
278284
}
279285

280286
.panel-bar {
@@ -300,6 +306,7 @@ button.small .icon {
300306
.panel-bar .term-operations.hidden {
301307
opacity: 0;
302308
transition-delay: 0.15s;
309+
pointer-events: none;
303310
}
304311
.panel-bar .term-operations.visible {
305312
opacity: 1;

ui/arduino/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
const PANEL_HEIGHT = 320
1+
const PANEL_CLOSED = 45
2+
const PANEL_TOO_SMALL = 65
3+
const PANEL_DEFAULT = 320
24

35
function App(state, emit) {
46
if (state.diskNavigationRoot == null) {

ui/arduino/store.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ async function store(state, emitter) {
3333
state.isConnected = false
3434
state.connectedPort = null
3535

36-
37-
state.isPanelOpen = false
3836
state.isSaving = false
3937
state.savingProgress = 0
4038
state.isTransferring = false
@@ -53,6 +51,14 @@ async function store(state, emitter) {
5351
state.openFiles.push(newFile)
5452
state.editingFile = newFile.id
5553

54+
state.savedPanelHeight = PANEL_DEFAULT
55+
state.panelHeight = PANEL_CLOSED
56+
state.resizePanel = function(e) {
57+
state.panelHeight = (PANEL_CLOSED/2) + document.body.clientHeight - e.clientY
58+
state.savedPanelHeight = state.panelHeight
59+
emitter.emit('render')
60+
}
61+
5662
// START AND BASIC ROUTING
5763
emitter.on('select-disk-navigation-root', async () => {
5864
const folder = await selectDiskFolder()
@@ -110,8 +116,8 @@ async function store(state, emitter) {
110116
// Connected and ready
111117
state.isConnecting = false
112118
state.isConnected = true
113-
if (state.view === 'editor') {
114-
state.isPanelOpen = true
119+
if (state.view === 'editor' && state.panelHeight <= PANEL_CLOSED) {
120+
state.panelHeight = state.savedPanelHeight
115121
}
116122
state.connectedPort = path
117123

@@ -138,7 +144,7 @@ async function store(state, emitter) {
138144
emitter.on('disconnect', async () => {
139145
await serial.disconnect()
140146
state.isConnected = false
141-
state.isPanelOpen = false
147+
state.panelHeight = PANEL_CLOSED
142148
state.boardFiles = []
143149
state.boardNavigationPath = '/'
144150
emitter.emit('refresh-files')
@@ -155,9 +161,9 @@ async function store(state, emitter) {
155161
// CODE EXECUTION
156162
emitter.on('run', async () => {
157163
log('run')
158-
state.isPanelOpen = true
159164
const openFile = state.openFiles.find(f => f.id == state.editingFile)
160165
const code = openFile.editor.editor.state.doc.toString()
166+
emitter.emit('open-panel')
161167
emitter.emit('render')
162168
try {
163169
await serial.get_prompt()
@@ -168,13 +174,19 @@ async function store(state, emitter) {
168174
})
169175
emitter.on('stop', async () => {
170176
log('stop')
171-
state.isPanelOpen = true
177+
if (state.panelHeight <= PANEL_CLOSED) {
178+
state.panelHeight = state.savedPanelHeight
179+
}
180+
emitter.emit('open-panel')
172181
emitter.emit('render')
173182
await serial.get_prompt()
174183
})
175184
emitter.on('reset', async () => {
176185
log('reset')
177-
state.isPanelOpen = true
186+
if (state.panelHeight <= PANEL_CLOSED) {
187+
state.panelHeight = state.savedPanelHeight
188+
}
189+
emitter.emit('open-panel')
178190
emitter.emit('render')
179191
await serial.reset()
180192
emitter.emit('update-files')
@@ -183,16 +195,28 @@ async function store(state, emitter) {
183195

184196
// PANEL
185197
emitter.on('open-panel', () => {
186-
state.isPanelOpen = true
198+
state.panelHeight = state.savedPanelHeight
187199
emitter.emit('render')
200+
setTimeout(() => {
201+
state.cache(XTerm, 'terminal').resizeTerm()
202+
}, 200)
188203
})
189204
emitter.on('close-panel', () => {
190-
state.isPanelOpen = false
205+
state.savedPanelHeight = state.panelHeight
206+
state.panelHeight = 0
191207
emitter.emit('render')
192208
})
193209
emitter.on('clear-terminal', () => {
194210
state.cache(XTerm, 'terminal').term.clear()
195211
})
212+
emitter.on('start-resizing-panel', () => {
213+
log('start-resizing-panel')
214+
window.addEventListener('mousemove', state.resizePanel)
215+
})
216+
emitter.on('stop-resizing-panel', () => {
217+
log('stop-resizing-panel')
218+
window.removeEventListener('mousemove', state.resizePanel)
219+
})
196220

197221
// SAVING
198222
emitter.on('save', async () => {

ui/arduino/views/components/elements/terminal.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ class XTerm extends Component {
2121
}
2222

2323
resizeTerm() {
24+
// XXX: This should not be querying the DOM like that :o
2425
if (document.querySelector('#panel')) {
25-
let handleSize = 45
2626
const parentStyle = window.getComputedStyle(document.querySelector('#panel'))
2727
const parentWidth = parseInt(parentStyle.getPropertyValue('width'))
28+
const parentHeight = parseInt(parentStyle.getPropertyValue('height'))
2829
const cols = Math.floor(parentWidth / this.term._core._renderService.dimensions.actualCellWidth) - 6
29-
const rows = Math.floor((PANEL_HEIGHT-handleSize) / this.term._core._renderService.dimensions.actualCellHeight) - 2
30+
const rows = Math.floor((parentHeight-PANEL_CLOSED) / this.term._core._renderService.dimensions.actualCellHeight) - 2
3031
this.term.resize(cols, rows)
3132
}
3233
}

ui/arduino/views/components/repl-panel.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
function ReplPanel(state, emit) {
2-
let height = state.isPanelOpen ? PANEL_HEIGHT : 45
3-
42
const onToggle = () => {
5-
if (state.isPanelOpen) {
3+
if (state.panelHeight > PANEL_CLOSED) {
64
emit('close-panel')
75
} else {
86
emit('open-panel')
97
}
108
}
119
const panelOpenClass = state.isPanelOpen ? 'open' : 'closed'
12-
const termOperationsVisibility = state.isPanelOpen ? 'visible' : 'hidden'
10+
const termOperationsVisibility = state.panelHeight > PANEL_TOO_SMALL ? 'visible' : 'hidden'
1311
const terminalDisabledClass = state.isConnected ? 'terminal-enabled' : 'terminal-disabled'
1412

1513
return html`
16-
<div id="panel" class="${panelOpenClass}">
14+
<div id="panel" style="height: ${state.panelHeight}px">
1715
<div class="panel-bar">
16+
<div id="drag-handle"
17+
onmousedown=${() => emit('start-resizing-panel')}
18+
onmouseup=${() => emit('stop-resizing-panel')}
19+
></div>
1820
<div class="term-operations ${termOperationsVisibility}">
1921
${ReplOperations(state, emit)}
2022
</div>
2123
${Button({
22-
icon: `arrow-${state.isPanelOpen ? 'down' : 'up'}.svg`,
24+
icon: `arrow-${state.panelHeight > PANEL_CLOSED ? 'down' : 'up'}.svg`,
2325
size: 'small',
2426
onClick: onToggle
2527
})}

0 commit comments

Comments
 (0)