Skip to content

Commit

Permalink
added SEGMENT_LIST_COLOR_WIDGET option (disabled by default)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisj committed Jan 16, 2025
1 parent fa5cd11 commit f804a1f
Showing 1 changed file with 46 additions and 35 deletions.
81 changes: 46 additions & 35 deletions src/segmentation_display_state/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ import { makeEyeButton } from "#src/widget/eye_button.js";
import { makeFilterButton } from "#src/widget/filter_button.js";
import { makeStarButton } from "#src/widget/star_button.js";

declare const SEGMENT_LIST_COLOR_WIDGET: boolean | undefined;
const SEGMENT_LIST_COLOR_WIDGET_ENABLED =
typeof SEGMENT_LIST_COLOR_WIDGET !== "undefined" &&
SEGMENT_LIST_COLOR_WIDGET === true;
export class Uint64MapEntry {
constructor(
public key: Uint64,
Expand Down Expand Up @@ -352,8 +356,11 @@ const segmentWidgetTemplate = (() => {
filterElement.classList.add("neuroglancer-segment-list-entry-filter");
const filterIndex = template.childElementCount;
template.appendChild(filterElement);
const colorWidgetIndex = template.childElementCount;
template.appendChild(ColorWidget.template());
let colorWidgetIndex = -1;
if (SEGMENT_LIST_COLOR_WIDGET_ENABLED) {
colorWidgetIndex = template.childElementCount;
template.appendChild(ColorWidget.template());
}
return {
template,
copyContainerIndex,
Expand Down Expand Up @@ -553,29 +560,29 @@ function makeRegisterSegmentWidgetEventHandlers(
selectedSegments.set(id, !selectedSegments.has(id));
});

const trackableRGB = new TrackableRGB(vec3.fromValues(0, 0, 0));
trackableRGB.changed.add(() => {
const testU = new Uint64(packColor(trackableRGB.value));
const idString = element.dataset.id!;
const id = tempObjectId;
id.tryParseString(idString);
displayState.segmentStatedColors.value.delete(id);
displayState.segmentStatedColors.value.set(id, testU);
});

// TODO, need to register disposer?
new ColorWidget(
trackableRGB,
undefined,
children[template.colorWidgetIndex] as HTMLInputElement,
() => {
if (SEGMENT_LIST_COLOR_WIDGET_ENABLED) {
const trackableRGB = new TrackableRGB(vec3.fromValues(0, 0, 0));
trackableRGB.changed.add(() => {
const testU = new Uint64(packColor(trackableRGB.value));
const idString = element.dataset.id!;
const id = tempObjectId;
id.tryParseString(idString);
displayState.segmentStatedColors.value.delete(id);
},
false,
);
displayState.segmentStatedColors.value.set(id, testU);
});
new ColorWidget(
trackableRGB,
undefined,
children[template.colorWidgetIndex] as HTMLInputElement,
() => {
const idString = element.dataset.id!;
const id = tempObjectId;
id.tryParseString(idString);
displayState.segmentStatedColors.value.delete(id);
},
false,
);
}
};
}

Expand Down Expand Up @@ -707,13 +714,15 @@ export class SegmentWidgetFactory<Template extends SegmentWidgetTemplate> {
idContainer.children[template.idIndex] as HTMLElement,
color,
);
const isOverridden =
!!this.displayState?.segmentStatedColors.value.has(mapped);
setColorWidgetColor(
children[template.colorWidgetIndex] as HTMLInputElement,
color,
isOverridden,
);
if (SEGMENT_LIST_COLOR_WIDGET_ENABLED) {
const isOverridden =
!!this.displayState?.segmentStatedColors.value.has(mapped);
setColorWidgetColor(
children[template.colorWidgetIndex] as HTMLInputElement,
color,
isOverridden,
);
}
const { unmappedIdIndex } = template;
if (unmappedIdIndex !== -1) {
let unmappedIdString: string | undefined;
Expand All @@ -731,13 +740,15 @@ export class SegmentWidgetFactory<Template extends SegmentWidgetTemplate> {
idContainer.children[unmappedIdIndex] as HTMLElement,
color,
);
const isOverridden =
!!this.displayState?.segmentStatedColors.value.has(mapped);
setColorWidgetColor(
children[template.colorWidgetIndex] as HTMLInputElement,
color,
isOverridden,
);
if (SEGMENT_LIST_COLOR_WIDGET_ENABLED) {
const isOverridden =
!!this.displayState?.segmentStatedColors.value.has(mapped);
setColorWidgetColor(
children[template.colorWidgetIndex] as HTMLInputElement,
color,
isOverridden,
);
}
}
}
}
Expand Down

0 comments on commit f804a1f

Please sign in to comment.