Closed mizunokazumi closed 1 year ago
Here is a test case of using rtl
. Adding padding (padding: {left, right, top, bottom}
) cam fix this truncated issue.
Sorry, wrong example. In fact, the problem arose with the rtl change after initialization.
text.style.rtl = true
I already figured out that I need to call text.initRTL()
text.style.rtl = true
text.initRTL()
but after that I can't disable RTL (there is no reverse text.initRTL() method) - this is sad. In a project that uses localization switching, it is difficult to switch back to ltr (en -> ar -> en)
Maybe instead of initRTL something like
enableRTL() {
if (this.style.rtl) return
this.style.rtl = true
this.canvas.dir = 'rtl';
this.context.direction = 'rtl';
Object.values(this.imageManager.images).forEach((image) => {
image.originX = 1 - image.originX
})
this.canvas.style.display = 'none';
AddToDOM(this.canvas, this.scene.sys.canvas);
// And finally we set the x origin
this.originX = 1 - this.originX;
}
disableRTL() {
if (!this.style.rtl) return
this.style.rtl = false
this.canvas.dir = 'ltr';
this.context.direction = 'ltr';
Object.values(this.imageManager.images).forEach((image) => {
image.originX = 1 - image.originX
})
if (this.canvas.parentElement == this.scene.sys.canvas) {
this.scene.sys.canvas.removeChild(this.canvas)
}
// And finally we set the x origin
this.originX = 1 - this.originX;
}
Built-in text gameobject and BBCodeText do not support changing rtl after creating it.
For embedded gameobject text text.style.rtl = true
works quite well
For bbcodetext, the methods from my previous comment also work quite well — So I will use them
Thank you for your help and quick replies
Ah, I see, it is feature request about setting rtl during runtime, not a bug reporting of rendering in rtl mode.
Add setRTL
method to change rtl
setting during runtime, invoke setRTL
method before setting new content.
Demo, any click to toggle rtl
of last text game object.
Thank you!
The documentation for bbcodetext specifies the rtl flag, but when it is turned on, the text is severely truncated. This can be seen in the example from the documentation (if you add rtl: true): https://codepen.io/rexrainbow/pen/OZbOyg?editors=0010