#bevy_egui widget doesn't appear

5 messages · Page 1 of 1 (latest)

echo wedge
#

I'm trying to integrate it into my own codebase - in my code I create the entity async (not in Startup) as so

#[derive(Component)]
pub struct EguiGraph(egui_graphs::Graph<Properties, Properties, Directed, u16>);

impl Default for EguiGraph {
    fn default() -> Self {
        Self(egui_graphs::Graph::new(StableGraph::default()))
    }
}

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugins(EntropyPlugin::<WyRand>::new())
        .add_plugins(ProcGenPlugin)
        .add_plugins(EguiPlugin)
        .add_systems(Update, (on_gen_map_button, graph_update))
        .add_systems(Update, on_graph_created)
        .run();
}

fn on_gen_map_button(
    mut commands: Commands,
    mut contexts: EguiContexts,
    mut gen_event_ew: EventWriter<GenEvent>,
) {
    let ctx = contexts.ctx_mut();

    egui::Window::new("grew_ui").show(ctx, |ui| {
        if ui.button("Generate Map").clicked() {
            let entity = commands.spawn(EguiGraph::default());

            let map_config = MapConfig { difficulty: 1 };

            gen_event_ew.send(GenEvent {
                entity: entity.id(),
                kind: GenKind::Map(map_config),
            });
        }
    });
}
#

Then I wait until something gets updated and update egui_graph

fn on_graph_created(mut q_graphs: Query<(&mut EguiGraph, &DiGraph), Added<DiGraph>>) {
    for (mut egui_graph, digraph) in q_graphs.iter_mut() {
        println!("on_graph_created: {:?}", digraph.0);

        egui_graph.0 = egui_graphs::Graph::from(&digraph.0);
    }
}

On every frame I'm updating as so (similar to update_graph in the sample)

fn graph_update(mut contexts: EguiContexts, mut q_egui_graph: Query<&mut EguiGraph>) {
    let ctx = contexts.ctx_mut();

    if let Ok(mut egui_graph) = q_egui_graph.get_single_mut() {
        println!("egui_graph: {:?}", egui_graph.0);

        egui::CentralPanel::default().show(ctx, |ui| {
            ui.add(&mut GraphView::<
                _,
                _,
                _,
                _,
                egui_graphs::DefaultNodeShape,
                egui_graphs::DefaultEdgeShape<_>,
            >::new(&mut egui_graph.0));
        });
    }
}
#

Pressing the button a central panel appears but there is no graph.

#

Dumping the logs of the graphs

Sample that works

graph: Graph { g: StableGraph { Ty: "Directed", node_count: 2, edge_count: 1, edges: (0, 1), node weights: {0: Node { id: Some(NodeIndex(0)), location: Some([27.5 29.5]), payload: Properties(Null), label: "0", selected: false, dragged: false }, 1: Node { id: Some(NodeIndex(1)), location: Some([168.2 157.5]), payload: Properties(Null), label: "1", selected: false, dragged: false }}, edge weights: {0: Edge { id: Some(EdgeID { idx: EdgeIndex(0), order: 0 }), payload: Properties(Null), selected: false }}, free_node: NodeIndex(65535), free_edge: EdgeIndex(65535) } }
#

My code that doesn't

egui_graph: Graph { g: StableGraph { Ty: "Directed", node_count: 2, edge_count: 1, edges: (0, 1), node weights: {0: Node { id: Some(NodeIndex(0)), location: Some([49.3 136.5]), payload: Some(Properties(Null)), label: "0", selected: false, dragged: false, computed: ComputedNode { num_connections: 1 } }, 1: Node { id: Some(NodeIndex(1)), location: Some([246.8 198.5]), payload: Some(Properties(Null)), label: "1", selected: false, dragged: false, computed: ComputedNode { num_connections: 0 } }}, edge weights: {0: Edge { id: Some(EdgeID { idx: EdgeIndex(0), order: 0 }), payload: Some(Properties(Null)), selected: false }}, free_node: NodeIndex(65535), free_edge: EdgeIndex(65535) } }