1
- using System ;
1
+ using NStack ;
2
+ using System ;
2
3
3
4
namespace Terminal . Gui {
4
5
/// <summary>
@@ -138,7 +139,7 @@ void Border_BorderChanged (Border border)
138
139
/// <summary>
139
140
/// Initializes with default null values.
140
141
/// </summary>
141
- public ToplevelContainer ( ) : this ( null , null ) { }
142
+ public ToplevelContainer ( ) : this ( null , string . Empty ) { }
142
143
143
144
/// <summary>
144
145
/// Initializes a <see cref="ToplevelContainer"/> with a <see cref="LayoutStyle.Computed"/>
@@ -147,7 +148,7 @@ public ToplevelContainer () : this (null, null) { }
147
148
/// <param name="title">The title.</param>
148
149
public ToplevelContainer ( Border border , string title = null )
149
150
{
150
- Initialize ( Rect . Empty , border , title ) ;
151
+ Initialize ( Rect . Empty , border , title ?? string . Empty ) ;
151
152
}
152
153
153
154
/// <summary>
@@ -158,17 +159,17 @@ public ToplevelContainer (Border border, string title = null)
158
159
/// <param name="title">The title.</param>
159
160
public ToplevelContainer ( Rect frame , Border border , string title = null ) : base ( frame )
160
161
{
161
- Initialize ( frame , border , title ) ;
162
+ Initialize ( frame , border , title ?? string . Empty ) ;
162
163
}
163
164
164
- private void Initialize ( Rect frame , Border border , string title = null )
165
+ private void Initialize ( Rect frame , Border border , string title )
165
166
{
166
167
ColorScheme = Colors . TopLevel ;
167
- Text = title ?? "" ;
168
168
if ( border == null ) {
169
169
Border = new Border ( ) {
170
170
BorderStyle = BorderStyle . Single ,
171
- BorderBrush = ColorScheme . Normal . Background
171
+ BorderBrush = ColorScheme . Normal . Background ,
172
+ Title = ( ustring ) title
172
173
} ;
173
174
} else {
174
175
Border = border ;
@@ -266,8 +267,12 @@ public override void Redraw (Rect bounds)
266
267
Border . DrawContent ( this , false ) ;
267
268
if ( HasFocus )
268
269
Driver . SetAttribute ( ColorScheme . HotNormal ) ;
269
- if ( Border . DrawMarginFrame )
270
- Border . DrawTitle ( this , Frame ) ;
270
+ if ( Border . DrawMarginFrame ) {
271
+ if ( ! ustring . IsNullOrEmpty ( Border . Title ) )
272
+ Border . DrawTitle ( this ) ;
273
+ else
274
+ Border . DrawTitle ( this , Frame ) ;
275
+ }
271
276
Driver . SetAttribute ( GetNormalColor ( ) ) ;
272
277
273
278
// Checks if there are any SuperView view which intersect with this window.
@@ -306,16 +311,20 @@ public override bool MouseEvent (MouseEvent mouseEvent)
306
311
}
307
312
308
313
/// <summary>
309
- /// Event to be invoked when any border property change .
314
+ /// Invoked when any property of Border changes (except <see cref="Child"/>) .
310
315
/// </summary>
311
316
public event Action < Border > BorderChanged ;
312
317
313
318
private BorderStyle borderStyle ;
314
319
private bool drawMarginFrame ;
315
320
private Thickness borderThickness ;
321
+ private Color borderBrush ;
322
+ private Color background ;
316
323
private Thickness padding ;
317
324
private bool effect3D ;
318
325
private Point effect3DOffset = new Point ( 1 , 1 ) ;
326
+ private Attribute ? effect3DBrush ;
327
+ private ustring title = ustring . Empty ;
319
328
320
329
/// <summary>
321
330
/// Specifies the <see cref="Gui.BorderStyle"/> for a view.
@@ -363,12 +372,24 @@ public Thickness BorderThickness {
363
372
/// <summary>
364
373
/// Gets or sets the <see cref="Color"/> that draws the outer border color.
365
374
/// </summary>
366
- public Color BorderBrush { get ; set ; }
375
+ public Color BorderBrush {
376
+ get => borderBrush ;
377
+ set {
378
+ borderBrush = value ;
379
+ OnBorderChanged ( ) ;
380
+ }
381
+ }
367
382
368
383
/// <summary>
369
384
/// Gets or sets the <see cref="Color"/> that fills the area between the bounds of a <see cref="Border"/>.
370
385
/// </summary>
371
- public Color Background { get ; set ; }
386
+ public Color Background {
387
+ get => background ;
388
+ set {
389
+ background = value ;
390
+ OnBorderChanged ( ) ;
391
+ }
392
+ }
372
393
373
394
/// <summary>
374
395
/// Gets or sets a <see cref="Thickness"/> value that describes the amount of space between a
@@ -448,7 +469,24 @@ public Point Effect3DOffset {
448
469
/// <summary>
449
470
/// Gets or sets the color for the <see cref="Border"/>
450
471
/// </summary>
451
- public Attribute ? Effect3DBrush { get ; set ; }
472
+ public Attribute ? Effect3DBrush {
473
+ get => effect3DBrush ;
474
+ set {
475
+ effect3DBrush = value ;
476
+ OnBorderChanged ( ) ;
477
+ }
478
+ }
479
+
480
+ /// <summary>
481
+ /// The title to be displayed for this view.
482
+ /// </summary>
483
+ public ustring Title {
484
+ get => title ;
485
+ set {
486
+ title = value ;
487
+ OnBorderChanged ( ) ;
488
+ }
489
+ }
452
490
453
491
/// <summary>
454
492
/// Calculate the sum of the <see cref="Padding"/> and the <see cref="BorderThickness"/>
@@ -677,6 +715,7 @@ private void DrawChildBorder (Rect frame, bool fill = true)
677
715
} ;
678
716
if ( rect . Width > 0 && rect . Height > 0 ) {
679
717
driver . DrawWindowFrame ( rect , 1 , 1 , 1 , 1 , BorderStyle != BorderStyle . None , fill , this ) ;
718
+ DrawTitle ( Child ) ;
680
719
}
681
720
}
682
721
@@ -831,6 +870,7 @@ private void DrawParentBorder (Rect frame, bool fill = true)
831
870
} ;
832
871
if ( rect . Width > 0 && rect . Height > 0 ) {
833
872
driver . DrawWindowFrame ( rect , 1 , 1 , 1 , 1 , BorderStyle != BorderStyle . None , fill , this ) ;
873
+ DrawTitle ( Parent ) ;
834
874
}
835
875
}
836
876
@@ -900,18 +940,47 @@ private void AddRuneAt (ConsoleDriver driver, int col, int row, Rune ch)
900
940
}
901
941
902
942
/// <summary>
903
- /// Drawn the view text from a <see cref="View "/>.
943
+ /// Draws the view <see cref="Title "/> to the screen .
904
944
/// </summary>
945
+ /// <param name="view">The view.</param>
946
+ public void DrawTitle ( View view )
947
+ {
948
+ var driver = Application . Driver ;
949
+ if ( DrawMarginFrame ) {
950
+ driver . SetAttribute ( Child . GetNormalColor ( ) ) ;
951
+ if ( Child . HasFocus )
952
+ driver . SetAttribute ( Child . ColorScheme . HotNormal ) ;
953
+ var padding = view . Border . GetSumThickness ( ) ;
954
+ Rect scrRect ;
955
+ if ( view == Child ) {
956
+ scrRect = view . ViewToScreen ( new Rect ( 0 , 0 , view . Frame . Width + 2 , view . Frame . Height + 2 ) ) ;
957
+ scrRect = new Rect ( scrRect . X - 1 , scrRect . Y - 1 , scrRect . Width , scrRect . Height ) ;
958
+ driver . DrawWindowTitle ( scrRect , Title , 0 , 0 , 0 , 0 ) ;
959
+ } else {
960
+ scrRect = view . ViewToScreen ( new Rect ( 0 , 0 , view . Frame . Width , view . Frame . Height ) ) ;
961
+ driver . DrawWindowTitle ( scrRect , Title ,
962
+ padding . Left , padding . Top , padding . Right , padding . Bottom ) ;
963
+ }
964
+ }
965
+ driver . SetAttribute ( Child . GetNormalColor ( ) ) ;
966
+ }
967
+
968
+ /// <summary>
969
+ /// Draws the <see cref="View.Text"/> to the screen.
970
+ /// </summary>
971
+ /// <param name="view">The view.</param>
972
+ /// <param name="rect">The frame.</param>
905
973
public void DrawTitle ( View view , Rect rect )
906
974
{
907
975
var driver = Application . Driver ;
908
- if ( BorderStyle != BorderStyle . None ) {
976
+ if ( DrawMarginFrame ) {
909
977
driver . SetAttribute ( view . GetNormalColor ( ) ) ;
910
978
if ( view . HasFocus ) {
911
979
driver . SetAttribute ( view . ColorScheme . HotNormal ) ;
912
980
}
913
- var padding = GetSumThickness ( ) ;
914
- driver . DrawWindowTitle ( rect , view . Text ,
981
+ var padding = Parent . Border . GetSumThickness ( ) ;
982
+ var scrRect = Parent . ViewToScreen ( new Rect ( 0 , 0 , rect . Width , rect . Height ) ) ;
983
+ driver . DrawWindowTitle ( scrRect , view . Text ,
915
984
padding . Left , padding . Top , padding . Right , padding . Bottom ) ;
916
985
}
917
986
driver . SetAttribute ( view . GetNormalColor ( ) ) ;
0 commit comments