1- import { Component , OnInit , ViewChild , ElementRef , HostListener , OnDestroy , ChangeDetectorRef , Input } from '@angular/core' ;
1+ import { Component , OnInit , ViewChild , ElementRef , HostListener , OnDestroy , ChangeDetectorRef , Input , AfterViewChecked } from '@angular/core' ;
22import { SocketService } from '../../shared/socket.service' ;
33import { MudMessage } from '../mud-message' ;
44import { DebugData } from '../debug-data' ;
@@ -14,19 +14,23 @@ import { ServerConfigService } from '../../shared/server-config.service';
1414 templateUrl : './mudclient.component.html' ,
1515 styleUrls : [ './mudclient.component.css' ]
1616} )
17- export class MudclientComponent implements OnInit , OnDestroy {
17+ export class MudclientComponent implements AfterViewChecked , OnInit , OnDestroy {
1818
1919 @Input ( ) cfg : WebmudConfig ;
2020 @ViewChild ( 'mudBlock' ) mudBlock : ElementRef ;
2121 @ViewChild ( 'mudInput' ) mudInput : ElementRef ;
22+ @ViewChild ( 'mudTest' ) mudTest : ElementRef ;
2223
2324 private mudc_id : string ;
2425 private mudName : string = 'disconnect' ;
2526 private connected : boolean ;
26- public freeParam : boolean = true ;
27+ public sizeCalculated : boolean = false ;
2728 public inpType : string = 'text' ;
2829 private mudc_width : number ;
2930 private mudc_height : number ;
31+ public ref_width : number ;
32+ public ref_height : number ;
33+ private ref_height_ratio :number ;
3034 private obs_connect ;
3135 private obs_connected ;
3236 private obs_data ;
@@ -117,26 +121,39 @@ export class MudclientComponent implements OnInit,OnDestroy {
117121 if ( typeof this . cfg !== 'undefined' && typeof this . cfg . mudname !== 'undefined'
118122 && this . cfg . mudname !== '' ) {
119123 this . mudName = this . cfg . mudname ;
120- this . freeParam = false ;
121124 }
122125 }
123126
124127 calculateSizing ( ) {
125128 var oh = this . mudBlock . nativeElement . offsetHeight ;
126129 var ow = this . mudBlock . nativeElement . offsetWidth ;
127- // var elem = this.srvcfgService.getHeight(this.mudBlock.nativeElement);
128- this . mudc_width = Math . floor ( ow / 7.5 ) ;
129- this . mudc_height = Math . floor ( oh / 16 ) ;
130- // console.log('MudSize: '+this.mudc_width+'x'+this.mudc_height);
130+ if ( this . mudc_height != Math . floor ( oh / this . ref_height_ratio ) ) {
131+ this . mudc_height = Math . floor ( oh / this . ref_height_ratio ) ;
132+ console . log ( 'MudSize: ' + this . mudc_width + 'x' + this . mudc_height + ' <= ' + ow + 'x' + oh ) ;
133+ if ( typeof this . mudc_id === 'undefined' && this . cfg . autoConnect ) {
134+ this . connect ( ) ;
135+ }
136+ }
131137 this . cfgService . setMudOutputSize ( oh , ow ) ;
138+ if ( typeof this . mudc_id !== undefined ) {
139+ this . socketService . setMudOutputSize ( this . mudc_id , this . mudc_height , this . mudc_height ) ;
140+ }
132141 }
133142
134- ngAfterViewInit ( ) {
135- this . calculateSizing ( ) ;
136- if ( ! this . freeParam ) {
137- if ( this . cfg . autoConnect ) {
138- this . connect ( ) ;
139- }
143+ calculateTest ( ) {
144+ this . ref_width = this . mudTest . nativeElement . offsetWidth ;
145+ this . ref_height = this . mudTest . nativeElement . offsetHeight ;
146+ this . mudc_width = 80 ;
147+ this . ref_height_ratio = this . ref_height / 25.0 ;
148+ }
149+
150+ ngAfterViewChecked ( ) {
151+ var other = this ;
152+ if ( ! this . sizeCalculated ) {
153+ this . calculateTest ( ) ;
154+ setTimeout ( function ( ) { other . sizeCalculated = true ; } , 500 ) ;
155+ } else {
156+ this . calculateSizing ( ) ;
140157 }
141158 }
142159
0 commit comments