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

definite measure func #8111

Closed
ickshonpe opened this issue Mar 17, 2023 · 4 comments · Fixed by DioxusLabs/taffy#397
Closed

definite measure func #8111

ickshonpe opened this issue Mar 17, 2023 · 4 comments · Fixed by DioxusLabs/taffy#397
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior

Comments

@ickshonpe
Copy link
Contributor

ickshonpe commented Mar 17, 2023

Bevy version

Bevy Main doesn't support user measure funcs, so you need this branch:

bevy = { git = "https://github.com/ickshonpe/bevy.git", branch = "definite-measure-func" }

It just replaces the current measure func with this:

 let measure = taffy::node::MeasureFunc::Boxed(Box::new(
            move |_constraints: Size<Option<f32>>, available: Size<AvailableSpace>| {
                available.map(|a| a.into_option()).map(|v| v.unwrap_or(0.))
            },
        ));

and adds a resource bevy::ui::AlwaysUpdate which when present causes the UI to do a full update every frame.

What you did

https://github.com/ickshonpe/definite_measure_func

use bevy::prelude::*;
use bevy::ui::AlwaysUpdate;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup)
        .add_system(update)
        .run();
}

fn setup(mut commands: Commands) {
    commands.spawn(Camera2dBundle::default());
    commands.spawn((NodeBundle {
            background_color: Color::RED.into(),
            ..Default::default()
        },
        CalculatedSize::default()
    ));
}

fn update(
    mut commands: Commands, 
    input: Res<Input<KeyCode>>,
    always_update: Option<Res<AlwaysUpdate>>,
) {
    if input.just_pressed(KeyCode::Space) {
        if always_update.is_some() {
            commands.remove_resource::<AlwaysUpdate>();
        } else {
            commands.insert_resource(AlwaysUpdate);
        }
    }
}

What went wrong

unknown_2023.03.16-23.43_clip_1.mp4

The available horizontal space doesn't change when you enlarge the window horizontally.

Additional information

This can be fixed by doing a full update on all the nodes whenever the window resizes.
Because the full update gives the behaviour I expected, it looks to me like this is a bug and not just that I don't entirely understand the measure func constraints correctly or something.

It might just be that the only problem is that we weren't doing a full update on resizing when we needed to, but I'm not certain.

@ickshonpe ickshonpe added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Mar 17, 2023
@nicoburns
Copy link
Contributor

Definitely looks like a bug to me. Especially seeing as changing the vertical height fixes it! Weird that other layouts seem to work fine when resizing the window though...

@alice-i-cecile alice-i-cecile added A-UI Graphical user interfaces, styles, layouts, and widgets and removed S-Needs-Triage This issue needs to be labelled labels Mar 17, 2023
@ickshonpe
Copy link
Contributor Author

It's obvious now with this simple example, but I spent so many hours yesterday hacking around with the assumption there was something wrong with my text wrapping PR changes or the text pipeline 😅

@nicoburns
Copy link
Contributor

@ickshonpe This should be fixed by Taffy v0.3.9

@ickshonpe
Copy link
Contributor Author

ickshonpe commented Mar 20, 2023

Awesome, back to banging my head against the text-wrapping implementation 😣

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants