Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
Fixed some warnings, returned to pinning only the minor versions, and…
Browse files Browse the repository at this point in the history
… completed the last couple of TODOs in the PR.

egui_helpers::progress_bar() signature has changed due to egui version bump.
  • Loading branch information
jacobsky committed May 26, 2022
1 parent 2d795eb commit 60127a4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 37 deletions.
3 changes: 1 addition & 2 deletions example_project/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
34 changes: 5 additions & 29 deletions example_project/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ pub struct GodotEguiExample {
checkbox: bool,
icon_1: Ref<Texture>,
icon_2: Ref<Texture>,
use_custom_fonts: bool,
show_font_settings: bool,
}

Expand All @@ -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,
}
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);

Expand All @@ -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");
}
Expand Down
3 changes: 1 addition & 2 deletions godot_egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions godot_egui/src/egui_helpers.rs
Original file line number Diff line number Diff line change
@@ -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());

Expand All @@ -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(),
);

Expand Down
4 changes: 2 additions & 2 deletions godot_egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down

0 comments on commit 60127a4

Please sign in to comment.