Skip to content

Commit f77e8c8

Browse files
committed
#207: Improve resizable div behavior, remember adjustment per app session
1 parent 71d63a9 commit f77e8c8

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

src/renderer/components/HelmetProject/HelmetProject.jsx

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ const HelmetProject = ({
3737
const [statusRunFinishTime, setStatusRunFinishTime] = useState(null); //Updated when receiving "finished" message
3838
const [demandConvergenceArray, setDemandConvergenceArray] = useState([]); // Add convergence values to array every iteration
3939

40+
// User-set scenario list height in the Scenarios tab
41+
const [scenarioListHeight, setScenarioListHeight] = useState(null);
42+
4043
// Cost-Benefit Analysis (CBA) controls
4144
const [cbaOptions, setCbaOptions] = useState({});
4245

@@ -409,6 +412,8 @@ const HelmetProject = ({
409412
handleClickStartStop={_handleClickStartStop}
410413
logArgs={logArgs}
411414
duplicateScenario={duplicateScenario}
415+
scenarioListHeight={scenarioListHeight}
416+
setScenarioListHeight={setScenarioListHeight}
412417
/>
413418
</TabPanel>
414419
<TabPanel>

src/renderer/components/HelmetProject/Runtime/Runtime.css

+12-3
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
border-bottom: 1px solid #CCCCCC;
2121
box-sizing: border-box;
2222
padding: 20px;
23-
height: fit-content;
23+
min-height: 190px;
2424
margin-top: 1rem;
25-
min-height: 250px;
2625
position: relative;
2726
}
2827

2928
.Runtime__scenarios_controls_drag_handle {
3029
cursor: row-resize;
3130
height: 50px;
31+
background-color: #FFFFFF;
3232
}
3333

3434
.Runtime__scenarios-heading {
@@ -42,7 +42,9 @@
4242

4343
.Runtime__scenarios {
4444
width: 700px;
45-
overflow-y: auto;
45+
overflow-y: scroll;
46+
scrollbar-width: 20px;
47+
height: calc(100% - 95px);
4648
}
4749

4850
.Runtime__scenario {
@@ -104,6 +106,9 @@
104106
background: #007AC9;
105107
border-color: #007AC9;
106108
color: #ffffff;
109+
position: relative;
110+
bottom: 16px;
111+
z-index: 1;
107112
}
108113
.Runtime__add-new-scenario-btn:hover {
109114
color: #ffffff;
@@ -119,6 +124,10 @@
119124
background-repeat: no-repeat;
120125
}
121126

127+
.no-select {
128+
user-select: none;
129+
}
130+
122131
/* Start-stop */
123132

124133
.Runtime__start-stop-controls {

src/renderer/components/HelmetProject/Runtime/Runtime.jsx

+23-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useState, useEffect } from 'react';
22
import { Tooltip } from 'react-tooltip'
33
import { renderToStaticMarkup } from 'react-dom/server';
44
const _ = require('lodash');
@@ -8,7 +8,7 @@ const Runtime = ({
88
setOpenScenarioID,
99
reloadScenarios,
1010
handleClickScenarioToActive, handleClickNewScenario,
11-
handleClickStartStop, logArgs, duplicateScenario
11+
handleClickStartStop, logArgs, duplicateScenario, scenarioListHeight, setScenarioListHeight
1212
}) => {
1313

1414
const visibleTooltipProperties = [
@@ -121,27 +121,39 @@ const Runtime = ({
121121
return <div/>
122122
}
123123

124-
const resizableDiv = document.getElementById("resizableDiv");
124+
useEffect(() => {
125+
if (scenarioListHeight) {
126+
const resizableDiv = document.getElementById("resizableDiv");
127+
resizableDiv.style.height = scenarioListHeight;
128+
}
129+
});
125130

126131
let mousePosition;
127132
const resize = (e) => {
133+
if (e.buttons === 0) {
134+
// No mouse button is pressed, release event listener
135+
document.body.style = "user-select: auto;"
136+
document.removeEventListener("mousemove", resize, false);
137+
}
128138
const yDimension = mousePosition - e.y;
129139
mousePosition = e.y;
130-
resizableDiv.style.height = (parseInt(getComputedStyle(resizableDiv, '').height) - yDimension) + "px";
140+
const resizableDiv = document.getElementById("resizableDiv");
141+
142+
const newHeight = (parseInt(getComputedStyle(resizableDiv, '').height) - yDimension) + "px";
143+
resizableDiv.style.height = newHeight;
144+
setScenarioListHeight(newHeight);
131145
}
132146

133147
const onMouseDown = (e) => {
134148
if (e.pageY > (e.target.offsetTop + e.target.offsetHeight)) {
135149
mousePosition = e.y;
150+
document.body.style = "user-select: none;"
136151
document.addEventListener("mousemove", resize, false);
137152
}
138153
}
139154

140155
const onMouseUp = () => {
141-
document.removeEventListener("mousemove", resize, false);
142-
}
143-
144-
const onMouseOut = () => {
156+
document.body.style = "user-select: auto;"
145157
document.removeEventListener("mousemove", resize, false);
146158
}
147159

@@ -165,7 +177,7 @@ const Runtime = ({
165177

166178
<div className="Runtime__scenarios-controls" id="resizableDiv">
167179
<div className="Runtime__scenarios-heading">Ladatut skenaariot</div>
168-
<div className="Runtime__scenarios">
180+
<div className="Runtime__scenarios" id="scenarioList">
169181
{/* Create table of all scenarios "<Button-To-Add-As-Runnable> <Button-To-Open-Configuration>" */}
170182
{scenarios.map((s) => {
171183
// Component for the tooltip showing scenario settings
@@ -234,7 +246,7 @@ const Runtime = ({
234246
<div className={"Runtime__scenario-delete"}
235247
onClick={(e) => runningScenarioID ? undefined : deleteScenario(s)}
236248
></div>
237-
<Tooltip id="scenario-tooltip" style={{ borderRadius: "1rem", maxWidth: "40rem", marginLeft: "-50px" }}/>
249+
<Tooltip id="scenario-tooltip" style={{ borderRadius: "1rem", maxWidth: "40rem", marginLeft: "-50px", zIndex: 2 }}/>
238250

239251
&nbsp;
240252
<div className={"Runtime__scenario-clone"}
@@ -256,7 +268,7 @@ const Runtime = ({
256268
</button>
257269
</div>
258270
</div>
259-
<div className="Runtime__scenarios_controls_drag_handle" onMouseDown={onMouseDown} onMouseUp={onMouseUp} onMouseOut={onMouseOut} />
271+
<div className="Runtime__scenarios_controls_drag_handle" onMouseDown={onMouseDown} onMouseUp={onMouseUp} />
260272

261273
<div className="Runtime__start-stop-controls">
262274
<div className="Runtime__heading">Ajettavana</div>

0 commit comments

Comments
 (0)