Empyreus / lanterna

Automatically exported from code.google.com/p/lanterna
GNU Lesser General Public License v3.0
0 stars 0 forks source link

Issue with borders and titles #7

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi!

I think I've found two issues with borders. 

First issue: When a panel uses Border.Invisible and a title, the title overlaps 
with the first row of the content. 

Sample code:

    Panel panel = new Panel("Panel");
    panel.setBorder(new Border.Invisible());
    panel.addComponent(new Label("Label 1"));
    panel.addComponent(new Label("Label 2"));
    panel.addComponent(new Label("Label 3"));

Result:

    LaPanel
    Label 2
    Label 3

Expected:

    Label 1
    Label 2
    Label 3

You could argue that the title should still be shown, but if no title is set 
then it looks a little weird. My patch assumes that for an invisible border, 
there is no title. 

Second issue: When a panel uses Border.Standard, the innerAreaLocation and 
innerAreaSize are calculated incorrectly, resulting in the contents being 
pushed down by one line and the last line being truncated. 

Sample code:

    Panel panel = new Panel("Panel");
    panel.setBorder(new Border.Standard());
    panel.addComponent(new Label("Label 1"));
    panel.addComponent(new Label("Label 2"));
    panel.addComponent(new Label("Label 3"));

Result:

    --Panel----
    |         |
    | Label 1 |
    | Label 2 |
    -----------

Expected:

    --Panel----
    | Label 1 |
    | Label 2 |
    | Label 3 |
    -----------

I've attached a patch that resolves these issues. It pushes the responsibility 
for drawing the panel title to the Border, as the title forms part of the 
window decoration rather than the contents. I felt this worked better for the 
invisible border scenario, but I guess it really depends on how you want it to 
work there. 

I also suspect there'll be issues if a panel title exceeds the dimensions of 
the Panel. 

Cheers,
Chris. 

Original issue reported on code.google.com by chips.do...@gmail.com on 29 Apr 2012 at 9:13

Attachments:

GoogleCodeExporter commented 9 years ago
Thank you!

Martin

Original comment by mab...@gmail.com on 29 Apr 2012 at 1:11

GoogleCodeExporter commented 9 years ago

Original comment by mab...@gmail.com on 29 Apr 2012 at 1:11

GoogleCodeExporter commented 9 years ago
There, I've committed your patch to both 1.0-branch and trunk. I fully agree 
with your reasoning, the Border class will take reponsibility for drawing 
titles. What to do when the title is bigger than the panel, I guess make the 
panel big enough, if possible. I'll have a look at that too.

Now, I only need to figure out how to make Maven create branches and make 
releases and 1.2 should be out. Then perhaps I could try submitting this to 
Maven central repos.

Original comment by mab...@gmail.com on 30 Apr 2012 at 12:56