Skip to content

Commit

Permalink
fixed space bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelthatsit committed Feb 15, 2024
1 parent 021e07e commit 31777aa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
4 changes: 2 additions & 2 deletions samples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
</mr-button>
</mr-div>

<mr-text class="title">
<mr-textfield class="title">
mr.js
</mr-text>
</mr-textfield>


<mr-div class="headset">
Expand Down
33 changes: 15 additions & 18 deletions src/core/componentSystems/TextSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,19 @@ export class TextSystem extends MRSystem {
}
if (textContentChanged || entity.needsStyleUpdate) {

if(text.length > 0) {
this.updateStyle(entity);
entity.textObj.sync(() => {
if (entity instanceof MRButton) {
entity.textObj.anchorX = 'center';
} else {
entity.textObj.position.setX(-entity.width / 2);
entity.textObj.position.setY(entity.height / 2);
}

if (isTextFieldOrArea) {
this.updateTextInput(entity)
}
});
} else {
this.updateStyle(entity);
entity.textObj.sync(() => {
if (entity instanceof MRButton) {
entity.textObj.anchorX = 'center';
} else {
entity.textObj.position.setX(-entity.width / 2);
entity.textObj.position.setY(entity.height / 2);
}

if (isTextFieldOrArea) {
this.updateTextInput(entity)
}
}
});
}
}
}
Expand All @@ -153,8 +147,11 @@ export class TextSystem extends MRSystem {
*/
updateStyle = (entity) => {
const { textObj } = entity;

textObj.font = this.preloadedFonts[entity.compStyle.fontFamily] ?? textObj.font;
if(textObj.text.trim().length != 0) {
textObj.font = this.preloadedFonts[entity.compStyle.fontFamily]
} else {
textObj.font = null
}
textObj.fontSize = this.parseFontSize(entity.compStyle.fontSize, entity);
textObj.fontWeight = this.parseFontWeight(entity.compStyle.fontWeight);
textObj.fontStyle = entity.compStyle.fontStyle;
Expand Down

0 comments on commit 31777aa

Please sign in to comment.