Skip to content

Commit

Permalink
Issue #805
Browse files Browse the repository at this point in the history
Labels now have show/hide methods.
  • Loading branch information
dkoes committed Aug 31, 2024
1 parent b5da96a commit cc817a8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
SpriteMaterial,
Sprite,
Vector2,
Material,
} from "./WebGL";
import { Gradient } from "./Gradient";
import { Color, CC, ColorSpec } from "./colors";
Expand Down Expand Up @@ -101,7 +102,7 @@ export class Label {
stylespec: any;
canvas: HTMLCanvasElement;
context: any;
sprite: any;
sprite: Sprite;
text: any;
frame: any;
constructor(text: string, parameters: LabelSpec) {
Expand All @@ -122,6 +123,15 @@ export class Label {
return this.stylespec;
}

hide() {
this.sprite.visible = false;
}

show() {

this.sprite.visible = true;
}

setContext() {
var style = this.stylespec;
var useScreen =
Expand Down Expand Up @@ -305,7 +315,7 @@ export class Label {
alignment: spriteAlignment,
depthTest: !inFront,
screenOffset: style.screenOffset || null,
});
}) as Material;

this.sprite.scale.set(1, 1, 1);

Expand Down
1 change: 1 addition & 0 deletions src/WebGL/objects/Sprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class Sprite extends Object3D {
_modelViewMatrix: any;
z?: number;
material?: Material;
hidden = false;

constructor(material = new SpriteMaterial() as Material) {
super();
Expand Down
11 changes: 11 additions & 0 deletions tests/auto/tests/hidelabel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@


let l = viewer.addLabel("Hello World",{position:{x:0,y:0,z:0},useScreen: true, fontSize: 64});
let l2 = viewer.addLabel("Hello World",{position:{x:10,y:0,z:0},backgroundColor: "blue",useScreen: true, fontSize: 64});
let l3 = viewer.addLabel("Hello World",{position:{x:10,y:100,z:0},backgroundColor: "yellow",useScreen: true, fontSize: 64});

l.hide();
l3.hide();
viewer.render( );
l3.show();
viewer.render();
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cc817a8

Please sign in to comment.