gyscos / cursive

A Text User Interface library for the Rust programming language
MIT License
4.31k stars 245 forks source link

Full width TextView not stretched as expected #300

Open michalfita opened 5 years ago

michalfita commented 5 years ago

Bug Report/Asking for Help

Problem description

Following code snippet (excerpt from modified example code):

    let mut panes = LinearLayout::vertical();

    panes.add_child(BoxView::with_full_screen(DummyView));
    panes.add_child(TextView::new("© 2018 Gal Anonym")
        .with_id("status")
        .full_width()
        .fixed_height(1));

    siv.screen_mut().add_transparent_layer(panes);

shows: obraz While I expect the bottom bar to be extended to maximum screen width. I can't tell whether it's a bug in the code or I don't understand documentation. However, maybe somebody can help.

Environment

gyscos commented 5 years ago

Hi, and thanks for the report! I think the problem is just that TextView only draws the background for the text it contains; so even though it extends to the right end of the screen, you don't see it. This is what you get with add_transparent_layer. You can manually wrap a view in a Layer, which will fill the background for the entire view.

michalfita commented 5 years ago

Right, makes sense:

    // Status bar
    let mut panes = LinearLayout::vertical();

    panes.add_child(BoxView::with_full_screen(DummyView));
    panes.add_child(Layer::new(
        PaddedView::new(
            ((1,1),(0,0)), TextView::new("© 2018 Cursive)
                .h_align(align::HAlign::Right)
                .with_id("status")
                .full_width()
                .fixed_height(1)
            )
        ));

    siv.screen_mut().add_transparent_layer(panes);

Produces what I want: obraz

As these issues act as good additional documentation, I think my example may help.

Plus, I believe it demonstrates some deficiencies of the current Cursive API.