Skip to content

Commit 6a6e824

Browse files
authored
Merge pull request #6 from arduino/bugfix/resize-panel
Resizeable panel
2 parents 0445cfa + bdf3e6c commit 6a6e824

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

ui/arduino/components/panel.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
function Panel(state, emit) {
2-
let openClass = state.isTerminalOpen || state.isFilesOpen ? 'open' : ''
2+
let open = state.isTerminalOpen || state.isFilesOpen
3+
let openClass = open ? 'open' : ''
4+
let panelHeight = open ? `height: ${state.panelHeight}` : ''
35
return html`
4-
<div id="panel" class=${openClass}>
6+
<div id="panel" class=${openClass} style="${panelHeight}">
7+
${open ? html`<div id="handle" onmousedown=${() => emit('start-resizing-panel')}></div>` : null}
58
${state.isTerminalOpen ? PanelTerminal(state, emit) : null}
69
${state.isFilesOpen ? PanelFiles(state, emit) : null}
710
</div>

ui/arduino/components/panel_terminal.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ class XTerm extends Component {
2626
}
2727

2828
resizeTerm() {
29+
let handleSize = 2 * 0.0225 * window.innerHeight
2930
const parentStyle = window.getComputedStyle(document.querySelector('#panel'))
3031
const parentWidth = parseInt(parentStyle.getPropertyValue('width'))
3132
const parentHeight = parseInt(parentStyle.getPropertyValue('height'))
3233
const cols = Math.floor(parentWidth / this.term._core._renderService.dimensions.actualCellWidth)
33-
const rows = Math.floor(parentHeight / this.term._core._renderService.dimensions.actualCellHeight)
34+
const rows = Math.floor((parentHeight-handleSize) / this.term._core._renderService.dimensions.actualCellHeight)
3435
this.term.resize(cols, rows)
3536
}
3637
}

ui/arduino/store.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function store(state, emitter) {
2323
state.messageTimeout = 0
2424

2525
state.isTerminalBound = false // XXX
26+
state.panelHeight = null
2627

2728
// SERIAL CONNECTION
2829
emitter.on('load-ports', async () => {
@@ -204,6 +205,7 @@ function store(state, emitter) {
204205
// PANEL MANAGEMENT
205206
emitter.on('show-terminal', () => {
206207
log('show-terminal')
208+
if (state.panelHeight === null) state.panelHeight = '50%'
207209
state.isTerminalOpen = !state.isTerminalOpen
208210
state.isFilesOpen = false
209211
emitter.emit('render')
@@ -220,6 +222,19 @@ function store(state, emitter) {
220222
state.isFilesOpen = false
221223
emitter.emit('render')
222224
})
225+
emitter.on('start-resizing-panel', () => {
226+
console.log('start-resizing-panel')
227+
function handleMouseMove(e) {
228+
// console.log('mouse move', e)
229+
let height = window.innerHeight - e.clientY
230+
state.panelHeight = `${height}px`
231+
emitter.emit('render')
232+
}
233+
window.addEventListener('mousemove', handleMouseMove)
234+
window.addEventListener('mouseup', (e) => {
235+
window.removeEventListener('mousemove', handleMouseMove)
236+
}, { once: true })
237+
})
223238

224239
// NAMING/RENAMING FILE
225240
emitter.on('save-filename', async (filename) => {

ui/arduino/theme.css

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,17 @@ img {
174174
overflow: hidden;
175175
}
176176
#panel.open {
177-
height: 100%;
177+
position: fixed;
178+
bottom: 0;
179+
left: 0;
180+
right: 0;
181+
height: 50%;
182+
z-index: 99;
183+
}
184+
#panel #handle {
185+
padding: 1rem;
186+
background: var(--teal);
187+
cursor: n-resize;
178188
}
179189

180190
#terminal {
@@ -186,11 +196,12 @@ img {
186196

187197
#files {
188198
width: 100%;
189-
height: 100%;
190-
background: var(--teal);
199+
height: calc(100% - 2rem);
200+
background: var(--white);
191201
display: flex;
192202
flex-direction: row;
193203
padding: 1rem;
204+
overflow: hidden;
194205
}
195206

196207
#files .file-list {
@@ -203,13 +214,18 @@ img {
203214

204215
#files .file-list .path {
205216
height: 2.5rem;
206-
color: var(--white);
217+
color: var(--black);
207218
overflow: hidden;
208219
white-space: nowrap;
209220
text-overflow: ellipsis;
210221
}
211222

223+
#files .toolbar-label {
224+
color: var(--black);
225+
}
226+
212227
#files .file-list ul {
228+
border: solid 0.1rem var(--teal);
213229
width: 100%;
214230
height: 100%;
215231
padding: 0.5rem;

0 commit comments

Comments
 (0)