Skip to content

View.Redraw doesn't clear itself and PositionCursor doesn't ensure focus when a prior view was disabled. #2354

@BDisp

Description

@BDisp

Is your feature request related to a problem? Please describe.
If a view with subviews is added the clear method isn't executed and only the subviews are redrawn.

Describe the solution you'd like
Allowing the view been clear by the base class and also ignore the HasFocus property in the Redraw method. If not ignore (default) the normal color is used if the view doesn't have the focus and the focus color is used if it have the focus. If ignore, then only the normal color is used whether is focused or not.

Describe alternatives you've considered
Only by deriving from View class and overridden the Redraw method but not needed with the solution above.

Additional context
For all this work some more improvements are needed, like on CanFocus, Add, PositionCursor, Redraw, Enabled.

Code to test the issue:

			Application.Init ();
			var root1 = new View () {
				Width = 20,
				Height = 10,
				ColorScheme = Colors.Base,
				//IgnoreHasFocusPropertyOnRedraw = true,
				Enabled = false
			};
			var label1 = new Label (new string ('c', 100)) {
				Width = Dim.Fill ()
			};
			var tv1 = new TextView () {
				Y = 2,
				Height = 1,
				Text = new string ('t', 100),
				Width = Dim.Fill (),
				Multiline = false
			};
			var labelFocus1 = new Label (new string ('f', 100)) {
				Y = 4,
				Width = Dim.Fill (),
				CanFocus = true
			};

			root1.Add (label1, tv1, labelFocus1);

			var root2 = new View () {
				X = 3,
				Y = 12,
				Width = 20,
				Height = 10,
				ColorScheme = Colors.Base,
				//IgnoreHasFocusPropertyOnRedraw = true
			};
			var label2 = new Label (new string ('c', 100)) {
				Width = Dim.Fill ()
			};
			var tv2 = new TextView () {
				Y = 2,
				Height = 1,
				Text = new string ('t', 100),
				Width = Dim.Fill (),
				Multiline = false
			};
			var labelFocus2 = new Label (new string ('f', 100)) {
				Y = 4,
				Width = Dim.Fill (),
				CanFocus = true
			};

			root2.Add (label2, tv2, labelFocus2);

			var sb = new StatusBar (new StatusItem [] {
				new StatusItem(Key.F9,"~F9~ Toggle Enable", () => {
					root1.Enabled = !root1.Enabled;
					root2.Enabled = !root2.Enabled;
				}),
				//new StatusItem(Key.F10,"~F10~ Toggle IgnoreHasFocusPropertyOnRedraw", () => {
				//	root1.IgnoreHasFocusPropertyOnRedraw = !root1.IgnoreHasFocusPropertyOnRedraw;
				//	root2.IgnoreHasFocusPropertyOnRedraw = !root2.IgnoreHasFocusPropertyOnRedraw;
				//	root1.SetNeedsDisplay();
				//	root2.SetNeedsDisplay();
				//})
			});

			Application.Top.Add (root1, root2, sb);
			Application.Run (Application.Top);

Try this code above and the output is this:

view-redraw-issue

After the fix, please remove all the commented code and the output is this:

view-redraw-fix

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions