Skip to content

Commit d08ecaa

Browse files
authored
Merge pull request #105 from arduino/feature/resize-panel
Feature/resize panel
2 parents 9b9115c + 2ac39df commit d08ecaa

File tree

7 files changed

+92
-30
lines changed

7 files changed

+92
-30
lines changed

ui/arduino/main.css

+31-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
@import url('https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@400;700&display=swap');
1+
@font-face {
2+
font-family: "RobotoMono", monospace;
3+
src:
4+
url("media/roboto-mono-latin-ext-400-normal.woff"),
5+
url("media/roboto-mono-latin-ext-400-normal.woff2");
6+
font-weight: normal;
7+
font-style: normal;
8+
}
29

310
* {
411
/* box-sizing: border-box; */
512
-moz-user-select: none;
613
-webkit-user-select: none;
714
user-select: none;
15+
font-family: "RobotoMono", monospace;
816
}
917

1018
body, html {
@@ -31,6 +39,7 @@ button {
3139
border-radius: 45px;
3240
background: rgba(255, 255, 255, 0.8);
3341
cursor: pointer;
42+
transition: all 0.1s;
3443
}
3544
button.small {
3645
width: 28px;
@@ -99,7 +108,7 @@ button.small .icon {
99108
height: 100%;
100109
justify-content: center;
101110
align-items: center;
102-
font-family: Roboto Mono;
111+
font-family: "RobotoMono", monospace;
103112
overflow: hidden;
104113
}
105114

@@ -141,6 +150,7 @@ button.small .icon {
141150
cursor: pointer;
142151
background: #DAE3E3;
143152
overflow: hidden;
153+
transition: all 0.1s;
144154
}
145155

146156
.tab:hover {
@@ -259,12 +269,18 @@ button.small .icon {
259269
transition: height 0.15s;
260270
}
261271

262-
#panel.closed {
263-
height: 45px;
272+
#panel {
273+
min-height: 45px;
274+
}
275+
276+
#panel #drag-handle {
277+
width: 100%;
278+
height: 100%;
279+
cursor: grab;
264280
}
265281

266-
#panel.open {
267-
height: 320px;
282+
#panel #drag-handle:active {
283+
cursor: grabbing;
268284
}
269285

270286
.panel-bar {
@@ -290,6 +306,7 @@ button.small .icon {
290306
.panel-bar .term-operations.hidden {
291307
opacity: 0;
292308
transition-delay: 0.15s;
309+
pointer-events: none;
293310
}
294311
.panel-bar .term-operations.visible {
295312
opacity: 1;
@@ -445,7 +462,7 @@ button.small .icon {
445462
position: relative;
446463
cursor: pointer;
447464
color: #000;
448-
font-family: Roboto Mono;
465+
font-family: "RobotoMono", monospace;
449466
font-size: 14px;
450467
font-style: normal;
451468
font-weight: 400;
@@ -472,7 +489,7 @@ button.small .icon {
472489
width: 30px;
473490
height: 100%;
474491
background: linear-gradient(0.25turn, white 25%, rgba(0, 0, 0, 0));
475-
z-index: 99;
492+
z-index: 98;
476493
}
477494

478495
.file-list {
@@ -504,6 +521,7 @@ button.small .icon {
504521
align-items: center;
505522
gap: 10px;
506523
align-self: stretch;
524+
transition: all 0.1s;
507525
}
508526

509527
.file-list .item.selected,
@@ -512,14 +530,16 @@ button.small .icon {
512530
}
513531

514532
.file-list .item .options {
515-
display: none;
533+
display: flex;
534+
opacity: 0;
516535
align-items: center;
517536
align-self: stretch;
518537
cursor: pointer;
538+
transition: all 0.1s;
519539
}
520540

521541
.file-list .item:hover .options {
522-
display: flex;
542+
opacity: 1;
523543
}
524544

525545
.file-list .item .icon {
@@ -528,7 +548,7 @@ button.small .icon {
528548
}
529549
.file-list .item .text {
530550
color: #000;
531-
font-family: Roboto Mono;
551+
font-family: "RobotoMono", monospace;
532552
font-size: 14px;
533553
font-style: normal;
534554
font-weight: 400;

ui/arduino/main.js

+3-1
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) {
Binary file not shown.
Binary file not shown.

ui/arduino/store.js

+47-10
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,18 @@ 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+
if (state.panelHeight <= PANEL_CLOSED) {
59+
state.savedPanelHeight = PANEL_DEFAULT
60+
} else {
61+
state.savedPanelHeight = state.panelHeight
62+
}
63+
emitter.emit('render')
64+
}
65+
5666
// START AND BASIC ROUTING
5767
emitter.on('select-disk-navigation-root', async () => {
5868
const folder = await selectDiskFolder()
@@ -110,8 +120,8 @@ async function store(state, emitter) {
110120
// Connected and ready
111121
state.isConnecting = false
112122
state.isConnected = true
113-
if (state.view === 'editor') {
114-
state.isPanelOpen = true
123+
if (state.view === 'editor' && state.panelHeight <= PANEL_CLOSED) {
124+
state.panelHeight = state.savedPanelHeight
115125
}
116126
state.connectedPort = path
117127

@@ -138,7 +148,7 @@ async function store(state, emitter) {
138148
emitter.on('disconnect', async () => {
139149
await serial.disconnect()
140150
state.isConnected = false
141-
state.isPanelOpen = false
151+
state.panelHeight = PANEL_CLOSED
142152
state.boardFiles = []
143153
state.boardNavigationPath = '/'
144154
emitter.emit('refresh-files')
@@ -155,9 +165,9 @@ async function store(state, emitter) {
155165
// CODE EXECUTION
156166
emitter.on('run', async () => {
157167
log('run')
158-
state.isPanelOpen = true
159168
const openFile = state.openFiles.find(f => f.id == state.editingFile)
160169
const code = openFile.editor.editor.state.doc.toString()
170+
emitter.emit('open-panel')
161171
emitter.emit('render')
162172
try {
163173
await serial.get_prompt()
@@ -168,13 +178,19 @@ async function store(state, emitter) {
168178
})
169179
emitter.on('stop', async () => {
170180
log('stop')
171-
state.isPanelOpen = true
181+
if (state.panelHeight <= PANEL_CLOSED) {
182+
state.panelHeight = state.savedPanelHeight
183+
}
184+
emitter.emit('open-panel')
172185
emitter.emit('render')
173186
await serial.get_prompt()
174187
})
175188
emitter.on('reset', async () => {
176189
log('reset')
177-
state.isPanelOpen = true
190+
if (state.panelHeight <= PANEL_CLOSED) {
191+
state.panelHeight = state.savedPanelHeight
192+
}
193+
emitter.emit('open-panel')
178194
emitter.emit('render')
179195
await serial.reset()
180196
emitter.emit('update-files')
@@ -183,16 +199,37 @@ async function store(state, emitter) {
183199

184200
// PANEL
185201
emitter.on('open-panel', () => {
186-
state.isPanelOpen = true
202+
emitter.emit('stop-resizing-panel')
203+
state.panelHeight = state.savedPanelHeight
187204
emitter.emit('render')
205+
setTimeout(() => {
206+
state.cache(XTerm, 'terminal').resizeTerm()
207+
}, 200)
188208
})
189209
emitter.on('close-panel', () => {
190-
state.isPanelOpen = false
210+
emitter.emit('stop-resizing-panel')
211+
state.savedPanelHeight = state.panelHeight
212+
state.panelHeight = 0
191213
emitter.emit('render')
192214
})
193215
emitter.on('clear-terminal', () => {
194216
state.cache(XTerm, 'terminal').term.clear()
195217
})
218+
emitter.on('start-resizing-panel', () => {
219+
log('start-resizing-panel')
220+
window.addEventListener('mousemove', state.resizePanel)
221+
// Stop resizing when mouse leaves window or enters the tabs area
222+
document.body.addEventListener('mouseleave', () => {
223+
emitter.emit('stop-resizing-panel')
224+
}, { once: true })
225+
document.querySelector('#tabs').addEventListener('mouseenter', () => {
226+
emitter.emit('stop-resizing-panel')
227+
}, { once: true })
228+
})
229+
emitter.on('stop-resizing-panel', () => {
230+
log('stop-resizing-panel')
231+
window.removeEventListener('mousemove', state.resizePanel)
232+
})
196233

197234
// SAVING
198235
emitter.on('save', async () => {

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

+3-2
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

+8-6
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)