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

Container with items are repeatedly rendering only the first item #14

Open
hedyhli opened this issue Jun 3, 2024 · 0 comments
Open

Comments

@hedyhli
Copy link

hedyhli commented Jun 3, 2024

using zi and zi-term 0.3.2, consider this minimal reproducible example:

use zi::{
    components::text::{Text, TextProperties},
    prelude::*,
};
use zi_term::Result;

struct App {
    link: ComponentLink<Self>,
}

impl Component for App {
    type Message = ();
    type Properties = ();

    fn create(_: Self::Properties, _frame: Rect, link: ComponentLink<Self>) -> Self {
        Self { link }
    }

    fn view(&self) -> Layout {
        let t1 = Text::with(TextProperties::new().content("1").style(
            Style::bold(Colour::black(), Colour::white())));

        let t2 = Text::with(TextProperties::new().content("2").style(
            Style::normal(Colour::rgb(100, 0, 0), Colour:: white())));

        let t3 = Text::with(TextProperties::new().content("3").style(
            Style::normal(Colour::rgb(0, 100, 0), Colour:: white())));

        Layout::column([
            Item::fixed(1)(
                Container::row([
                    Item::auto(t1),
                    Item::auto(t2),
                    Item::auto(t3),
                ])
            )]
        )
    }

    fn update(&mut self, _: Self::Message) -> ShouldRender {
        ShouldRender::Yes
    }

    fn bindings(&self, bindings: &mut Bindings<Self>) {
        if !bindings.is_empty() {
            return;
        }
        bindings.set_focus(true);
        bindings
            .command("exit", |this: &Self| this.link.exit())
            .with([Key::Char('q')]);
    }
}

fn main() -> Result<()> {
    let counter = App::with(());
    zi_term::incremental()?.run_event_loop(counter)
}

Expected

A row with 3 equally spaced columns with text 1, 2 and 3 of different background colors.

Actual

A row with 3 equally spaced columns, all three columns have the 1 text, with bold white on black style, i.e., item 1.

image

If the items are rearraged, to say, first t2, then t3, then t1, then all three columns show t2.

I encounter the same problem regardless of whether the flex direction is row or column.

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

1 participant