Skip to content

Commit 2893597

Browse files
committed
making showLayerPanel option disable layer visibility always
1 parent b4ebc45 commit 2893597

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

src/layer_groups_layout.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ export class SingletonLayerGroupViewer
445445
...getCommonViewerState(viewer),
446446
},
447447
{
448-
showLayerPanel: viewer.uiControlVisibility.showLayerPanel,
448+
showLayerPanel: viewer.effectiveShowLayerPanel,
449449
showViewerMenu: false,
450450
showLayerHoverValues: viewer.uiControlVisibility.showLayerHoverValues,
451451
},
@@ -762,7 +762,7 @@ function makeComponent(container: LayoutComponentContainer, spec: any) {
762762
...getCommonViewerState(viewer),
763763
},
764764
{
765-
showLayerPanel: viewer.uiControlVisibility.showLayerPanel,
765+
showLayerPanel: viewer.effectiveShowLayerPanel,
766766
showViewerMenu: true,
767767
showLayerHoverValues: viewer.uiControlVisibility.showLayerHoverValues,
768768
},

src/ui/layer_list_panel.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ export class LayerListPanel extends SidePanel {
339339
sidePanelManager: SidePanelManager,
340340
public manager: TopLevelLayerListSpecification,
341341
public state: LayerListPanelState,
342+
public hideLayerPanel: TrackableBoolean,
342343
public showLayerPanel?: TrackableBoolean,
343344
) {
344345
super(sidePanelManager, state.location);
@@ -347,8 +348,9 @@ export class LayerListPanel extends SidePanel {
347348
this.titleElement = titleElement!;
348349

349350
// Add layer panel toggle button to title bar
350-
if (this.showLayerPanel) {
351-
const toggleButton = new CheckboxIcon(this.showLayerPanel, {
351+
// Only show toggle button when showLayerPanel configuration is enabled
352+
if (this.showLayerPanel?.value) {
353+
const toggleButton = new CheckboxIcon(this.hideLayerPanel, {
352354
svg: svg_eye,
353355
backgroundScheme: "dark",
354356
enableTitle: "Hide layer panel",
@@ -357,6 +359,23 @@ export class LayerListPanel extends SidePanel {
357359
toggleButton.element.style.order = "50"; // Position before close button (order: 100)
358360
titleBar.appendChild(toggleButton.element);
359361
this.registerDisposer(toggleButton);
362+
363+
// Watch for showLayerPanel configuration changes and hide/show button accordingly
364+
this.registerDisposer(
365+
this.showLayerPanel.changed.add(() => {
366+
if (this.showLayerPanel!.value) {
367+
// Configuration enabled - show button
368+
if (!toggleButton.element.parentElement) {
369+
titleBar.appendChild(toggleButton.element);
370+
}
371+
} else {
372+
// Configuration disabled - hide button
373+
if (toggleButton.element.parentElement) {
374+
toggleButton.element.remove();
375+
}
376+
}
377+
}),
378+
);
360379
}
361380
itemContainer.classList.add("neuroglancer-layer-list-panel-items");
362381
this.addBody(itemContainer);

src/viewer.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ class TrackableViewerState extends CompoundTrackable {
291291
this.add("hideLayerPanel", viewer.hideLayerPanelState);
292292

293293
// Add UI configuration to state for persistence
294-
for (const key of VIEWER_UI_CONFIG_OPTIONS) {
295-
this.add(key, viewer.uiConfiguration[key]);
296-
}
294+
// for (const key of VIEWER_UI_CONFIG_OPTIONS) {
295+
// this.add(key, viewer.uiConfiguration[key]);
296+
// }
297297
}
298298

299299
restoreState(obj: any) {
@@ -483,6 +483,7 @@ export class Viewer extends RefCounted implements ViewerState {
483483
dataSourceProvider: Borrowed<DataSourceRegistry>;
484484

485485
uiConfiguration: ViewerUIConfiguration;
486+
effectiveShowLayerPanel: WatchableValueInterface<boolean>;
486487

487488
private makeUiControlVisibilityState(key: keyof ViewerUIOptions) {
488489
const showUIControls = this.uiConfiguration.showUIControls;
@@ -562,6 +563,19 @@ export class Viewer extends RefCounted implements ViewerState {
562563

563564
this.dataSourceProvider = dataSourceProvider;
564565
this.uiConfiguration = uiConfiguration;
566+
567+
// Create effective showLayerPanel state that combines configuration and user preference
568+
this.effectiveShowLayerPanel = this.registerDisposer(
569+
makeDerivedWatchableValue(
570+
(configEnabled: boolean, hideState: boolean) => {
571+
// Layer panel is shown when config allows it AND hide state is false
572+
return configEnabled && !hideState;
573+
},
574+
this.uiConfiguration.showLayerPanel,
575+
this.hideLayerPanelState,
576+
)
577+
);
578+
565579

566580
this.registerDisposer(
567581
observeWatchable((value) => {
@@ -954,6 +968,7 @@ export class Viewer extends RefCounted implements ViewerState {
954968
this.sidePanelManager,
955969
this.layerSpecification,
956970
this.layerListPanelState,
971+
this.hideLayerPanelState,
957972
this.uiConfiguration.showLayerPanel,
958973
),
959974
}),

0 commit comments

Comments
 (0)