Skip to content

Commit

Permalink
feat(event-display): separate Phoenix menu UI from UI manager
Browse files Browse the repository at this point in the history
  • Loading branch information
9inpachi committed Apr 17, 2021
1 parent 7632a18 commit 5743adc
Show file tree
Hide file tree
Showing 4 changed files with 450 additions and 325 deletions.
2 changes: 1 addition & 1 deletion packages/phoenix-event-display/src/event-display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ export class EventDisplay {

// Remove the label if the string is empty
if (!label) {
this.ui.removeLabel(labelId);
this.ui.removeLabel(labelId, true);
return;
}

Expand Down
31 changes: 28 additions & 3 deletions packages/phoenix-event-display/src/ui/dat-gui-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { SceneManager } from '../three/scene-manager';
import { Color } from 'three';
import { Cut } from '../extras/cut.model';

/**
* A wrapper class for dat.GUI menu to perform UI related operations.
*/
export class DatGUIMenuUI {
/** dat.GUI menu. */
private gui: GUI;
Expand Down Expand Up @@ -31,7 +34,7 @@ export class DatGUIMenuUI {
private maxPositionZ = 4000;

/**
* Create dat.GUI menu with different controls related to detector geometry and event data.
* Create dat.GUI menu UI with different controls related to detector geometry and event data.
* @param elementId ID of the wrapper element.
* @param three The three manager for managing three.js related operations.
*/
Expand Down Expand Up @@ -295,7 +298,7 @@ export class DatGUIMenuUI {
}

/**
* Add labels folder to dat.GUI and Phoenix menu.
* Add labels folder to dat.GUI menu.
* @param configFunctions Functions to attach to the labels folder configuration.
*/
public addLabelsFolder(configFunctions: any) {
Expand Down Expand Up @@ -348,8 +351,9 @@ export class DatGUIMenuUI {
/**
* Add configuration UI for label.
* @param labelId Unique ID of the label.
* @param removeLabel Function to remove label from the scene.
*/
public addLabel(labelId: string) {
public addLabel(labelId: string, removeLabel?: () => void) {
this.guiParameters[labelId] = {
show: true,
color: 0xafafaf,
Expand All @@ -373,5 +377,26 @@ export class DatGUIMenuUI {
colorMenu.onChange((color) =>
this.three.getSceneManager().changeObjectColor(labelId, color)
);

this.guiParameters[labelId]['removeLabel'] = () => {
removeLabel?.();
this.removeLabel(labelId, labelItem);
};
labelItem.add(this.guiParameters[labelId], 'removeLabel').name('Remove');
}

/**
* Remove label from UI, scene and event data loader if it exists.
* @param labelId A unique label ID string.
* @param labelItemFolder dat.GUI folder of the label if any.
*/
public removeLabel(labelId: string, labelItemFolder?: GUI) {
if (!labelItemFolder) {
labelItemFolder = this.labelsFolder.__folders[labelId];
}

if (labelItemFolder) {
this.labelsFolder.removeFolder(labelItemFolder);
}
}
}
Loading

0 comments on commit 5743adc

Please sign in to comment.