Skip to content

Commit

Permalink
Extract image controls shift buttons to a component
Browse files Browse the repository at this point in the history
  • Loading branch information
urubens committed Jun 29, 2020
1 parent c8680c8 commit 5930aa9
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 125 deletions.
169 changes: 44 additions & 125 deletions src/components/viewer/ImageControls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,13 @@
<!-- ----- CHANNELS ----- -->
<div class="image-dimension" v-if="hasChannels">
<strong class="image-dimension-name">C</strong>
<div class="buttons has-addons">
<button
class="button is-small item"
:disabled="!canShiftBackward('channel')"
@click="shift('channel', -Math.min(step, currentSlice.channel))"
>
<i class="fas fa-fast-backward"></i>
<div class="step-counter">-{{step}}</div>
</button>
<button
class="button is-small item"
:disabled="!canShiftBackward('channel')"
@click="shift('channel', -1)"
>
<i class="fas fa-step-backward"></i>
</button>
</div>
<image-controls-shift-buttons
:index="index"
:forward="false"
:current="currentSlice.channel"
:size="image.channels"
@shift="shift('channel', $event)"
/>

<cytomine-slider
v-model="currentChannel"
Expand All @@ -33,96 +23,54 @@
</template>
</cytomine-slider>

<div class="buttons has-addons">
<button
class="button is-small item"
:disabled="!canShiftForward('channel')"
@click="shift('channel', 1)"
>
<i class="fas fa-step-forward"></i>
</button>
<button
class="button is-small item"
:disabled="!canShiftForward('channel')"
@click="shift('channel', Math.min(step, image.channels - currentSlice.channel - 1))"
>
<i class="fas fa-fast-forward"></i>
<div class="step-counter">+{{step}}</div>
</button>
</div>
<image-controls-shift-buttons
:index="index"
:forward="true"
:current="currentSlice.channel"
:size="image.channels"
@shift="shift('channel', $event)"
/>
</div>


<!-- ----- DEPTH ----- -->
<div class="image-dimension" v-if="hasDepth">
<strong class="image-dimension-name">Z</strong>
<div class="buttons has-addons">
<button
class="button is-small"
:disabled="!canShiftBackward('zStack')"
@click="shift('zStack', -Math.min(step, currentSlice.zStack))"
>
<i class="fas fa-fast-backward"></i>
<div class="step-counter">-{{step}}</div>
</button>

<button
class="button is-small"
:disabled="!canShiftBackward('zStack')"
@click="shift('zStack', -1)"
>
<i class="fas fa-step-backward"></i>
</button>
</div>
<image-controls-shift-buttons
:index="index"
:forward="false"
:current="currentSlice.zStack"
:size="image.depth"
@shift="shift('zStack', $event)"
/>

<cytomine-slider
v-model="currentZStack"
:max="image.depth - 1"
:integer-only="true"
class="image-dimension-slider" />

<div class="buttons has-addons">
<button
class="button is-small"
:disabled="!canShiftForward('zStack')"
@click="shift('zStack', 1)"
>
<i class="fas fa-step-forward"></i>
</button>
<button
class="button is-small"
:disabled="!canShiftForward('zStack')"
@click="shift('zStack', Math.min(step, image.depth - currentSlice.zStack - 1))"
>
<i class="fas fa-fast-forward"></i>
<div class="step-counter">+{{step}}</div>
</button>
</div>
<image-controls-shift-buttons
:index="index"
:forward="true"
:current="currentSlice.zStack"
:size="image.depth"
@shift="shift('zStack', $event)"
/>
</div>



<!-- ----- DURATION ----- -->
<div class="image-dimension" v-if="hasDuration">
<strong class="image-dimension-name">T</strong>

<div class="buttons has-addons">
<button
class="button is-small"
:disabled="!canShiftBackward('time')"
@click="shift('time', -Math.min(step, currentSlice.time))"
>
<i class="fas fa-fast-backward"></i>
<div class="step-counter">-{{step}}</div>
</button>
<button
class="button is-small"
:disabled="!canShiftBackward('time')"
@click="shift('time', -1)"
>
<i class="fas fa-step-backward"></i>
</button>
</div>
<image-controls-shift-buttons
:index="index"
:forward="false"
:current="currentSlice.time"
:size="image.duration"
@shift="shift('time', $event)"
/>

<!-- <div class="buttons has-addons">-->
<!-- <button class="button is-small">-->
Expand All @@ -141,36 +89,27 @@
</template>
</cytomine-slider>

<div class="buttons has-addons">
<button
class="button is-small"
:disabled="!canShiftForward('time')"
@click="shift('time', 1)"
>
<i class="fas fa-step-forward"></i>
</button>
<button
class="button is-small"
:disabled="!canShiftForward('time')"
@click="shift('time', Math.min(step, image.duration - currentSlice.time - 1))"
>
<i class="fas fa-fast-forward"></i>
<div class="step-counter">+{{step}}</div>
</button>
</div>
<image-controls-shift-buttons
:index="index"
:forward="true"
:current="currentSlice.time"
:size="image.duration"
@shift="shift('time', $event)"
/>
</div>
</div>
</template>

<script>
import CytomineSlider from '@/components/form/CytomineSlider';
import ImageControlsShiftButtons from '@/components/viewer/ImageControlsShiftButtons';
import {formatMinutesSeconds} from '@/utils/slice-utils.js';
import {slicePositionToRank} from '@/utils/slice-utils';
export default {
name: 'image-controls',
components: {CytomineSlider},
components: {ImageControlsShiftButtons, CytomineSlider},
data() {
return {
step: 2, // TODO: add into configuration
Expand Down Expand Up @@ -404,30 +343,10 @@ export default {
width: 1rem;
}
.buttons {
float:left;
margin: 1px;
margin-bottom: 0 !important;
.button {
margin-bottom: 0;
}
}
.image-dimension-slider {
flex-grow: 3;
}
.step-counter {
position: absolute;
top: 0.25em;
right: 0.25em;
font-size: 0.7em;
font-weight: 600;
text-align:right;
line-height: 0.9em;
}
</style>

<style>
Expand Down
101 changes: 101 additions & 0 deletions src/components/viewer/ImageControlsShiftButtons.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<template>
<div class="buttons has-addons">
<template v-if="forward">
<button
class="button is-small item"
:disabled="!canShift"
@click="shift(1)"
>
<i class="fas fa-step-forward"></i>
</button>
<button
class="button is-small item"
:disabled="!canShift"
@click="shift(Math.min(step, size - current - 1))"
>
<i class="fas fa-fast-forward"></i>
<div class="step-counter">+{{step}}</div>
</button>
</template>
<template v-else>
<button
class="button is-small item"
:disabled="!canShift"
@click="shift(-Math.min(step, current))"
>
<i class="fas fa-fast-backward"></i>
<div class="step-counter">-{{step}}</div>
</button>
<button
class="button is-small item"
:disabled="!canShift"
@click="shift(-1)"
>
<i class="fas fa-step-backward"></i>
</button>
</template>

</div>
</template>

<script>
export default {
name: 'ImageControlsShiftButtons',
props: {
index: String,
forward: Boolean,
current: Number,
size: Number,
},
computed: {
imageModule() {
return this.$store.getters['currentProject/imageModule'](this.index);
},
viewerWrapper() {
return this.$store.getters['currentProject/currentViewer'];
},
imageWrapper() {
return this.viewerWrapper.images[this.index];
},
step: {
get() {
return this.imageWrapper.controls.step;
},
set(value) {
this.$store.dispatch(this.imageModule + 'setStep', value);
}
},
canShift() {
return (this.forward) ? (this.current < this.size - 1) : (this.current >= 1);
}
},
methods: {
shift(value) {
this.$emit('shift', value);
}
}
};
</script>

<style lang="scss" scoped>
.buttons {
float:left;
margin: 1px;
margin-bottom: 0 !important;
.button {
margin-bottom: 0;
}
}
.step-counter {
position: absolute;
top: 0.25em;
right: 0.25em;
font-size: 0.7em;
font-weight: 600;
text-align:right;
line-height: 0.9em;
}
</style>
2 changes: 2 additions & 0 deletions src/store/modules/project_modules/viewer_modules/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import view from './image_modules/view';
import review from './image_modules/review';
import tracks from './image_modules/tracks';
import annotationsList from './image_modules/annotations-list';
import controls from './image_modules/controls';

import Vue from 'vue';

Expand Down Expand Up @@ -330,6 +331,7 @@ export default {
review,
tracks,
annotationsList,
controls
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2009-2019. Authors: see NOTICE file.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export default {
state() {
return {
step: 2
};
},

mutations: {
setStep(state, value) {
state.step = value;
}
},
};

0 comments on commit 5930aa9

Please sign in to comment.