Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Border color doesn't change when changing color scheme #2686

Closed
Binto86 opened this issue May 29, 2023 · 19 comments · Fixed by #2687
Closed

Border color doesn't change when changing color scheme #2686

Binto86 opened this issue May 29, 2023 · 19 comments · Fixed by #2687
Labels
bug v1 For Issues & PRs targetting v1.x

Comments

@Binto86
Copy link

Binto86 commented May 29, 2023

Describe the bug
The border color of some Views (for example FrameView or Window) doesn't change when changing color scheme while the application is running.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new application using Terminal.Gui
  2. Add a new Window and add a FrameView and a Button into the Window
  3. Change the ColorScheme on the button click
  4. Run the application and see, that when clicking the button, the color of everything except the border changes

Expected behavior
The border foreground and background changes according to the new ColorScheme

Screenshots
Before button click:
image

After button click:
image

Desktop (please complete the following information):

  • OS: Windows 11
  • Version 1.12.1 of Terminal.Gui

Aditional information
The code I use to set up this example:

Application.Init();

var win = new Window("Test");
var frame = new FrameView()
{
    X = 5,
    Y = 10,
    Width = Dim.Fill() - 5,
    Height = Dim.Fill() - 10,
    Title = "Test Frame",
};
var button = new Button(50, 0, "Change theme");
button.Clicked += () => Clicked();

win.Add(button, frame);

Application.Top.Add(win);
Application.Run();
Application.Shutdown();

void Clicked()
{
    win.ColorScheme = new ColorScheme
    {
        Disabled = Attribute.Make(Color.White, Color.Black),
        Normal = Attribute.Make(Color.Cyan, Color.Black),
        HotNormal = Attribute.Make(Color.White, Color.Black),
        Focus = Attribute.Make(Color.White, Color.Black),
        HotFocus = Attribute.Make(Color.White, Color.Black),
    };
}
@tznind
Copy link
Collaborator

tznind commented May 29, 2023

In this case the border is on the Window not the TextView... can you please provide your code for this example? And indicate which version of Terminal.Gui you are using.

@Binto86
Copy link
Author

Binto86 commented May 29, 2023

I am sorry I totally screwed up setting up the example project, the problem is actually with FrameView, I will update the original post.
I am using version 1.12.1 of Terminal.Gui

@Binto86
Copy link
Author

Binto86 commented May 29, 2023

I also added the code i used for this example to the original post

@BDisp
Copy link
Collaborator

BDisp commented May 29, 2023

Here the workaround:

			void Clicked ()
			{
				win.ColorScheme = new ColorScheme {
					Disabled = Attribute.Make (Color.White, Color.Black),
					Normal = Attribute.Make (Color.Cyan, Color.Black),
					HotNormal = Attribute.Make (Color.White, Color.Black),
					Focus = Attribute.Make (Color.White, Color.Black),
					HotFocus = Attribute.Make (Color.White, Color.Black),
				};
				win.Border.Background = Color.Black;
				win.Border.BorderBrush = Color.White;
				frame.Border.Background = Color.Black;
				frame.Border.BorderBrush = Color.White;
			}

@Binto86
Copy link
Author

Binto86 commented May 30, 2023

@BDisp I know about this workaround, I just think that I shouldn't need to us it.

@tig
Copy link
Collaborator

tig commented May 30, 2023

@BDisp I know about this workaround, I just think that I shouldn't need to us it.

This is fixed in v2; the entire way borders works is different in v2. So for now, please you use the workaround.

@tig tig closed this as completed May 30, 2023
@Binto86
Copy link
Author

Binto86 commented May 30, 2023

@tig ok thanks for the info, I didn't know about that

@BDisp
Copy link
Collaborator

BDisp commented May 30, 2023

@tig I've the fix for this and I'll submit a PR soon. So, I reopen this. Thanks.

@BDisp
Copy link
Collaborator

BDisp commented May 30, 2023

@Binto86 please check if the fix #2687 is working as expected. Thanks.

@BDisp
Copy link
Collaborator

BDisp commented May 30, 2023

Here is the output:

border color-fix

@tig tig added bug v1 For Issues & PRs targetting v1.x labels May 30, 2023
@Binto86
Copy link
Author

Binto86 commented May 30, 2023

Nice this is the correct behaviour

@Binto86
Copy link
Author

Binto86 commented May 30, 2023

I will quickly clone the repo and test this locally

@Binto86
Copy link
Author

Binto86 commented May 30, 2023

Ok I get the same result as you, but I noticed that the FrameView title has the Normal colors, while the window title has Focus

@BDisp
Copy link
Collaborator

BDisp commented May 30, 2023

Ok I get the same result as you, but I noticed that the FrameView title has the Normal colors, while the window title has Focus

Because it has the focus and was the attributes you chosen:
Window has focus so it will use:
HotNormal = Attribute.Make (Color.Cyan, Color.Black) (for title)
HotFocus = Attribute.Make (Color.White, Color.Black) (for Button)

FrameView doesn't have focus so it will use:
Normal = Attribute.Make (Color.Cyan, Color.Black)

If you want the opposite, then you have to toggle these attributes.

@BDisp
Copy link
Collaborator

BDisp commented May 30, 2023

Try with this code:

			void Clicked ()
			{
				win.ColorScheme = new ColorScheme {
					Disabled = Attribute.Make (Color.White, Color.Black),
					Normal = Attribute.Make (Color.White, Color.Black),
					HotNormal = Attribute.Make (Color.Cyan, Color.Black),
					Focus = Attribute.Make (Color.White, Color.Black),
					HotFocus = Attribute.Make (Color.Cyan, Color.Black)
				};
			}

@BDisp
Copy link
Collaborator

BDisp commented May 30, 2023

I think you want this:

border color-fix

@BDisp
Copy link
Collaborator

BDisp commented May 30, 2023

For clarification, the attribute HotNormal is used to draw the title that has the focus, in this case the Window. The HotFoxus is used to draw the hot-key that has the focus, in this case the Button.

@Binto86
Copy link
Author

Binto86 commented May 30, 2023

okok, i don't need it, it was just thing I noticed and wasn't sure if its correct, otherwise, the fix is good imo

@BDisp
Copy link
Collaborator

BDisp commented May 30, 2023

Try this new code and you will understand that is very important how to set correctly the ColorScheme. Note that Window always have the focus because is the super-view.

			Application.Init ();

			var win = new Window ("Test");
			var frame = new FrameView () {
				X = 5,
				Y = 10,
				Width = Dim.Fill () - 5,
				Height = Dim.Fill () - 10,
				Title = "Test Frame",
			};
			ColorScheme originalScheme = null;

			var buttonFrame = new Button ("Restore theme") { X = Pos.Center () };
			buttonFrame.Clicked += () => RestoreTheme ();
			frame.Add (buttonFrame);

			var buttonWindow = new Button ("Change theme") { X = Pos.Center () };
			buttonWindow.Clicked += () => ChangeTheme ();

			win.Add (buttonWindow, frame);

			Application.Top.Add (win);
			Application.Run ();
			Application.Shutdown ();

			void ChangeTheme ()
			{
				originalScheme = win.ColorScheme;
				win.ColorScheme = new ColorScheme {
					Disabled = Attribute.Make (Color.White, Color.Black),
					Normal = Attribute.Make (Color.White, Color.Black),
					HotNormal = Attribute.Make (Color.Cyan, Color.Black),
					Focus = Attribute.Make (Color.Black, Color.White),
					HotFocus = Attribute.Make (Color.Cyan, Color.White)
				};
			}

			void RestoreTheme ()
			{
				win.ColorScheme = originalScheme;
			}

border color-fix

@tig tig closed this as completed in #2687 Jun 7, 2023
tig pushed a commit that referenced this issue Jun 7, 2023
…2687)

* Fixes #2686. Border color doesn't change when changing color scheme.

* Fix issue that was preventing unit test from running.

* Fixes #2688. ReadOnly TextView's broken scrolling after version update.

* keyModifiers must be reset after key up was been processed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug v1 For Issues & PRs targetting v1.x
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants