From a0de218f14b872b219df04834aa17c6be507ceef Mon Sep 17 00:00:00 2001 From: Doonv <58695417+doonv@users.noreply.github.com> Date: Mon, 22 Jul 2024 14:52:52 +0300 Subject: [PATCH] Update to Bevy 0.14 --- Cargo.toml | 6 ++--- src/command.rs | 2 +- src/config.rs | 42 ++++++++++++++++++----------- src/ui/completions.rs | 62 ++++++++++++++++++++++++------------------- 4 files changed, 64 insertions(+), 48 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7570d07..60a63f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,8 +23,8 @@ builtin-parser = ["dep:logos"] [dependencies] # This crate by itself doesn't use any bevy features, but `bevy_egui` (dep) uses "bevy_asset". -bevy = { version = "0.13.0", default-features = false, features = [] } -bevy_egui = "0.27.0" +bevy = { version = "0.14.0", default-features = false, features = [] } +bevy_egui = "0.28.0" chrono = "0.4.31" tracing-log = "0.2.0" tracing-subscriber = "0.3.18" @@ -35,7 +35,7 @@ logos = { version = "0.14.0", optional = true } fuzzy-matcher = { version = "0.3.7", optional = true } [dev-dependencies] -bevy = "0.13.0" +bevy = "0.14.0" [target.'cfg(target_os = "android")'.dependencies] diff --git a/src/command.rs b/src/command.rs index 8448c9f..9086998 100644 --- a/src/command.rs +++ b/src/command.rs @@ -3,7 +3,7 @@ use std::borrow::Cow; use std::ops::Range; -use bevy::ecs::system::Command; +use bevy::ecs::world::Command; use bevy::prelude::*; /// The command parser currently being used by the dev console. diff --git a/src/config.rs b/src/config.rs index adfdafd..0b03ace 100644 --- a/src/config.rs +++ b/src/config.rs @@ -64,9 +64,19 @@ pub trait ToColor32 { } impl ToColor32 for Color { fn to_color32(&self) -> Color32 { - let [r, g, b, a] = self.as_rgba_u8(); + let Srgba { + red, + green, + blue, + alpha, + } = self.to_srgba(); - Color32::from_rgba_unmultiplied(r, g, b, a) + Color32::from_rgba_unmultiplied( + (red * 255.0) as u8, + (green * 255.0) as u8, + (blue * 255.0) as u8, + (alpha * 255.0) as u8, + ) } } @@ -86,24 +96,24 @@ impl ConsoleTheme { /// Atom's iconic One Dark theme. pub const ONE_DARK: Self = Self { font: FontId::monospace(14.0), - dark: Color::rgb(0.42, 0.44, 0.48), - text_color: Color::rgb(0.67, 0.7, 0.75), - error: Color::rgb(0.91, 0.46, 0.5), - warning: Color::rgb(0.82, 0.56, 0.32), - info: Color::rgb(0.55, 0.76, 0.4), - debug: Color::rgb(0.29, 0.65, 0.94), - trace: Color::rgb(0.78, 0.45, 0.89), + dark: Color::srgb(0.42, 0.44, 0.48), + text_color: Color::srgb(0.67, 0.7, 0.75), + error: Color::srgb(0.91, 0.46, 0.5), + warning: Color::srgb(0.82, 0.56, 0.32), + info: Color::srgb(0.55, 0.76, 0.4), + debug: Color::srgb(0.29, 0.65, 0.94), + trace: Color::srgb(0.78, 0.45, 0.89), }; /// High contrast theme, might help some people. pub const HIGH_CONTRAST: Self = Self { font: FontId::monospace(14.0), - dark: Color::rgb(0.5, 0.5, 0.5), - text_color: Color::rgb(1.0, 1.0, 1.0), - error: Color::rgb(1.0, 0.0, 0.0), - warning: Color::rgb(1.0, 1.0, 0.0), - info: Color::rgb(0.0, 1.0, 0.0), - debug: Color::rgb(0.25, 0.25, 1.0), - trace: Color::rgb(1.0, 0.0, 1.0), + dark: Color::srgb(0.5, 0.5, 0.5), + text_color: Color::srgb(1.0, 1.0, 1.0), + error: Color::srgb(1.0, 0.0, 0.0), + warning: Color::srgb(1.0, 1.0, 0.0), + info: Color::srgb(0.0, 1.0, 0.0), + debug: Color::srgb(0.25, 0.25, 1.0), + trace: Color::srgb(1.0, 0.0, 1.0), }; /// Returns a [`Color32`] based on the `level` diff --git a/src/ui/completions.rs b/src/ui/completions.rs index 7bf491c..c94d1df 100644 --- a/src/ui/completions.rs +++ b/src/ui/completions.rs @@ -103,35 +103,41 @@ pub fn completions( } } } - egui::popup_below_widget(ui, text_edit_complete_id, &text_edit.response, |ui| { - ui.vertical(|ui| { - for ( - i, - CompletionSuggestion { - suggestion, - highlighted_indices, - }, - ) in completions.iter().take(6).enumerate() - { - let mut layout = egui::text::LayoutJob::default(); - for (i, _) in suggestion.char_indices() { - layout.append( - &suggestion[i..=i], - 0.0, - if highlighted_indices.contains(&i) { - config.theme.format_bold() - } else { - config.theme.format_text() - }, - ); - } - let res = ui.label(layout); - if i == state.selected_completion { - res.highlight(); + egui::popup_below_widget( + ui, + text_edit_complete_id, + &text_edit.response, + egui::PopupCloseBehavior::CloseOnClickOutside, + |ui| { + ui.vertical(|ui| { + for ( + i, + CompletionSuggestion { + suggestion, + highlighted_indices, + }, + ) in completions.iter().take(6).enumerate() + { + let mut layout = egui::text::LayoutJob::default(); + for (i, _) in suggestion.char_indices() { + layout.append( + &suggestion[i..=i], + 0.0, + if highlighted_indices.contains(&i) { + config.theme.format_bold() + } else { + config.theme.format_text() + }, + ); + } + let res = ui.label(layout); + if i == state.selected_completion { + res.highlight(); + } } - } - }) - }); + }) + }, + ); } /// Also consumes the up and down arrow keys.