From 60127a487b1da2773bb3f3ef08128037888fe5d9 Mon Sep 17 00:00:00 2001 From: Jacobsky Date: Thu, 26 May 2022 10:58:47 +0900 Subject: [PATCH] Fixed some warnings, returned to pinning only the minor versions, and completed the last couple of TODOs in the PR. egui_helpers::progress_bar() signature has changed due to egui version bump. --- example_project/Cargo.toml | 3 +-- example_project/src/lib.rs | 34 +++++----------------------------- godot_egui/Cargo.toml | 3 +-- godot_egui/src/egui_helpers.rs | 4 ++-- godot_egui/src/lib.rs | 4 ++-- 5 files changed, 11 insertions(+), 37 deletions(-) diff --git a/example_project/Cargo.toml b/example_project/Cargo.toml index 9891012..8a498d2 100644 --- a/example_project/Cargo.toml +++ b/example_project/Cargo.toml @@ -11,6 +11,5 @@ crate-type = ["cdylib"] [dependencies] gdnative = { git = "https://github.com/godot-rust/godot-rust.git", branch = "master" } -#gdnative = "0.10" -egui = "0.18.1" +egui = "0.18" godot_egui = { path = "../godot_egui" } diff --git a/example_project/src/lib.rs b/example_project/src/lib.rs index 71f1ef3..8d5798a 100644 --- a/example_project/src/lib.rs +++ b/example_project/src/lib.rs @@ -15,7 +15,6 @@ pub struct GodotEguiExample { checkbox: bool, icon_1: Ref, icon_2: Ref, - use_custom_fonts: bool, show_font_settings: bool, } @@ -29,7 +28,6 @@ impl GodotEguiExample { elapsed_time: 0.0, icon_1: load_texture("res://icon.png"), icon_2: load_texture("res://icon_ferris.png"), - use_custom_fonts: false, show_font_settings: false, } } @@ -68,8 +66,6 @@ impl GodotEguiExample { // You may also want to pass in `None` and draw a background using a regular Panel node instead. let frame = egui::Frame { inner_margin: egui::style::Margin::symmetric(20.0, 20.0), ..Default::default() }; - let mut should_reverse_font_priorities = false; - gui.map_mut(|gui, instance| { // We use the `update` method here to just draw a simple UI on the central panel. If you need more // fine-grained control, you can use update_ctx to get access to egui's context directly. @@ -132,15 +128,8 @@ impl GodotEguiExample { ui.label( "This example registers two custom fonts. Custom fonts can be registered from the \ Godot Editor by setting font paths. For more control, you can also use \ - egui::Context's set_fonts method to register fonts manually. - \nEgui does not currently support locally overriding a font, but you can switch the \ - global font priorities for an egui::Context so that different fonts take \ - precedence. The checkbox below will reverse the vector of fonts so that the last \ - one, our Custom Font 2, becomes the main font.", + egui::Context's set_fonts method to register fonts manually.", ); - if ui.checkbox(&mut self.use_custom_fonts, "Reverse font priorities").clicked() { - should_reverse_font_priorities = true; - } ui.add_space(5.0); @@ -155,33 +144,20 @@ impl GodotEguiExample { ui.add_space(5.0); ui.horizontal(|ui| { - ui.label("You can also configure font settings, check it out:"); + ui.label("You can also configure style settings, check it out:"); if ui.button("Font settings").clicked() { self.show_font_settings = true; } }); }); }); - // TODO: How fonts are stored has completely changed so this will need to be redone. + // TODO: How fonts are stored has completely changed so this will need to be redone if it is desired in the sample project. if self.show_font_settings { - // let mut font_definitions = ctx.fonts().definitions().clone(); - egui::Window::new("Settings").open(&mut self.show_font_settings).show(ctx, |_ui| { - // use egui::Widget; - // font_definitions.ui(ui); - // ui.fonts().texture().ui(ui); + egui::Window::new("Style Settings").open(&mut self.show_font_settings).show(ctx, |ui| { + ctx.style_ui(ui) }); - // ctx.set_fonts(font_definitions); } }); - - // TODO: How fonts are stored has completely changed so this will need to be redone. - // if should_reverse_font_priorities { - // gui.update_ctx(&instance, |ctx| { - // let mut font_defs = ctx.fonts().definitions().clone(); - // font_defs.fonts_for_family.get_mut(&egui::FontFamily::Proportional).unwrap().reverse(); - // ctx.set_fonts(font_defs); - // }) - // } }) .expect("Map mut should succeed"); } diff --git a/godot_egui/Cargo.toml b/godot_egui/Cargo.toml index 6feabeb..24d03a3 100644 --- a/godot_egui/Cargo.toml +++ b/godot_egui/Cargo.toml @@ -13,5 +13,4 @@ workspace = ".." [dependencies] gdnative = { git = "https://github.com/godot-rust/godot-rust.git", branch = "master"} -#gdnative = "0.10" -egui = "0.18.1" +egui = "0.18" diff --git a/godot_egui/src/egui_helpers.rs b/godot_egui/src/egui_helpers.rs index ae1004c..ed0c501 100644 --- a/godot_egui/src/egui_helpers.rs +++ b/godot_egui/src/egui_helpers.rs @@ -1,4 +1,4 @@ -pub fn progress_bar(ui: &mut egui::Ui, progress: f32) -> egui::Response { +pub fn progress_bar(ui: &mut egui::Ui, progress: f32, font_size: f32) -> egui::Response { let desired_size = ui.spacing().interact_size.y * egui::vec2(8.0, 0.8); let (rect, response) = ui.allocate_exact_size(desired_size, egui::Sense::hover()); @@ -17,7 +17,7 @@ pub fn progress_bar(ui: &mut egui::Ui, progress: f32) -> egui::Response { rect.center(), egui::Align2::CENTER_CENTER, format!("{:.2}", progress), - egui::FontId::proportional(24.0), // TODO(bromeon): which size? + egui::FontId::proportional(font_size), ui.style().visuals.text_color(), ); diff --git a/godot_egui/src/lib.rs b/godot_egui/src/lib.rs index e113549..9a3e230 100644 --- a/godot_egui/src/lib.rs +++ b/godot_egui/src/lib.rs @@ -98,6 +98,7 @@ impl GodotEgui { raw_input: Rc::new(RefCell::new(egui::RawInput::default())), mouse_was_captured: false, override_default_fonts: false, + // reverse_font_priority: false, custom_fonts: [None, None, None, None, None], scroll_speed: 20.0, consume_mouse_events: true, @@ -114,8 +115,7 @@ impl GodotEgui { let _ = self.egui_ctx.end_frame(); // This is where "res://" points to - //let mut font_defs = self.egui_ctx.fonts().definitions().clone(); - let mut font_defs = FontDefinitions::default(); // TODO(bromeon): changed from egui 0.15->0.18; correct? + let mut font_defs = FontDefinitions::default(); if self.override_default_fonts { font_defs.families.get_mut(&egui::FontFamily::Proportional).unwrap().clear()