Skip to content

Commit 6c6329a

Browse files
authored
Merge pull request #754 from PaulHax/maximize
Maximize view on double click
2 parents ed3840b + bf5bb92 commit 6c6329a

3 files changed

Lines changed: 60 additions & 1 deletion

File tree

src/components/LayoutGrid.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
>
77
<div v-for="(item, i) in items" :key="i" class="d-flex flex-equal">
88
<layout-grid v-if="item.type === 'layout'" :layout="(item as Layout)" />
9-
<div v-else class="layout-item">
9+
<div v-else class="layout-item" @dblclick="maximize(item.id!)">
1010
<component
1111
:is="item.component"
1212
:key="item.id"
@@ -26,6 +26,8 @@ import { storeToRefs } from 'pinia';
2626
import { ViewTypeToComponent } from '@/src/core/viewTypes';
2727
import { Layout, LayoutDirection } from '../types/layout';
2828
import { useViewStore } from '../store/views';
29+
import { useToolStore } from '../store/tools';
30+
import { ALLOW_MAXIMIZE_TOOLS } from '../config';
2931
3032
export default defineComponent({
3133
name: 'LayoutGrid',
@@ -35,6 +37,12 @@ export default defineComponent({
3537
useViewStore().setActiveViewID(id);
3638
}
3739
},
40+
maximize(viewId: string) {
41+
const currentTool = useToolStore().currentTool;
42+
if (ALLOW_MAXIMIZE_TOOLS.includes(currentTool)) {
43+
useViewStore().toggleMaximizeView(viewId);
44+
}
45+
},
3846
},
3947
props: {
4048
layout: {

src/config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Layout, LayoutDirection } from './types/layout';
88
import { ViewSpec } from './types/views';
99
import { SampleDataset } from './types';
1010
import { Action } from './constants';
11+
import { Tools } from './store/tools/types';
1112

1213
/**
1314
* These are the initial view IDs.
@@ -289,6 +290,14 @@ export const ACTION_TO_KEY = {
289290
showKeyboardShortcuts: '?',
290291
} satisfies Record<Action, string>;
291292

293+
export const ALLOW_MAXIMIZE_TOOLS = [
294+
Tools.WindowLevel,
295+
Tools.Pan,
296+
Tools.Zoom,
297+
Tools.Select,
298+
Tools.Crosshairs,
299+
];
300+
292301
export const DEFAULT_SEGMENT_MASKS: SegmentMask[] = [
293302
{
294303
value: 1,

src/store/views.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,22 @@ import {
99
View,
1010
} from '../io/state-file/schema';
1111

12+
function cloneLayout(layout: Layout): Layout {
13+
return {
14+
direction: layout.direction,
15+
items: layout.items.map((item) =>
16+
typeof item === 'string' ? item : cloneLayout(item)
17+
),
18+
...(layout.name && { name: layout.name }),
19+
};
20+
}
21+
1222
interface State {
1323
layout: Layout;
1424
viewSpecs: Record<string, ViewSpec>;
1525
activeViewID: string;
26+
maximizedViewID: string | null;
27+
originalLayout: Layout | null;
1628
}
1729

1830
export const useViewStore = defineStore('view', {
@@ -23,6 +35,8 @@ export const useViewStore = defineStore('view', {
2335
},
2436
viewSpecs: structuredClone(InitViewSpecs),
2537
activeViewID: '',
38+
maximizedViewID: null,
39+
originalLayout: null,
2640
}),
2741
getters: {
2842
viewIDs(state) {
@@ -44,6 +58,7 @@ export const useViewStore = defineStore('view', {
4458
}
4559
},
4660
setLayout(layout: Layout) {
61+
this.restoreLayout();
4762
this.layout = layout;
4863

4964
const layoutsToProcess = [layout];
@@ -59,6 +74,33 @@ export const useViewStore = defineStore('view', {
5974
});
6075
}
6176
},
77+
maximizeView(viewID: string) {
78+
if (this.maximizedViewID) {
79+
this.restoreLayout();
80+
}
81+
82+
this.originalLayout = cloneLayout(this.layout);
83+
this.maximizedViewID = viewID;
84+
85+
this.layout = {
86+
direction: LayoutDirection.H,
87+
items: [viewID],
88+
};
89+
},
90+
restoreLayout() {
91+
if (this.originalLayout) {
92+
this.layout = this.originalLayout;
93+
this.originalLayout = null;
94+
this.maximizedViewID = null;
95+
}
96+
},
97+
toggleMaximizeView(viewID: string) {
98+
if (this.maximizedViewID === viewID) {
99+
this.restoreLayout();
100+
} else {
101+
this.maximizeView(viewID);
102+
}
103+
},
62104
serialize(stateFile: StateFile) {
63105
const viewConfigStore = useViewConfigStore();
64106
const { manifest } = stateFile;

0 commit comments

Comments
 (0)