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

Pile failing to render anything at all. #231

Open
hydra opened this issue Dec 16, 2024 · 3 comments
Open

Pile failing to render anything at all. #231

hydra opened this issue Dec 16, 2024 · 3 comments

Comments

@hydra
Copy link
Contributor

hydra commented Dec 16, 2024

This minimal example works:

use cushy::widget::{MakeWidget};
use cushy::widgets::pile::Pile;
use cushy::Run;
use cushy::widgets::label::Displayable;

fn main() -> cushy::Result {
    let pile = Pile::default();

    let handle = pile.push("show a pile!".to_label());
    handle.show(false);

    pile.centered().expand()
        .run()
}

Source: https://github.com/hydra/cushy/blob/pile_fail_1/examples/pile.rs
Screenshot:
image

This example does not render the pile:

use cushy::widget::{MakeWidget};
use cushy::widgets::pile::Pile;
use cushy::{App, Run};
use cushy::widgets::label::Displayable;
use cushy::window::PendingWindow;

#[cushy::main]
fn main(app: &mut App) -> cushy::Result {
    let pending = PendingWindow::default();

    let pile = Pile::default();

    let handle = pile.push("show a pile!".to_label());
    handle.show(false);

    let ui = pending.with_root(
        pile.centered().expand()
    );

    ui.open_centered(app)?;

    Ok(())
}

Source: https://github.com/hydra/cushy/blob/pile_fail_1/examples/pile_fail_1.rs
Screenshot:
image

The only difference seems to be how the window is created.

This is blocking me from using Pile in my application.

@hydra
Copy link
Contributor Author

hydra commented Dec 16, 2024

in Pile::synchronize_widgets, the pile.widgets.entries() does not return any widget entries.

@hydra
Copy link
Contributor Author

hydra commented Dec 16, 2024

So it seems to be something to do with when the handle is dropped.

This example demonstrates that when there is no reference to the handle, the pile doesn't render the first (and only) widget in the pile, note that the button handler is commented out, and thus handle is free to be drop()ed by the compiler.

#[cushy::main]
fn main(app: &mut App) -> cushy::Result {
    let pending = PendingWindow::default();

    let pile = Pile::default();

    let handle = pile.push("show a pile 1!".to_label());
    handle.show(false);

    let show_first_button = format!("show first")
        .into_button()
        //.on_click({
        //    let section = handle.clone();
        //    move |_| section.show(true)
        //})
        .make_widget();

    println!("pile: {:?}", pile);

    let ui = pending.with_root(
        show_first_button
            .and(pile.centered().expand())
            .into_rows()
            .expand()
    );

    ui.open_centered(app)?;

    Ok(())
}

screenshot:
image

here's a callstack showing that PiledWidgetData is dropped, before the main window is shown.

image

however, if you restore the commented-out code, as follows, then it works:

...
    let show_first_button = format!("show first")
        .into_button()
        .on_click({
            let section = handle.clone();
            move |_| section.show(true)
        })
        .make_widget();
...

screenshot:
image

and here is a screenshot of the callstack showing that PiledWidgetData is dropped only when the application is closed.

image

I'm guessing this isn't intended and/or needs to be documented. I had to go down the rabbit-hole pretty far to figure this out and we probably don't want other users of Pile to be subjected to the same problem.

@hydra
Copy link
Contributor Author

hydra commented Dec 16, 2024

this seems to be stemming from the cushy::main macro which injects the main() body into an on_startup handler for the app, so even adding an explicit drop after ui.open_centered(app)?; doesn't help as the macro obfuscates the fact that main is really a closure.

It also feels like Pile::push needs a must_use attribute and/or #[allow(clippy::must_use_candidate)] in the same way impl PendingPiledWidget::finish() does.

hydra added a commit to MakerPnP/makerpnp that referenced this issue Dec 16, 2024
hydra added a commit to MakerPnP/makerpnp that referenced this issue Dec 16, 2024
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