Skip to content

Commit 0f530b5

Browse files
committed
Better UI on landscape / portrait for GCode Viewer
1 parent 779883e commit 0f530b5

File tree

3 files changed

+79
-62
lines changed

3 files changed

+79
-62
lines changed
7 Bytes
Binary file not shown.

extensions/gcodeViewer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gcodeViewer",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "ESP3D-WEBUI extension",
55
"main": "gcodeViewer.html",
66
"scripts": {

extensions/gcodeViewer/src/gcodeViewer.html

Lines changed: 78 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script type="text/javascript">
2-
const gcodeViewer_version = "1.0.0"
2+
const gcodeViewer_version = "1.0.1"
33
// The code use batch processing to avoid memory overflow
44
// The code use async/await to avoid blocking the UI due to some long process
55
// The code is standalone does not need any external library like Three.js or similar to limit the size of the code
@@ -3061,43 +3061,11 @@
30613061
// Resize the canvas
30623062
function resizeCanvas() {
30633063
stopAnimation()
3064-
const canvas = document.getElementById("glCanvas")
3065-
const controls = document.getElementById("controls")
3066-
const container = document.getElementById("extensionUI-container")
3067-
3068-
// Get the window dimensions
3069-
const windowWidth = window.innerWidth
3070-
const windowHeight = window.innerHeight
3071-
3072-
// Define the maximum canvas size (90% of the smallest window dimension)
3073-
const maxCanvasSize = Math.min(windowWidth, windowHeight) - 40 // 5px for left/right margins
3074-
3075-
// Define the minimum size for the controls (adjust as needed)
3076-
const minControlsSize = 200
3077-
3078-
let canvasSize, controlsWidth, controlsHeight
3079-
3080-
if (windowWidth > windowHeight) {
3081-
// Mode landscape
3082-
canvasSize = Math.min(maxCanvasSize, windowHeight - 40)
3083-
controlsHeight = canvasSize
3084-
container.style.flexDirection = "row"
3085-
} else {
3086-
// Mode portrait
3087-
canvasSize = Math.min(maxCanvasSize, windowWidth - 40)
3088-
controlsWidth = canvasSize
3089-
controlsHeight = Math.max(
3090-
minControlsSize,
3091-
windowHeight - canvasSize
3092-
)
3093-
container.style.flexDirection = "column"
3094-
}
3095-
3096-
// Apply the new dimensions
3097-
canvas.width = canvas.height = canvasSize
3098-
console.log("Canvas w x h", canvas.width, canvas.height)
3099-
controls.style.width = `${controlsWidth}px`
3100-
controls.style.height = `${controlsHeight}px`
3064+
const container = document.querySelector('.canvas-container');
3065+
const canvas = document.getElementById('glCanvas');
3066+
console.log(container.clientWidth, "X", container.clientHeight)
3067+
canvas.width = container.clientWidth;
3068+
canvas.height = container.clientHeight
31013069
//draw the scene
31023070
drawScene()
31033071
}
@@ -3451,7 +3419,7 @@ <h2>GCode Viewer Extension v${gcodeViewer_version}</h2>
34513419
let computeGrid = false
34523420
if (invertXY != currentSettings.invertXY) {
34533421
invertXY = currentSettings.invertXY
3454-
computeGrid=true;
3422+
computeGrid = true;
34553423
redraw = true;
34563424
if (gcodePoints.length > 0) {
34573425
computeObject = true;
@@ -3470,7 +3438,7 @@ <h2>GCode Viewer Extension v${gcodeViewer_version}</h2>
34703438
redraw = true
34713439
}
34723440
if (currentSettings.controlRendering != controlRendering) {
3473-
controlRendering = currentSettings.controlRendering ;
3441+
controlRendering = currentSettings.controlRendering;
34743442
redraw = true
34753443
}
34763444
isSmartZoomEnabled = currentSettings.enableSmartZoom
@@ -3730,25 +3698,51 @@ <h2>GCode Viewer Extension v${gcodeViewer_version}</h2>
37303698
display: flex;
37313699
justify-content: center;
37323700
align-items: center;
3701+
overflow: hidden;
37333702
}
37343703

3735-
#extensionUI-container {
3704+
.gcodeviewer_extension_container {
37363705
display: flex;
3737-
flex-direction: column;
3738-
justify-content: center;
3739-
align-items: center;
37403706
width: 100%;
37413707
height: 100%;
3742-
37433708
box-sizing: border-box;
37443709
}
37453710

3711+
.gcodeviewer_rendering {
3712+
flex: 1;
3713+
display: flex;
3714+
flex-direction: column;
3715+
overflow: hidden;
3716+
}
3717+
37463718
#glCanvas {
3747-
margin: 0px;
3748-
padding: 0;
3719+
position: absolute;
3720+
top: 0;
3721+
left: 0;
3722+
width: 100%;
3723+
height: 100%;
37493724
border: 1px solid rgb(215, 215, 215);
3750-
max-width: 100%;
3751-
max-height: calc(100% - 50px);
3725+
}
3726+
3727+
.gcodeviewer-top-bar {
3728+
width: 100%;
3729+
padding: 10px;
3730+
display: flex;
3731+
justify-content: space-between;
3732+
}
3733+
3734+
.gcodeviewer_controls {
3735+
width: 250px;
3736+
padding: 10px;
3737+
display: flex;
3738+
flex-direction: column;
3739+
overflow-y: auto;
3740+
}
3741+
3742+
.canvas-container {
3743+
flex: 1;
3744+
position: relative;
3745+
overflow: hidden;
37523746
}
37533747

37543748
#progressBar {
@@ -3758,12 +3752,9 @@ <h2>GCode Viewer Extension v${gcodeViewer_version}</h2>
37583752
text-align: center;
37593753
line-height: 30px;
37603754
color: white;
3761-
margin: 5px;
3755+
margin: 5px 0;
37623756
}
37633757

3764-
#controls {
3765-
min-height: 2rem;
3766-
}
37673758

37683759
.loader-container {
37693760
position: absolute;
@@ -3777,12 +3768,36 @@ <h2>GCode Viewer Extension v${gcodeViewer_version}</h2>
37773768
background-color: rgba(255, 255, 255, 0.8);
37783769
z-index: 1000;
37793770
}
3771+
3772+
@media (max-aspect-ratio: 1/1) {
3773+
.gcodeviewer_extension_container {
3774+
flex-direction: column;
3775+
}
3776+
3777+
.gcodeviewer_controls {
3778+
width: 100%;
3779+
height: auto;
3780+
max-height: 30%;
3781+
}
3782+
}
3783+
3784+
/* Pour les écrans où la largeur est plus grande que la hauteur */
3785+
@media (min-aspect-ratio: 1/1) {
3786+
.gcodeviewer_extension_container {
3787+
flex-direction: row;
3788+
}
3789+
3790+
.gcodeviewer_controls {
3791+
height: 100%;
3792+
max-width: 30%;
3793+
}
3794+
}
37803795
</style>
3781-
<div id="extensionUI-container" lass="flex-row-between">
3782-
<div id="loaderContainer" class="loader-container">
3783-
<div class="loading loading-lg"></div>
3784-
</div>
3785-
<div class="flex-cols">
3796+
<div id="extensionUI-container" class="gcodeviewer_extension_container">
3797+
<div class="gcodeviewer_rendering">
3798+
<div id="loaderContainer" class="loader-container">
3799+
<div class="loading loading-lg"></div>
3800+
</div>
37863801
<div class="flex-row-between" style="width: 100%; padding-right: 10px">
37873802
<div class="dropdown">
37883803
<span class="dropdown-toggle btn m-1" tabindex="0" id="drop-btn" style="z-index: 10000"></span>
@@ -3825,9 +3840,11 @@ <h2>GCode Viewer Extension v${gcodeViewer_version}</h2>
38253840
</div>
38263841
<div class="text-primary mt-2" id="fileName"></div>
38273842
</div>
3828-
<canvas id="glCanvas" width="400" height="400"></canvas>
3843+
<div class="canvas-container">
3844+
<canvas id="glCanvas"></canvas>
3845+
</div>
38293846
</div>
3830-
<div id="controls" class="flex-cols" style="overflow-y: auto">
3847+
<div id="controls" class="gcodeviewer_controls">
38313848
<div style="align-self: stretch">
38323849
<div id="progressBar">0%</div>
38333850
</div>
@@ -3855,4 +3872,4 @@ <h2>GCode Viewer Extension v${gcodeViewer_version}</h2>
38553872

38563873
<input type="file" id="fileInput" accept=".gcode" style="display: none" />
38573874
</div>
3858-
</div>
3875+
</div>

0 commit comments

Comments
 (0)