question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I want to draw horizontal line (HLine)

See original GitHub issue

I want to draw horizontal line (U+2500), just like the border of Window/FrameView, I use following code (shortened for brevity):

    private Label _topSeparatorLabel;

    public Window Win { get; private set; }

    public void Init( Toplevel top )
    {
      Win = new Window( "Application Name Setup" )
      {
        X = 0,
        Y = 0,
        Width = Dim.Fill(),
        Height = Dim.Fill() - 1
      };
    }

    public void Setup()
    {
      _topSeparatorLabel = new Label()
      {
        X = 0,
        Y = 5,
        Width = Dim.Width( Win ) - 2,
        Height = 1
      };
      _topSeparatorLabel.DrawContent += TopSeparatorLabel_DrawContent;

      Win.Add( _topSeparatorLabel );
    }

    private void TopSeparatorLabel_DrawContent( Rect obj )
    {
      _topSeparatorLabel.Text = new string( '\u2500', _topSeparatorLabel.Bounds.Width );
    }

The idea is I need some kind of Line control which I can put anywhere to separate content in Window. Since there is none, I think to simply use Label and give its Text with repeated value of \u2500.

Screenshot 2021-07-15 200151

Is this a good approach, or there will be a problem here? Thanks in advance.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:17

github_iconTop GitHub Comments

4reactions
tznindcommented, Jul 16, 2021

Here is a HorizontalLineView class I just created now for you 😃 this should be much more elegant and maintainable than using Label.

public class HorizontalLineView : View {

	public HorizontalLineView ()
	{
		CanFocus = false;
		Width = Dim.Fill ();
		Height = 1;
	}
	public override void Redraw (Rect bounds)
	{
		base.Redraw (bounds);

		Move (0, 0);
		Driver.SetAttribute (ColorScheme.Normal);

		var hLineWidth = Math.Max(1,Rune.ColumnWidth (Driver.HLine));

		for (int x = 0; x< bounds.Width;x += hLineWidth) {
			Move (x, 0);
			Driver.AddRune (Driver.HLine);
		}
	}
}

Heres some code to test it:

Application.Init ();

var window = new Window () { Width = Dim.Fill (), Height = Dim.Fill () };

window.Add (new Label ("hey, I'm above") { X = 0, Y = 0 });
window.Add (new HorizontalLineView () { X = 0, Y = 1 });
window.Add (new Label ("And I'm below") { X = 0, Y = 2 });

Application.Run (window);
Application.Shutdown ();

image

3reactions
ichan-akiracommented, Jul 16, 2021

@ichan-akira if @tznind accept my challenge, please reopens this issue again. Thanks.

Sure! I prefer to use Terminal.Gui generic control/view as well! That will be excellent 👍 (For time being I will use the custom made view by @tznind 😸 )

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I draw a horizontal line spanning only some of the ...
Here's a solution using booktabs and getting rid of of the vertical rules, which leads to a prettier result imho. Have a look...
Read more >
How do you make(draw) a horizontal line in LaTeX?
Easiest way to draw horizontal lines in Latex is to use the \rule[raise-height]{length}{thickness} command. And here you can pass length and thickness in ......
Read more >
python - Plot a horizontal line on a given plot
Use axhline (a horizontal axis line). For example, this plots a horizontal line at y = 0.5 : import matplotlib.pyplot as plt ...
Read more >
Simple hack to draw a perfectly vertical and horizontal line in ...
With this simple trick, you can draw a perfectly horizontal and vertical line in Ms Word and PowerPoint. Steps to draw a horizontal/...
Read more >
Plot a Horizontal line in Matplotlib
The axhline() function in pyplot module of matplotlib library is used to add a horizontal line across the axis. Syntax: matplotlib.pyplot.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found