Skip to content

Commit

Permalink
Update to git egui-sfml
Browse files Browse the repository at this point in the history
  • Loading branch information
crumblingstatue committed Oct 24, 2024
1 parent 2a1ad0d commit fce973d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 50 deletions.
9 changes: 4 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ either = "1.10.0"
tree_magic_mini = { version = "3.1.4", features = ["tree_magic_db"] }
bytemuck = "1.15.0"
slotmap = { version = "1.0.7", features = ["serde"] }
egui-sfml = { version = "0.6.0", optional = true }
egui-sfml = { git = "https://github.com/crumblingstatue/egui-sfml.git", optional = true }
num-traits = "0.2.18"
serde-big-array = "0.5.1"
egui = { version = "0.29", features = ["serde"] }
Expand Down
8 changes: 4 additions & 4 deletions src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Gui {
}
}

#[must_use = "Returns false if application should quit"]
/// The bool indicates whether the application should continue running
pub fn do_egui(
sf_egui: &mut SfEgui,
gui: &mut crate::gui::Gui,
Expand All @@ -94,8 +94,8 @@ pub fn do_egui(
rwin: &mut RenderWindow,
font_size: u16,
line_spacing: u16,
) -> anyhow::Result<bool> {
sf_egui.run(rwin, |_rwin, ctx| {
) -> anyhow::Result<(egui_sfml::DrawInput, bool)> {
let di = sf_egui.run(rwin, |_rwin, ctx| {
let mut open = IMMEDIATE.enabled() || PERSISTENT.enabled();
let was_open = open;
Window::new("Debug").open(&mut open).show(ctx, windows::debug_window::ui);
Expand Down Expand Up @@ -178,7 +178,7 @@ pub fn do_egui(
line_spacing,
);
})?;
Ok(true)
Ok((di, true))
}

pub fn set_font_sizes_ctx(ctx: &egui::Context, style: &Style) {
Expand Down
81 changes: 44 additions & 37 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,37 +319,43 @@ fn do_fatal_error_report(title: &str, mut desc: &str, backtrace: &Backtrace) {
}
}
rw.clear(Color::BLACK);
let _ = sf_egui.run(&mut rw, |rw, ctx| {
egui::CentralPanel::default().show(ctx, |ui| {
ui.heading(title);
ui.separator();
egui::ScrollArea::vertical().auto_shrink(false).max_height(500.).show(ui, |ui| {
ui.add(
egui::TextEdit::multiline(&mut desc)
.code_editor()
.desired_width(f32::INFINITY),
#[expect(clippy::unwrap_used)]
let di = sf_egui
.run(&mut rw, |rw, ctx| {
egui::CentralPanel::default().show(ctx, |ui| {
ui.heading(title);
ui.separator();
egui::ScrollArea::vertical().auto_shrink(false).max_height(500.).show(
ui,
|ui| {
ui.add(
egui::TextEdit::multiline(&mut desc)
.code_editor()
.desired_width(f32::INFINITY),
);
if !bt_string.is_empty() {
ui.heading("Backtrace");
ui.add(
egui::TextEdit::multiline(&mut bt_string.as_str())
.code_editor()
.desired_width(f32::INFINITY),
);
}
},
);
if !bt_string.is_empty() {
ui.heading("Backtrace");
ui.add(
egui::TextEdit::multiline(&mut bt_string.as_str())
.code_editor()
.desired_width(f32::INFINITY),
);
}
});
ui.separator();
ui.horizontal(|ui| {
if ui.button("Copy to clipboard").clicked() {
ui.output_mut(|out| out.copied_text = desc.to_owned());
}
if ui.button("Close").clicked() {
rw.close();
}
ui.separator();
ui.horizontal(|ui| {
if ui.button("Copy to clipboard").clicked() {
ui.output_mut(|out| out.copied_text = desc.to_owned());
}
if ui.button("Close").clicked() {
rw.close();
}
});
});
});
});
sf_egui.draw(&mut rw, None);
})
.unwrap();
sf_egui.draw(di, &mut rw, None);
rw.display();
}
}
Expand All @@ -376,7 +382,8 @@ fn do_frame(
update(app, sf_egui.context().wants_keyboard_input());
app.update(gui, window, lua, font_size, line_spacing);
let mp: ViewportVec = try_conv_mp_zero(window.mouse_position());
if !gui::do_egui(sf_egui, gui, app, mp, lua, window, font_size, line_spacing)? {
let (di, cont) = gui::do_egui(sf_egui, gui, app, mp, lua, window, font_size, line_spacing)?;
if !cont {
return Ok(false);
}
// Here we flush GUI command queue every frame
Expand All @@ -400,7 +407,7 @@ fn do_frame(
window.draw_text(&txt, &RenderStates::DEFAULT);
}
}
sf_egui.draw(window, None);
sf_egui.draw(di, window, None);
window.display();
// Should only be true on the frame right after reloading
app.just_reloaded = false;
Expand Down Expand Up @@ -642,12 +649,12 @@ fn handle_events(
clippy::cast_precision_loss,
reason = "Window sizes larger than i16::MAX aren't supported."
)]
window.set_view(&View::from_rect(Rect::new(
0.,
0.,
width as f32,
height as f32,
)));
match View::from_rect(Rect::new(0., 0., width as f32, height as f32)) {
Ok(view) => window.set_view(&view),
Err(e) => {
gamedebug_core::per!("Failed to create view: {e}");
}
}
}
_ => {}
}
Expand Down
6 changes: 3 additions & 3 deletions src/view/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ impl View {
}
},
);
rs.set_texture(Some(font.texture(hex.font_size.into())));
rs.texture = Some(font.texture(hex.font_size.into()));
}
ViewKind::Dec(dec) => {
draw_view(
Expand Down Expand Up @@ -510,7 +510,7 @@ impl View {
}
},
);
rs.set_texture(Some(font.texture(dec.font_size.into())));
rs.texture = Some(font.texture(dec.font_size.into()));
}
ViewKind::Text(text) => {
draw_view(
Expand Down Expand Up @@ -574,7 +574,7 @@ impl View {
}
},
);
rs.set_texture(Some(font.texture(text.font_size.into())));
rs.texture = Some(font.texture(text.font_size.into()));
}
ViewKind::Block => {
draw_view(
Expand Down

0 comments on commit fce973d

Please sign in to comment.