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

CC-122/126 Add option to hide/show code block #47

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 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
91 changes: 56 additions & 35 deletions src/layer/annotation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import "#src/layer/annotation/style.css";
import svgCode from "ikonate/icons/code-alt.svg?raw";

import type { AnnotationDisplayState } from "#src/annotation/annotation_layer_state.js";
import { AnnotationLayerState } from "#src/annotation/annotation_layer_state.js";
Expand Down Expand Up @@ -45,7 +46,10 @@ import { RenderLayerRole } from "#src/renderlayer.js";
import type { SegmentationDisplayState } from "#src/segmentation_display_state/frontend.js";
import type { TrackableBoolean } from "#src/trackable_boolean.js";
import { TrackableBooleanCheckbox } from "#src/trackable_boolean.js";
import { makeCachedLazyDerivedWatchableValue } from "#src/trackable_value.js";
import {
makeCachedLazyDerivedWatchableValue,
observeWatchable,
} from "#src/trackable_value.js";
import type {
AnnotationLayerView,
MergedAnnotationStates,
Expand All @@ -67,6 +71,7 @@ import {
verifyStringArray,
} from "#src/util/json.js";
import { NullarySignal } from "#src/util/signal.js";
import { CheckboxIcon } from "#src/widget/checkbox_icon.js";
import { DependentViewWidget } from "#src/widget/dependent_view_widget.js";
import { makeHelpButton } from "#src/widget/help_button.js";
import { LayerReferenceWidget } from "#src/widget/layer_reference.js";
Expand Down Expand Up @@ -740,49 +745,65 @@ class RenderingOptionsTab extends Tab {
super();
const { element } = this;
element.classList.add("neuroglancer-annotation-rendering-tab");
element.appendChild(
this.registerDisposer(
new DependentViewWidget(
layer.annotationDisplayState.annotationProperties,
(properties, parent) => {
if (properties === undefined || properties.length === 0) return;
const propertyList = document.createElement("div");
parent.appendChild(propertyList);
propertyList.classList.add(
"neuroglancer-annotation-shader-property-list",
const shaderProperties = this.registerDisposer(
new DependentViewWidget(
layer.annotationDisplayState.annotationProperties,
(properties, parent) => {
if (properties === undefined || properties.length === 0) return;
const propertyList = document.createElement("div");
parent.appendChild(propertyList);
propertyList.classList.add(
"neuroglancer-annotation-shader-property-list",
);
for (const property of properties) {
const div = document.createElement("div");
div.classList.add("neuroglancer-annotation-shader-property");
const typeElement = document.createElement("span");
typeElement.classList.add(
"neuroglancer-annotation-shader-property-type",
);
for (const property of properties) {
const div = document.createElement("div");
div.classList.add("neuroglancer-annotation-shader-property");
const typeElement = document.createElement("span");
typeElement.classList.add(
"neuroglancer-annotation-shader-property-type",
);
typeElement.textContent = property.type;
const nameElement = document.createElement("span");
nameElement.classList.add(
"neuroglancer-annotation-shader-property-identifier",
);
nameElement.textContent = `prop_${property.identifier}`;
div.appendChild(typeElement);
div.appendChild(nameElement);
const { description } = property;
if (description !== undefined) {
div.title = description;
}
propertyList.appendChild(div);
typeElement.textContent = property.type;
const nameElement = document.createElement("span");
nameElement.classList.add(
"neuroglancer-annotation-shader-property-identifier",
);
nameElement.textContent = `prop_${property.identifier}`;
div.appendChild(typeElement);
div.appendChild(nameElement);
const { description } = property;
if (description !== undefined) {
div.title = description;
}
},
),
).element,
);
propertyList.appendChild(div);
}
},
),
).element;

element.appendChild(shaderProperties);
const topRow = document.createElement("div");
topRow.className =
"neuroglancer-segmentation-dropdown-skeleton-shader-header";
const label = document.createElement("div");
label.style.flex = "1";
label.textContent = "Annotation shader:";
topRow.appendChild(label);

const managedLayer = this.layer.managedLayer;
this.registerDisposer(
observeWatchable((visible) => {
shaderProperties.style.display = visible ? "block" : "none";
this.codeWidget.setVisible(visible);
}, managedLayer.codeVisible),
);
const codeVisibilityControl = new CheckboxIcon(managedLayer.codeVisible, {
enableTitle: "Show code",
disableTitle: "Hide code",
backgroundScheme: "dark",
svg: svgCode,
});
topRow.appendChild(codeVisibilityControl.element);

topRow.appendChild(
makeMaximizeButton({
title: "Show larger editor view",
Expand Down
20 changes: 20 additions & 0 deletions src/layer/image/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import "#src/layer/image/style.css";
import svgCode from "ikonate/icons/code-alt.svg?raw";

import type { CoordinateSpace } from "#src/coordinate_transform.js";
import {
Expand Down Expand Up @@ -54,6 +55,7 @@ import type { WatchableValueInterface } from "#src/trackable_value.js";
import {
makeCachedDerivedWatchableValue,
makeCachedLazyDerivedWatchableValue,
observeWatchable,
registerNested,
WatchableValue,
} from "#src/trackable_value.js";
Expand All @@ -79,6 +81,7 @@ import {
ShaderControlState,
} from "#src/webgl/shader_ui_controls.js";
import { ChannelDimensionsWidget } from "#src/widget/channel_dimensions_widget.js";
import { CheckboxIcon } from "#src/widget/checkbox_icon.js";
import { makeCopyButton } from "#src/widget/copy_button.js";
import type { DependentViewContext } from "#src/widget/dependent_view_widget.js";
import { makeHelpButton } from "#src/widget/help_button.js";
Expand Down Expand Up @@ -540,6 +543,22 @@ class RenderingOptionsTab extends Tab {
topRow.className = "neuroglancer-image-dropdown-top-row";
topRow.appendChild(document.createTextNode("Shader"));
topRow.appendChild(spacer);

const managedLayer = this.layer.managedLayer;
this.registerDisposer(
observeWatchable((visible) => {
this.codeWidget.setVisible(visible);
}, managedLayer.codeVisible),
);

const codeVisibilityControl = new CheckboxIcon(managedLayer.codeVisible, {
enableTitle: "Show code",
disableTitle: "Hide code",
backgroundScheme: "dark",
svg: svgCode,
});
topRow.appendChild(codeVisibilityControl.element);

topRow.appendChild(
makeMaximizeButton({
title: "Show larger editor view",
Expand All @@ -561,6 +580,7 @@ class RenderingOptionsTab extends Tab {
new ChannelDimensionsWidget(layer.channelCoordinateSpaceCombiner),
).element,
);

element.appendChild(this.codeWidget.element);
element.appendChild(
this.registerDisposer(
Expand Down
12 changes: 11 additions & 1 deletion src/layer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,11 +705,11 @@ export class ManagedUserLayer extends RefCounted {
set name(value: string) {
if (value !== this.name_) {
this.name_ = value;
this.layerChanged.dispatch();
aranega marked this conversation as resolved.
Show resolved Hide resolved
}
}

visible = true;
codeVisible = new TrackableBoolean(true, true);
archived = false;

get supportsPickOption() {
Expand Down Expand Up @@ -755,6 +755,7 @@ export class ManagedUserLayer extends RefCounted {
this.localVelocity,
),
);
this.codeVisible.changed.add(this.layerChanged.dispatch);
}

toJSON() {
Expand All @@ -764,6 +765,7 @@ export class ManagedUserLayer extends RefCounted {
}
const layerSpec = userLayer.toJSON();
layerSpec.name = this.name;
layerSpec.codeVisible = this.codeVisible.toJSON();
if (!this.visible) {
if (this.archived) {
layerSpec.archived = true;
Expand All @@ -774,6 +776,11 @@ export class ManagedUserLayer extends RefCounted {
return layerSpec;
}

setCodeVisible(value: boolean) {
this.codeVisible.value = value;
this.layerChanged.dispatch();
}

setVisible(value: boolean) {
if (value === this.visible) return;
if (value && this.archived) {
Expand Down Expand Up @@ -2018,6 +2025,9 @@ function initializeLayerFromSpecNoRestoreState(
} else {
managedLayer.visible = false;
}
managedLayer.codeVisible.restoreState(
verifyOptionalObjectProperty(spec, "codeVisible", verifyBoolean, true),
);
const layerConstructor = layerTypes.get(layerType) || NewUserLayer;
managedLayer.layer = new layerConstructor(managedLayer);
return spec;
Expand Down
20 changes: 19 additions & 1 deletion src/layer/single_mesh/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import "#src/layer/single_mesh/style.css";
import svgCode from "ikonate/icons/code-alt.svg?raw";

import type { ManagedUserLayer } from "#src/layer/index.js";
import {
Expand All @@ -32,10 +33,11 @@ import {
SingleMeshLayer,
} from "#src/single_mesh/frontend.js";
import type { WatchableValueInterface } from "#src/trackable_value.js";
import { WatchableValue } from "#src/trackable_value.js";
import { observeWatchable, WatchableValue } from "#src/trackable_value.js";
import type { Borrowed } from "#src/util/disposable.js";
import { RefCounted } from "#src/util/disposable.js";
import { removeChildren, removeFromParent } from "#src/util/dom.js";
import { CheckboxIcon } from "#src/widget/checkbox_icon.js";
import { makeHelpButton } from "#src/widget/help_button.js";
import { makeMaximizeButton } from "#src/widget/maximize_button.js";
import { ShaderCodeWidget } from "#src/widget/shader_code_widget.js";
Expand Down Expand Up @@ -207,6 +209,22 @@ class DisplayOptionsTab extends Tab {
spacer.style.flex = "1";

topRow.appendChild(spacer);

const managedLayer = this.layer.managedLayer;
this.registerDisposer(
observeWatchable((visible) => {
this.codeWidget.setVisible(visible);
}, managedLayer.codeVisible),
);

const codeVisibilityControl = new CheckboxIcon(managedLayer.codeVisible, {
enableTitle: "Show code",
disableTitle: "Hide code",
backgroundScheme: "dark",
svg: svgCode,
});
topRow.appendChild(codeVisibilityControl.element);

topRow.appendChild(
makeMaximizeButton({
title: "Show larger editor view",
Expand Down
8 changes: 8 additions & 0 deletions src/widget/shader_code_widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,12 @@ export class ShaderCodeWidget extends RefCounted {
this.textEditor = <any>undefined;
super.disposed();
}

setVisible(visible: boolean) {
this.element.style.display = visible ? "block" : "none";
}

isVisible() {
return this.element.style.display === "block";
}
}
Loading