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

feat(Slice): Use keyboard to change slices of the active view #679

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions src/components/LayoutGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
:id="item.id"
:type="item.viewType"
v-bind="item.props"
@focus="onFocusView(item.id!, item.viewType!)"
/>
</div>
</div>
Expand All @@ -28,6 +29,13 @@ import { useViewStore } from '../store/views';

export default defineComponent({
name: 'LayoutGrid',
methods: {
onFocusView(id: string, type: string) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍️ Good

Also, when I scroll with mouse wheel on a view, then press the arrow keys, its not always the same view that gets its slice changed. So maybe setActiveView on scroll events too?

if (type === '2D') {
useViewStore().setActiveViewID(id);
}
},
},
props: {
layout: {
type: Object as PropType<Layout>,
Expand Down
22 changes: 22 additions & 0 deletions src/composables/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import { Tools } from '../store/tools/types';
import { useRectangleStore } from '../store/tools/rectangles';
import { useRulerStore } from '../store/tools/rulers';
import { usePolygonStore } from '../store/tools/polygons';
import { useViewStore } from '../store/views';
import { Action } from '../constants';
import { useKeyboardShortcutsStore } from '../store/keyboard-shortcuts';
import { useCurrentImage } from './useCurrentImage';
import { useSliceConfig } from './useSliceConfig';

const applyLabelOffset = (offset: number) => () => {
const toolToStore = {
Expand Down Expand Up @@ -36,6 +39,22 @@ const showKeyboardShortcuts = () => {
keyboardStore.settingsOpen = !keyboardStore.settingsOpen;
};

const nextSlice = () => () => {
const { currentImageID } = useCurrentImage();
const { activeViewID } = useViewStore();

const { slice: currentSlice } = useSliceConfig(activeViewID, currentImageID);
currentSlice.value += 1;
};

const previousSlice = () => () => {
const { currentImageID } = useCurrentImage();
const { activeViewID } = useViewStore();

const { slice: currentSlice } = useSliceConfig(activeViewID, currentImageID);
currentSlice.value -= 1;
};
Comment on lines +42 to +56
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To remove duplicate code, could define something like offsetSlice(offset: number) then

const nextSlice = () => offsetSlice(1)
const previousSlice = () => offsetSlice(-1)


export const ACTION_TO_FUNC = {
windowLevel: setTool(Tools.WindowLevel),
pan: setTool(Tools.Pan),
Expand All @@ -48,6 +67,9 @@ export const ACTION_TO_FUNC = {
polygon: setTool(Tools.Polygon),
select: setTool(Tools.Select),

nextSlice: nextSlice(),
previousSlice: previousSlice(),

decrementLabel: applyLabelOffset(-1),
incrementLabel: applyLabelOffset(1),

Expand Down
3 changes: 3 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ export const ACTION_TO_KEY = {
mergeNewPolygon: 'Shift',
select: 's',

nextSlice: 'arrowdown',
previousSlice: 'arrowup',

decrementLabel: 'q',
incrementLabel: 'w',

Expand Down
7 changes: 7 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ export const ACTIONS = {
readable: 'Activate Select tool',
},

nextSlice: {
readable: 'Next Slice',
},
previousSlice: {
readable: 'Previous Slice',
},

decrementLabel: {
readable: 'Activate previous Label',
},
Expand Down
5 changes: 5 additions & 0 deletions src/store/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
interface State {
layout: Layout;
viewSpecs: Record<string, ViewSpec>;
activeViewID: string;
}

export const useViewStore = defineStore('view', {
Expand All @@ -21,13 +22,17 @@ export const useViewStore = defineStore('view', {
items: [],
},
viewSpecs: structuredClone(InitViewSpecs),
activeViewID: '',
}),
getters: {
viewIDs(state) {
return Object.keys(state.viewSpecs);
},
},
actions: {
setActiveViewID(id: string) {
this.activeViewID = id;
},
addView(id: string) {
if (!(id in this.viewSpecs)) {
this.viewSpecs[id] = structuredClone(DefaultViewSpec);
Expand Down