@@ -951,6 +951,10 @@ public virtual void Add (View view)
951
951
view . tabIndex = tabIndexes . IndexOf ( view ) ;
952
952
addingView = false ;
953
953
}
954
+ if ( view . Enabled && ! Enabled ) {
955
+ view . oldEnabled = true ;
956
+ view . Enabled = false ;
957
+ }
954
958
SetNeedsLayout ( ) ;
955
959
SetNeedsDisplay ( ) ;
956
960
OnAdded ( view ) ;
@@ -1303,14 +1307,16 @@ public virtual void PositionCursor ()
1303
1307
return ;
1304
1308
}
1305
1309
1306
- if ( focused ? . Visible == true && focused ? . Enabled == true && focused ? . Frame . Width > 0 && focused . Frame . Height > 0 ) {
1310
+ if ( focused == null && SuperView != null ) {
1311
+ SuperView . EnsureFocus ( ) ;
1312
+ } else if ( focused ? . Visible == true && focused ? . Enabled == true && focused ? . Frame . Width > 0 && focused . Frame . Height > 0 ) {
1307
1313
focused . PositionCursor ( ) ;
1314
+ } else if ( focused ? . Visible == true && focused ? . Enabled == false ) {
1315
+ focused = null ;
1316
+ } else if ( CanFocus && HasFocus && Visible && Frame . Width > 0 && Frame . Height > 0 ) {
1317
+ Move ( TextFormatter . HotKeyPos == - 1 ? 0 : TextFormatter . CursorPosition , 0 ) ;
1308
1318
} else {
1309
- if ( CanFocus && HasFocus && Visible && Frame . Width > 0 && Frame . Height > 0 ) {
1310
- Move ( TextFormatter . HotKeyPos == - 1 ? 0 : TextFormatter . CursorPosition , 0 ) ;
1311
- } else {
1312
- Move ( frame . X , frame . Y ) ;
1313
- }
1319
+ Move ( frame . X , frame . Y ) ;
1314
1320
}
1315
1321
}
1316
1322
@@ -1504,13 +1510,13 @@ public virtual void Redraw (Rect bounds)
1504
1510
var clipRect = new Rect ( Point . Empty , frame . Size ) ;
1505
1511
1506
1512
if ( ColorScheme != null ) {
1507
- Driver . SetAttribute ( HasFocus ? ColorScheme . Focus : ColorScheme . Normal ) ;
1513
+ Driver . SetAttribute ( HasFocus ? GetFocusColor ( ) : GetNormalColor ( ) ) ;
1508
1514
}
1509
1515
1510
1516
if ( ! IgnoreBorderPropertyOnRedraw && Border != null ) {
1511
1517
Border . DrawContent ( this ) ;
1512
1518
} else if ( ustring . IsNullOrEmpty ( TextFormatter . Text ) &&
1513
- ( GetType ( ) . IsNestedPublic ) && ! IsOverridden ( this , "Redraw" ) &&
1519
+ ( GetType ( ) . IsNestedPublic && ! IsOverridden ( this , "Redraw" ) || GetType ( ) . Name == "View ") &&
1514
1520
( ! NeedDisplay . IsEmpty || ChildNeedsDisplay || LayoutNeeded ) ) {
1515
1521
1516
1522
Clear ( ) ;
@@ -1525,8 +1531,8 @@ public virtual void Redraw (Rect bounds)
1525
1531
if ( TextFormatter != null ) {
1526
1532
TextFormatter . NeedsFormat = true ;
1527
1533
}
1528
- TextFormatter ? . Draw ( ViewToScreen ( Bounds ) , HasFocus ? ColorScheme . Focus : GetNormalColor ( ) ,
1529
- HasFocus ? ColorScheme . HotFocus : Enabled ? ColorScheme . HotNormal : ColorScheme . Disabled ,
1534
+ TextFormatter ? . Draw ( ViewToScreen ( Bounds ) , HasFocus ? GetFocusColor ( ) : GetNormalColor ( ) ,
1535
+ HasFocus ? ColorScheme . HotFocus : GetHotNormalColor ( ) ,
1530
1536
containerBounds ) ;
1531
1537
}
1532
1538
@@ -2617,7 +2623,13 @@ public override bool Enabled {
2617
2623
get => base . Enabled ;
2618
2624
set {
2619
2625
if ( base . Enabled != value ) {
2620
- base . Enabled = value ;
2626
+ if ( value ) {
2627
+ if ( SuperView == null || SuperView ? . Enabled == true ) {
2628
+ base . Enabled = value ;
2629
+ }
2630
+ } else {
2631
+ base . Enabled = value ;
2632
+ }
2621
2633
if ( ! value && HasFocus ) {
2622
2634
SetHasFocus ( false , this ) ;
2623
2635
}
@@ -2684,7 +2696,7 @@ public virtual Border Border {
2684
2696
/// to draw the view's border. If <see langword="true"/> no border is drawn (and the view is expected to draw the border
2685
2697
/// itself).
2686
2698
/// </summary>
2687
- public virtual bool IgnoreBorderPropertyOnRedraw { get ; set ; } = false ;
2699
+ public virtual bool IgnoreBorderPropertyOnRedraw { get ; set ; }
2688
2700
2689
2701
/// <summary>
2690
2702
/// Pretty prints the View
@@ -3109,6 +3121,17 @@ public virtual Attribute GetNormalColor ()
3109
3121
return Enabled ? ColorScheme . Normal : ColorScheme . Disabled ;
3110
3122
}
3111
3123
3124
+ /// <summary>
3125
+ /// Determines the current <see cref="ColorScheme"/> based on the <see cref="Enabled"/> value.
3126
+ /// </summary>
3127
+ /// <returns><see cref="Terminal.Gui.ColorScheme.Focus"/> if <see cref="Enabled"/> is <see langword="true"/>
3128
+ /// or <see cref="Terminal.Gui.ColorScheme.Disabled"/> if <see cref="Enabled"/> is <see langword="false"/>.
3129
+ /// If it's overridden can return other values.</returns>
3130
+ public virtual Attribute GetFocusColor ( )
3131
+ {
3132
+ return Enabled ? ColorScheme . Focus : ColorScheme . Disabled ;
3133
+ }
3134
+
3112
3135
/// <summary>
3113
3136
/// Determines the current <see cref="ColorScheme"/> based on the <see cref="Enabled"/> value.
3114
3137
/// </summary>
0 commit comments