Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix resizing of columns #256

Merged
merged 5 commits into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions aas-gui/Frontend/aas-web-gui/src/components/MainWindow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,23 @@ export default defineComponent({
curCol = e.target.parentElement; // the current element that will be scaled
nxtCol = curCol.nextElementSibling; // selects the divider
if(nxtCol) nxtCol = nxtCol.nextElementSibling; // the next element that will be scaled too
pageX = e.pageX; // the current x position of the mouse
pageX = parseInt(e.pageX); // the current x position of the mouse
curColWidth = parseInt(curCol.offsetWidth); // the current width of the current element
if(nxtCol) nxtColWidth = parseInt(nxtCol.offsetWidth); // the current width of the next element
});
// Eventlistener to scale the current and next Window when the mouse is moved
document.addEventListener('mousemove', function(e: any) {
if(!curCol) return; // if no element is selected return
let screenWidth = document.getElementsByTagName('html')[0].clientWidth; // the width of the screen (Window) excluding the scrollbar
let navigationDrawer: any = document.getElementsByClassName('leftMenu')[0]; // the width of the navigation drawer
let isDrawerOpen: boolean = navigationDrawer.style.transform == 'translateX(0%)'; // checks if the navigation drawer is open
screenWidth = screenWidth - (isDrawerOpen ? 336 : 0); // if the navigation drawer is open subtract the width of the navigation drawer from the screen width
let diffX = parseInt(e.pageX) - pageX; // amount the header was dragged (minus - left, plus - right)
// TODO: prevent negative width
if(curCol) curCol.style.width = (100 - ((screenWidth - curColWidth - diffX) / screenWidth) * 100) + '%'; // scale the current Column (Window)
if(nxtCol) nxtCol.style.width = (100 - ((screenWidth - nxtColWidth + diffX) / screenWidth) * 100) + '%'; // scale the next Column (Window) if it exists
if(!curCol) return; // if no element is selected return
let screenWidth = document.documentElement.clientWidth; // the width of the screen (Window) excluding the scrollbar
let navigationDrawer: any = document.getElementsByClassName('leftMenu')[0]; // the width of the navigation drawer
let isDrawerOpen: boolean = navigationDrawer.style.transform == 'translateX(0px)'; // checks if the navigation drawer is open
screenWidth = screenWidth - (isDrawerOpen ? navigationDrawer.clientWidth : 0); // if the navigation drawer is open subtract the width of the navigation drawer from the screen width
let diffX = parseInt(e.pageX) - pageX; // amount the header was dragged (minus - left, plus - right)
let minimalColWith = 200;
if ((curColWidth + diffX) >= minimalColWith && (nxtColWidth - diffX) >= minimalColWith) {
if(curCol) curCol.style.width = (100 - ((screenWidth - (curColWidth + diffX)) / screenWidth) * 100) + '%'; // scale the current Column (Window)
if(nxtCol) nxtCol.style.width = (100 - ((screenWidth - (nxtColWidth - diffX)) / screenWidth) * 100) + '%'; // scale the next Column (Window) if it exists
}
});
// Eventlistener to clear the local Variables mouse up
document.addEventListener('mouseup', function() {
Expand Down