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

Centering window label #2541

Closed
josefreichelt opened this issue Apr 13, 2023 · 4 comments
Closed

Centering window label #2541

josefreichelt opened this issue Apr 13, 2023 · 4 comments

Comments

@josefreichelt
Copy link

There doesnt seem to be a way to center the window title label.
Using v1
I'd expect TextAlignment to affect it, but it doesnt.

Is there a way to do this?

@BDisp
Copy link
Collaborator

BDisp commented Apr 13, 2023

In v1 there is no option for that. But in the v2 will have.

@tig
Copy link
Collaborator

tig commented Apr 13, 2023

See #2505

Closing.

@tig tig closed this as completed Apr 13, 2023
@tznind
Copy link
Collaborator

tznind commented Apr 14, 2023

@josefreichelt while this feature is appearing in v2 you can still achieve a similar thing in v1 with some manual drawing. See the code I had for this in the FileDialog. Something similar will ultimately mainfest in v2 so you can just remove it later on when you upgrade.

This code gives something like:

image

public override void Redraw (Rect bounds)
{
	base.Redraw (bounds);
	this.Move (1, 0, false);

	// TODO: Refactor this to some Title drawing options class
	if (ustring.IsNullOrEmpty (Title)) {
		return;
	}

	var title = this.Title.ToString ();
	var titleWidth = title.Sum (c => Rune.ColumnWidth (c));

	if (titleWidth > bounds.Width) {
		title = title.Substring (0, bounds.Width);
	} else {
		if (titleWidth + 2 < bounds.Width) {
			title = '╡' + this.Title.ToString () + '╞';
		}
		titleWidth += 2;
	}

	var padLeft = ((bounds.Width - titleWidth) / 2) - 1;

	padLeft = Math.Min (bounds.Width, padLeft);
	padLeft = Math.Max (0, padLeft);

	var padRight = bounds.Width - (padLeft + titleWidth + 2);
	padRight = Math.Min (bounds.Width, padRight);
	padRight = Math.Max (0, padRight);

	Driver.SetAttribute (
			  new Attribute (this.ColorScheme.Normal.Foreground, this.ColorScheme.Normal.Background));

	Driver.AddStr (ustring.Make (Enumerable.Repeat (Driver.HDLine, padLeft)));

	Driver.SetAttribute (
			  new Attribute (this.ColorScheme.Normal.Foreground, this.ColorScheme.Normal.Background));
	Driver.AddStr (title);

	Driver.SetAttribute (
			  new Attribute (this.ColorScheme.Normal.Foreground, this.ColorScheme.Normal.Background));

	Driver.AddStr (ustring.Make (Enumerable.Repeat (Driver.HDLine, padRight)));
}

@josefreichelt
Copy link
Author

Ah I see, thank you very much for the response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants