@@ -30,7 +30,7 @@ interface TextDisplayOptions {
3030 align ?: Alignment
3131 visibility ?: boolean
3232}
33- type Alignment = 'left' | 'center' | 'right'
33+ export type Alignment = 'left' | 'center' | 'right'
3434
3535export class TextDisplay extends ResizableOutlinerElement {
3636 static type = `${ PACKAGE . name } :text_display`
@@ -42,7 +42,6 @@ export class TextDisplay extends ResizableOutlinerElement {
4242 public needsUniqueName = true
4343
4444 // Properties
45- public align : Alignment
4645 public config : IBlueprintTextDisplayConfigJSON
4746
4847 public menu = new Menu ( [
@@ -70,6 +69,8 @@ export class TextDisplay extends ResizableOutlinerElement {
7069 private _newBackgroundAlpha : number | undefined
7170 private _shadow = new Valuable ( false )
7271 private _newShadow : boolean | undefined
72+ private _align = new Valuable < Alignment > ( 'center' )
73+ private _newAlign : Alignment | undefined
7374
7475 constructor ( data : TextDisplayOptions , uuid = guid ( ) ) {
7576 super ( data , uuid )
@@ -112,6 +113,10 @@ export class TextDisplay extends ResizableOutlinerElement {
112113 this . _newShadow = v
113114 void this . updateText ( )
114115 } )
116+ this . _align . subscribe ( v => {
117+ this . _newAlign = v
118+ void this . updateText ( )
119+ } )
115120 }
116121
117122 public sanitizeName ( ) : string {
@@ -202,6 +207,16 @@ export class TextDisplay extends ResizableOutlinerElement {
202207 this . _shadow . set ( value )
203208 }
204209
210+ get align ( ) {
211+ if ( this . _align === undefined ) return TextDisplay . properties [ 'align' ] . default as Alignment
212+ return this . _align . get ( )
213+ }
214+
215+ set align ( value ) {
216+ if ( this . _align === undefined ) return
217+ this . _align . set ( value )
218+ }
219+
205220 getUndoCopy ( ) {
206221 const copy = new TextDisplay ( this )
207222
@@ -275,7 +290,8 @@ export class TextDisplay extends ResizableOutlinerElement {
275290 this . _newLineWidth !== undefined ||
276291 this . _newBackgroundColor !== undefined ||
277292 this . _newBackgroundAlpha !== undefined ||
278- this . _newShadow !== undefined
293+ this . _newShadow !== undefined ||
294+ this . _newAlign !== undefined
279295 ) {
280296 let text : JsonText | undefined
281297 this . textError . set ( '' )
@@ -291,6 +307,7 @@ export class TextDisplay extends ResizableOutlinerElement {
291307 this . _newBackgroundColor = undefined
292308 this . _newBackgroundAlpha = undefined
293309 this . _newShadow = undefined
310+ this . _newAlign = undefined
294311 if ( ! text ) continue
295312 latestMesh = await this . setText ( text )
296313 }
@@ -315,6 +332,7 @@ export class TextDisplay extends ResizableOutlinerElement {
315332 backgroundColor : this . backgroundColor ,
316333 backgroundAlpha : this . backgroundAlpha ,
317334 shadow : this . shadow ,
335+ alignment : this . align ,
318336 } )
319337 mesh . name = this . uuid + '_text'
320338 const previousMesh = this . mesh . children . find ( v => v . name === mesh . name )
0 commit comments