Hello I'm new in Bevy and Rust, therefore please forgive me if this is a dumb question.
Context here.
I'm currently making a generic button function, which can pass custom on-click logic. Here's the function:
create_button("tile_enter": &str, "Enter": &str, 25.0: f32,
||{
let str: String = read_input_field("tile_width": &str, world: &mut World);
println!("{}", str);
}: fn(),
parent: &mut ChildBuilder
);
This button needs to read the value of my input field on click, and then do something afterward. The problem is within the on-click function.
Because I don't know if there's a way to pass system parameters with normal parameters (eg. i8, &str, etc), I need to pass the world: &mut World from the root function into read_input_field(&str, &mut World).
I need to use the world: &mut World for querying value inside input field. Here's the function:
pub fn read_input_field(id: &str, world: &mut World) -> String {
let mut text_query = world.query::<(&InputFieldInner)>();
for input_field_inner in text_query.iter(&world) {
if input_field_inner.id.ne(id) {
continue;
}
return input_field_inner.text.to_string();
}
return String::new();
}
Firstly, I could not find a way to pass in the world: &mut World as parameter.
Secondly, I don't know if it's a good way to query components using world.query.
Thirdly, I don't know whether I could pass in system parameters with normal parameters within the same function (eg. fn example(query: Query<&Text>, random_data: &str))
It would be appreciable if someone could educate me regarding this topic. ❤️