FyroxEngine / Fyrox

3D and 2D game engine written in Rust
https://fyrox.rs
MIT License
7.76k stars 353 forks source link

[Bug?] Multiple Calls of with_content to WindowBuilder seems to have unexpected behavior. #313

Closed DomtronVox closed 2 years ago

DomtronVox commented 2 years ago

I was messing around with an edge case of calling .with_content multiple time. I had assumed that the widget provided by the second call would just replace the previous widget. Instead the new widget is placed into the Window and the first widget just pops out of it and is placed on the application window at 0,0.

Is this a bug or is my assumption wrong and this is perfectly valid behavior?

Thanks!

Example code:

use fyrox::{
    core::{pool::Handle, algebra::Vector2},
    gui::{
        window::{WindowBuilder, WindowTitle}, 
        text::TextBuilder, 
        widget::WidgetBuilder, 
        UiNode, 
        UserInterface
    },
};

fn create_window(ui: &mut UserInterface) {
    WindowBuilder::new(
        WidgetBuilder::new()
            .with_desired_position(Vector2::new(300.0, 0.0))
            .with_width(300.0),
    )
    .with_content(
        TextBuilder::new(WidgetBuilder::new())
            .with_text("Example Window content.")
            .build(&mut ui.build_ctx())
    )
    .with_content(
        TextBuilder::new(WidgetBuilder::new())
            .with_text("Replacement text.")
            .build(&mut ui.build_ctx())
    )
    .with_title(WindowTitle::text("Window"))
    .can_close(true)
    .can_minimize(true)
    .open(true)
    .can_resize(false)
    .build(&mut ui.build_ctx());
}
mrDIMAS commented 2 years ago

This is perfectly valid behavior, because .with_content just sets a handle to inner content variable. Later this content will be attached to the inner panel of the window.