Skip to content
Extraits de code Groupes Projets
Vérifiée Valider f0a33841 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

AMADEUS: Update amadeus for new egui version (0.19)

parent fd20f1e9
Branches
Étiquettes
2 requêtes de fusion!193AMADEUS: Implementation of lkt-lib,!187Draft: Resolve "First Dry Update issue"
Pipeline #3224 en échec
Ce commit fait partie de la requête de fusion !187. Les commentaires créés ici seront créés dans le contexte de cette requête de fusion.
...@@ -9,9 +9,9 @@ lkt_lib = { path = "../lkt-lib" } ...@@ -9,9 +9,9 @@ lkt_lib = { path = "../lkt-lib" }
amadeus_macro = { path = "../amadeus-macro" } amadeus_macro = { path = "../amadeus-macro" }
serde = { version = "1", default-features = false, features = [ "derive", "std" ] } serde = { version = "1", default-features = false, features = [ "derive", "std" ] }
serde_json = { version = "1", default-features = false, features = [ "std" ] } serde_json = { version = "1", default-features = false, features = [ "std" ] }
eframe = { version = "0.17.0", features = [ "persistence" ] } eframe = { version = "0", features = [ "persistence" ] }
image = { version = "^0.24", default-features = false, features = [ "jpeg", "ico", "png" ] } image = { version = "^0.24", default-features = false, features = [ "jpeg", "ico", "png" ] }
egui = { version = "0.17.0", features = [ "extra_debug_asserts", "extra_asserts", "serde", "persistence" ] } egui = { version = "0", features = [ "extra_debug_asserts", "extra_asserts", "serde", "persistence" ] }
epi = { version = "0.17.0", features = [ "persistence" ] } epi = { version = "0", features = [ "persistence" ] }
log = { version = "0.4" } log = { version = "0.4" }
lazy_static = "1" lazy_static = "1"
\ No newline at end of file
...@@ -10,10 +10,7 @@ use crate::{ ...@@ -10,10 +10,7 @@ use crate::{
widgets, widgets,
}; };
use amadeus_macro::either; use amadeus_macro::either;
use eframe::{ use eframe::{egui, App};
egui,
epi::{self, App},
};
use lkt_lib::{ use lkt_lib::{
query::LektorQuery, query::LektorQuery,
response::LektorFormatedResponse, response::LektorFormatedResponse,
...@@ -98,8 +95,24 @@ impl Default for Amadeus<'_> { ...@@ -98,8 +95,24 @@ impl Default for Amadeus<'_> {
} }
impl Amadeus<'_> { impl Amadeus<'_> {
pub fn create() -> Box<Self> { pub fn create(cc: &eframe::CreationContext<'_>) -> Box<Self> {
Box::new(Amadeus::default()) let mut ret = Amadeus::default();
let ctx = &cc.egui_ctx;
if let Some(storage) = cc.storage {
ret.config = eframe::get_value(storage, "amadeus-rs-config").unwrap_or_default();
}
ctx.set_fonts(utils::font::get_font_definitions());
ret.load_amadeus_logo(ctx);
let mut style = (*ctx.style()).clone();
style.text_styles = utils::font::get_font_styles();
ctx.set_style(style);
ret.apply_settings();
ret.fill_debug_values();
Box::new(ret)
} }
fn load_amadeus_logo(&mut self, ctx: &egui::Context) { fn load_amadeus_logo(&mut self, ctx: &egui::Context) {
...@@ -109,7 +122,8 @@ impl Amadeus<'_> { ...@@ -109,7 +122,8 @@ impl Amadeus<'_> {
[size_x as usize, size_y as usize], [size_x as usize, size_y as usize],
pixels.as_slice(), pixels.as_slice(),
); );
self.amadeus_logo_texture = Some(ctx.load_texture("amadeus-logo", logo_texture)); self.amadeus_logo_texture =
Some(ctx.load_texture("amadeus-logo", logo_texture, egui::TextureFilter::Linear));
} }
fn collect_fulfilled_actions(&mut self) -> Vec<(u64, action::Action)> { fn collect_fulfilled_actions(&mut self) -> Vec<(u64, action::Action)> {
...@@ -138,7 +152,7 @@ impl Amadeus<'_> { ...@@ -138,7 +152,7 @@ impl Amadeus<'_> {
} }
} }
fn render_side_panel(&mut self, ctx: &egui::Context, _frame: &epi::Frame) { fn render_side_panel(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
if self.config.side_panel_show { if self.config.side_panel_show {
egui::SidePanel::left("LEFT_PANEL") egui::SidePanel::left("LEFT_PANEL")
.resizable(true) .resizable(true)
...@@ -158,7 +172,7 @@ impl Amadeus<'_> { ...@@ -158,7 +172,7 @@ impl Amadeus<'_> {
} }
} }
fn render_central_panel(&mut self, ctx: &egui::Context, _frame: &epi::Frame) { fn render_central_panel(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| { egui::CentralPanel::default().show(ctx, |ui| {
use utils::AmadeusMainView::*; use utils::AmadeusMainView::*;
match self.config.main_panel_view { match self.config.main_panel_view {
...@@ -184,7 +198,7 @@ impl Amadeus<'_> { ...@@ -184,7 +198,7 @@ impl Amadeus<'_> {
}); });
} }
fn render_bottom_panel(&mut self, ctx: &egui::Context, _frame: &epi::Frame) { fn render_bottom_panel(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
let seconds = time::SystemTime::now() let seconds = time::SystemTime::now()
.duration_since(time::SystemTime::UNIX_EPOCH) .duration_since(time::SystemTime::UNIX_EPOCH)
.unwrap() .unwrap()
...@@ -207,7 +221,7 @@ impl Amadeus<'_> { ...@@ -207,7 +221,7 @@ impl Amadeus<'_> {
if let Some(current_kara) = &self.lektord_current_kara { if let Some(current_kara) = &self.lektord_current_kara {
current_kara.render_compact(ui, self.config.dark_mode); current_kara.render_compact(ui, self.config.dark_mode);
} }
ui.with_layout(egui::Layout::right_to_left(), |ui| { ui.with_layout(egui::Layout::right_to_left(egui::Align::Min), |ui| {
ui.style_mut().override_text_style = Some(utils::font::heading3()); ui.style_mut().override_text_style = Some(utils::font::heading3());
ui.add_space(constants::PADDING * 2.); ui.add_space(constants::PADDING * 2.);
ui.label(text_duration); ui.label(text_duration);
...@@ -222,11 +236,11 @@ impl Amadeus<'_> { ...@@ -222,11 +236,11 @@ impl Amadeus<'_> {
}); });
} }
fn render_top_panel(&mut self, ctx: &egui::Context, frame: &epi::Frame) { fn render_top_panel(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
egui::TopBottomPanel::top("MENU").show(ctx, |ui| { egui::TopBottomPanel::top("MENU").show(ctx, |ui| {
ui.add_space(constants::TOP_PANEL_PADDING * 2.); ui.add_space(constants::TOP_PANEL_PADDING * 2.);
egui::menu::bar(ui, |ui| { egui::menu::bar(ui, |ui| {
ui.with_layout(egui::Layout::left_to_right(), |ui| { ui.with_layout(egui::Layout::left_to_right(egui::Align::Min), |ui| {
ui.style_mut().override_text_style = Some(utils::font::heading1()); ui.style_mut().override_text_style = Some(utils::font::heading1());
if ui.add(egui::Button::new("Amadeus").frame(false)).clicked() { if ui.add(egui::Button::new("Amadeus").frame(false)).clicked() {
self.config.side_panel_show = !self.config.side_panel_show; self.config.side_panel_show = !self.config.side_panel_show;
...@@ -285,10 +299,10 @@ impl Amadeus<'_> { ...@@ -285,10 +299,10 @@ impl Amadeus<'_> {
.then(|| self.actions.push(action::Action::PlaybackNext)); .then(|| self.actions.push(action::Action::PlaybackNext));
}); });
ui.with_layout(egui::Layout::right_to_left(), |ui| { ui.with_layout(egui::Layout::right_to_left(egui::Align::Min), |ui| {
ui.style_mut().override_text_style = Some(utils::font::body()); ui.style_mut().override_text_style = Some(utils::font::body());
if ui.add(egui::Button::new("❌")).clicked() { if ui.add(egui::Button::new("❌")).clicked() {
frame.quit(); frame.close();
} }
ui.style_mut().override_text_style = Some(utils::font::small_body()); ui.style_mut().override_text_style = Some(utils::font::small_body());
...@@ -449,7 +463,7 @@ impl Amadeus<'_> { ...@@ -449,7 +463,7 @@ impl Amadeus<'_> {
} }
impl App for Amadeus<'_> { impl App for Amadeus<'_> {
fn update(&mut self, ctx: &egui::Context, frame: &epi::Frame) { fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
self.begin_render_instant = time::SystemTime::now(); self.begin_render_instant = time::SystemTime::now();
ctx.request_repaint(); ctx.request_repaint();
self.set_visuals(ctx); self.set_visuals(ctx);
...@@ -482,30 +496,9 @@ impl App for Amadeus<'_> { ...@@ -482,30 +496,9 @@ impl App for Amadeus<'_> {
} }
} }
fn setup( fn save(&mut self, storage: &mut dyn eframe::Storage) {
&mut self,
ctx: &egui::Context,
_frame: &epi::Frame,
maybe_storage: Option<&dyn epi::Storage>,
) {
if let Some(storage) = maybe_storage {
self.config = eframe::epi::get_value(storage, "amadeus-rs-config").unwrap_or_default();
}
ctx.set_fonts(utils::font::get_font_definitions());
self.load_amadeus_logo(ctx);
let mut style = (*ctx.style()).clone();
style.text_styles = utils::font::get_font_styles();
ctx.set_style(style);
self.apply_settings();
self.fill_debug_values();
}
fn save(&mut self, storage: &mut dyn eframe::epi::Storage) {
if self.has_config_changed { if self.has_config_changed {
eframe::epi::set_value(storage, "amadeus-rs-config", &self.config); eframe::set_value(storage, "amadeus-rs-config", &self.config);
self.has_config_changed = false; self.has_config_changed = false;
} }
} }
...@@ -521,8 +514,4 @@ impl App for Amadeus<'_> { ...@@ -521,8 +514,4 @@ impl App for Amadeus<'_> {
fn auto_save_interval(&self) -> time::Duration { fn auto_save_interval(&self) -> time::Duration {
time::Duration::from_secs(1) time::Duration::from_secs(1)
} }
fn name(&self) -> &str {
"Amadeus"
}
} }
...@@ -103,7 +103,7 @@ impl Card<'_, Kara> for KaraCard { ...@@ -103,7 +103,7 @@ impl Card<'_, Kara> for KaraCard {
format!("{} - {}", self.inner.category, self.inner.language), format!("{} - {}", self.inner.category, self.inner.language),
); );
if left_space >= MIN_WIDTH_FOR_ADDITIONAL_INFOS { if left_space >= MIN_WIDTH_FOR_ADDITIONAL_INFOS {
ui.with_layout(egui::Layout::right_to_left(), |ui| { ui.with_layout(egui::Layout::right_to_left(egui::Align::Min), |ui| {
ui.label(format!("kara by {}", self.inner.author)); ui.label(format!("kara by {}", self.inner.author));
}); });
} }
...@@ -114,7 +114,7 @@ impl Card<'_, Kara> for KaraCard { ...@@ -114,7 +114,7 @@ impl Card<'_, Kara> for KaraCard {
ui.colored_label(constants::get_text_color(dark_mode), song); ui.colored_label(constants::get_text_color(dark_mode), song);
ui.style_mut().override_text_style = Some(utils::font::body()); ui.style_mut().override_text_style = Some(utils::font::body());
if left_space >= MIN_WIDTH_FOR_ADDITIONAL_INFOS { if left_space >= MIN_WIDTH_FOR_ADDITIONAL_INFOS {
ui.with_layout(egui::Layout::right_to_left(), |ui| { ui.with_layout(egui::Layout::right_to_left(egui::Align::Min), |ui| {
if !self.inner.is_available { if !self.inner.is_available {
ui.colored_label( ui.colored_label(
constants::get_accent_color(dark_mode), constants::get_accent_color(dark_mode),
......
...@@ -16,7 +16,7 @@ fn main() { ...@@ -16,7 +16,7 @@ fn main() {
logger::set_level(log::Level::Debug); logger::set_level(log::Level::Debug);
eframe::run_native( eframe::run_native(
amadeus::Amadeus::create(), "amadeus-rs",
eframe::NativeOptions { eframe::NativeOptions {
maximized: false, maximized: false,
decorated: true, decorated: true,
...@@ -26,5 +26,6 @@ fn main() { ...@@ -26,5 +26,6 @@ fn main() {
icon_data: Some(utils::get_icon_data()), icon_data: Some(utils::get_icon_data()),
..Default::default() ..Default::default()
}, },
Box::new(|cc| amadeus::Amadeus::create(cc)),
); );
} }
...@@ -14,7 +14,6 @@ use std::{ ...@@ -14,7 +14,6 @@ use std::{
}; };
pub trait Deamon: Sized { pub trait Deamon: Sized {
#[must_use]
type Channels; type Channels;
/// Quit the deamon /// Quit the deamon
......
...@@ -19,9 +19,9 @@ pub(crate) fn get_icon_as_dynamic_image() -> (image::RgbaImage, [u32; 2]) { ...@@ -19,9 +19,9 @@ pub(crate) fn get_icon_as_dynamic_image() -> (image::RgbaImage, [u32; 2]) {
return (logo_buffer, size); return (logo_buffer, size);
} }
pub(crate) fn get_icon_data() -> epi::IconData { pub(crate) fn get_icon_data() -> eframe::IconData {
let (logo_buffer, [size_x, size_y]) = get_icon_as_dynamic_image(); let (logo_buffer, [size_x, size_y]) = get_icon_as_dynamic_image();
return epi::IconData { return eframe::IconData {
rgba: logo_buffer.to_vec(), rgba: logo_buffer.to_vec(),
height: size_y, height: size_y,
width: size_x, width: size_x,
......
...@@ -50,7 +50,7 @@ pub fn add_labelled_toggle_switch( ...@@ -50,7 +50,7 @@ pub fn add_labelled_toggle_switch(
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.style_mut().override_text_style = Some(utils::font::body()); ui.style_mut().override_text_style = Some(utils::font::body());
ui.add(egui::Label::new(before)); ui.add(egui::Label::new(before));
ui.with_layout(egui::Layout::right_to_left(), |ui| { ui.with_layout(egui::Layout::right_to_left(egui::Align::Min), |ui| {
let response = ui.add(toggle_switch(dark_mode, switch)); let response = ui.add(toggle_switch(dark_mode, switch));
*changed |= response.changed(); *changed |= response.changed();
}); });
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter