Skip to content

Commit 896d66f

Browse files
authored
Merge pull request #74 from ruofeidu/main
Fixed fontColor for textButton and bump to 0.5.1
2 parents 6ca1ebb + be7eefa commit 896d66f

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "xrblocks",
3-
"version": "0.5.0",
3+
"version": "0.5.1",
44
"description": "XR Blocks SDK",
55
"main": "build/xrblocks.js",
66
"types": "build/xrblocks.d.ts",

samples/ui/index.html

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,13 +435,24 @@
435435

436436
const canvasTexture = new THREE.CanvasTexture(canvas);
437437
canvasTexture.needsUpdate = true;
438-
439-
const chartArea = chartGrid.addRow({weight: 0.85});
438+
const chartCol = chartGrid.addCol();
439+
chartCol.addRow({weight: 0.15});
440+
const chartArea = chartCol.addRow({weight: 0.85});
440441
const chartMesh = new THREE.Mesh(
441442
new THREE.PlaneGeometry(1, 1),
442443
new THREE.MeshBasicMaterial({map: canvasTexture})
443444
);
444445
chartArea.add(chartMesh);
446+
447+
const tmpRow = chartGrid.addCol();
448+
tmpRow.addRow({weight: 0.3});
449+
const okButton = tmpRow.addRow().addTextButton({
450+
text: 'OK',
451+
backgroundColor: '#22aa33',
452+
opacity: 0.5,
453+
fontColor: '#66ccff',
454+
fontSizeDp: 50,
455+
});
445456
}
446457

447458
init() {

src/ui/components/TextButton.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export type TextButtonOptions = TextViewOptions & {
1515
maxWidth?: number;
1616
radius?: number;
1717
boxSize?: number;
18+
hoverColor?: string | number;
19+
selectedFontColor?: string | number;
1820
};
1921

2022
export class TextButton extends TextView {
@@ -60,7 +62,7 @@ export class TextButton extends TextView {
6062
constructor(options: TextButtonOptions = {}) {
6163
const geometry = new THREE.PlaneGeometry(1, 1);
6264
const colorVec4 = getVec4ByColorString(
63-
options.backgroundColor ?? '#00000000'
65+
options.backgroundColor ?? '#000000'
6466
);
6567

6668
const {
@@ -93,6 +95,9 @@ export class TextButton extends TextView {
9395
// Applies our own overrides to the default values.
9496
this.fontSize = options.fontSize ?? this.fontSize;
9597
this.fontColor = options.fontColor ?? this.fontColor;
98+
this.hoverColor = options.hoverColor ?? this.hoverColor;
99+
this.selectedFontColor =
100+
options.selectedFontColor ?? this.selectedFontColor;
96101
this.width = options.width ?? this.width;
97102
this.height = options.height ?? this.height;
98103
}
@@ -119,18 +124,18 @@ export class TextButton extends TextView {
119124
if (!this.textObj) {
120125
return;
121126
}
122-
if (this.textObj) {
123-
this.textObj.renderOrder = this.renderOrder + 1;
124-
}
127+
// Update render order to ensure text appears on top of the button mesh
128+
this.textObj.renderOrder = this.renderOrder + 1;
129+
125130
const ux = this.ux;
126131
if (ux.isHovered()) {
127132
if (ux.isSelected()) {
128-
this.setTextColor(0x666666);
133+
this.setTextColor(this.selectedFontColor);
129134
} else {
130-
this.setTextColor(0xaaaaaa);
135+
this.setTextColor(this.hoverColor);
131136
}
132137
} else {
133-
this.setTextColor(0xffffff);
138+
this.setTextColor(this.fontColor);
134139
this.uniforms.uOpacity.value = this.defaultOpacity * this.opacity;
135140
}
136141
}

src/ui/components/TextView.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,9 @@ export class TextView extends View<TextViewEventMap> {
394394
}
395395
}
396396

397-
protected setTextColor(color: number) {
397+
protected setTextColor(color: number | string) {
398398
if (Text && this.textObj instanceof Text) {
399-
this.textObj.color = color;
399+
this.textObj.color = getColorHex(color);
400400
}
401401
}
402402

0 commit comments

Comments
 (0)