Skip to content

Commit ebda90c

Browse files
committed
Use percentages for layout resizing
1 parent 860dcd0 commit ebda90c

2 files changed

Lines changed: 17 additions & 16 deletions

File tree

src/components/layouts/DefaultLayout.vue

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,43 @@ import { watchMouseDragMove } from "../../util";
66
// Can be done once we have more than a single layout
77
88
const state = reactive({
9-
firstPaneHeight: Math.round(window.innerHeight / 2),
10-
secondPaneWidth: Math.round(window.innerWidth / 2),
9+
firstPaneHeight: 50,
10+
secondPaneWidth: 50,
1111
});
1212
13+
const clampPercent = (num) => Math.max(0, Math.min(100, num));
14+
1315
const handleVResize = (event) => {
1416
const originalHeight = state.firstPaneHeight;
15-
const handleMouseDragMove = ({ deltaY }) =>
16-
(state.firstPaneHeight = Math.max(0, originalHeight + deltaY));
17+
const containerEl = event.target.parentNode;
18+
const handleMouseDragMove = ({ deltaY }) => {
19+
const percentDiff = (deltaY * 100) / containerEl.clientHeight;
20+
state.firstPaneHeight = clampPercent(originalHeight + percentDiff);
21+
};
1722
watchMouseDragMove(event, handleMouseDragMove);
1823
};
1924
2025
const handleHResize = (event) => {
2126
const originalWidth = state.secondPaneWidth;
22-
const handleMouseDragMove = ({ deltaX }) =>
23-
(state.secondPaneWidth = Math.max(0, originalWidth + deltaX));
27+
const containerEl = event.target.parentNode.parentNode;
28+
const handleMouseDragMove = ({ deltaX }) => {
29+
const percentDiff = (deltaX * 100) / containerEl.clientWidth;
30+
state.secondPaneWidth = clampPercent(originalWidth + percentDiff);
31+
};
2432
watchMouseDragMove(event, handleMouseDragMove);
2533
};
2634
</script>
2735

2836
<template>
2937
<div class="fl layout-container">
30-
<div class="fl top" :style="{ height: state.firstPaneHeight + 'px' }">
38+
<div class="fl top" :style="{ height: state.firstPaneHeight + '%' }">
3139
<slot name="slot1"></slot>
3240
</div>
3341
<div class="v-resize" @mousedown="handleVResize"></div>
3442
<div class="fl bottom">
3543
<div
3644
class="fl first quarter needs-border-bottom"
37-
:style="{ width: state.secondPaneWidth + 'px' }"
45+
:style="{ width: state.secondPaneWidth + '%' }"
3846
>
3947
<slot name="slot2"></slot>
4048
</div>

src/components/panes/PacketList.vue

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
<script setup>
2-
import {
3-
computed,
4-
reactive,
5-
ref,
6-
shallowRef,
7-
useTemplateRef,
8-
watch,
9-
} from "vue";
2+
import { computed, ref, shallowRef, useTemplateRef, watch } from "vue";
103
import { useResizeObserver, useScroll } from "@vueuse/core";
114
import { manager } from "../../globals";
125
import Minimap from "./PacketList/Minimap.vue";

0 commit comments

Comments
 (0)