Skip to content

Commit

Permalink
feat(SegmentList): add opacity slider for selected segment
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Oct 17, 2024
1 parent d4b0cc1 commit 207067c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/SegmentGroupOpacity.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const setOpacity = (opacity: number) => {

<template>
<v-slider
class="pa-4"
class="ma-4"
label="Segment Group Opacity"
min="0"
max="1"
Expand Down
45 changes: 44 additions & 1 deletion src/components/SegmentList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { hexaToRGBA, rgbaToHexa } from '@/src/utils/color';
import { reactive, ref, toRefs, computed, watch } from 'vue';
import { SegmentMask } from '@/src/types/segment';
import { usePaintToolStore } from '@/src/store/tools/paint';
import { RGBAColor } from '@kitware/vtk.js/types';
const props = defineProps({
groupId: {
Expand Down Expand Up @@ -57,6 +58,36 @@ watch(
{ immediate: true }
);
// --- segment opacity --- //
const selectedSegmentMask = computed(() => {
if (!selectedSegment.value) return null;
return segmentGroupStore.getSegment(groupId.value, selectedSegment.value);
});
const segmentOpacity = computed(() => {
if (!selectedSegmentMask.value) return 1;
return selectedSegmentMask.value.color[3] / 255;
});
const setSegmentOpacity = (opacity: number) => {
if (!selectedSegmentMask.value) {
return;
}
const color = selectedSegmentMask.value.color;
segmentGroupStore.updateSegment(
groupId.value,
selectedSegmentMask.value.value,
{
color: [
...(color.slice(0, 3) as [number, number, number]),
Math.round(opacity * 255),
],
}
);
};
// --- editing state --- //
const editingSegmentValue = ref<Maybe<number>>(null);
Expand Down Expand Up @@ -106,6 +137,18 @@ function deleteEditingSegment() {
</script>

<template>
<v-slider
class="ma-4"
label="Segment Opacity"
min="0"
max="1"
step="0.01"
density="compact"
hide-details
thumb-label
:model-value="segmentOpacity"
@update:model-value="setSegmentOpacity($event)"
/>
<editable-chip-list
v-model="selectedSegment"
:items="segments"
Expand All @@ -119,7 +162,7 @@ function deleteEditingSegment() {
<div class="dot-container mr-3">
<div
class="color-dot"
:style="{ background: rgbaToHexa(item.color) }"
:style="{ background: rgbaToHexa([...item.color.slice(0,3), 255] as RGBAColor) }"
/>
</div>
</template>
Expand Down

0 comments on commit 207067c

Please sign in to comment.