Clean up whitespace

This commit is contained in:
Philip Kristoffersen
2022-04-28 23:39:23 +02:00
parent 29ad5ee2e7
commit 8e9cbd8652
4 changed files with 87 additions and 81 deletions
+3 -1
View File
@@ -80,7 +80,9 @@ pub async fn download_images_for_users<'b>(
//Validate that the downloads where ok //Validate that the downloads where ok
for to_download in to_downloads { for to_download in to_downloads {
let file_length = std::fs::metadata(&to_download.path).map(|m| m.len()).unwrap_or_default(); let file_length = std::fs::metadata(&to_download.path)
.map(|m| m.len())
.unwrap_or_default();
if file_length < 2 { if file_length < 2 {
// Image is too small, something went wrong // Image is too small, something went wrong
//Try to delete file again, don't care if it fails //Try to delete file again, don't care if it fails
+35 -30
View File
@@ -87,7 +87,8 @@ impl MyEguiApp {
fn render_ui_image_action(&self, ui: &mut egui::Ui) -> UserAction { fn render_ui_image_action(&self, ui: &mut egui::Ui) -> UserAction {
let state = &self.image_selected_state; let state = &self.image_selected_state;
ui.heading("Images"); ui.heading("Images");
if (state.selected_shortcut.is_some() || (state.has_multiple_users() && state.steam_user.is_some())) if (state.selected_shortcut.is_some()
|| (state.has_multiple_users() && state.steam_user.is_some()))
&& ui.button("Back").clicked() && ui.button("Back").clicked()
{ {
return UserAction::BackButton; return UserAction::BackButton;
@@ -124,7 +125,10 @@ impl MyEguiApp {
Some(shortcuts) => { Some(shortcuts) => {
let user_info = &self.image_selected_state.steam_user.as_ref().unwrap(); let user_info = &self.image_selected_state.steam_user.as_ref().unwrap();
for shortcut in shortcuts { for shortcut in shortcuts {
let (_,key) = shortcut.key(&ImageType::Grid, Path::new(&user_info.steam_user_data_folder)); let (_, key) = shortcut.key(
&ImageType::Grid,
Path::new(&user_info.steam_user_data_folder),
);
let texture = self.image_selected_state.image_handles.get(&key); let texture = self.image_selected_state.image_handles.get(&key);
let mut clicked = false; let mut clicked = false;
if let Some(texture) = texture { if let Some(texture) = texture {
@@ -134,7 +138,7 @@ impl MyEguiApp {
clamp_to_width(&mut size, 100.); clamp_to_width(&mut size, 100.);
let image_button = ImageButton::new(texture, size); let image_button = ImageButton::new(texture, size);
clicked = clicked || ui.add(image_button).clicked(); clicked = clicked || ui.add(image_button).clicked();
}, }
_ => {} _ => {}
} }
} }
@@ -200,7 +204,9 @@ impl MyEguiApp {
let image_handles = &self.image_selected_state.image_handles; let image_handles = &self.image_selected_state.image_handles;
let path = &image.thumbnail_path; let path = &image.thumbnail_path;
//Redownload if file is too small //Redownload if file is too small
if !path.exists() || std::fs::metadata(path).map(|m| m.len()).unwrap_or_default() < 2{ if !path.exists()
|| std::fs::metadata(path).map(|m| m.len()).unwrap_or_default() < 2
{
image_handles.insert(image_key.clone(), TextureState::Downloading); image_handles.insert(image_key.clone(), TextureState::Downloading);
let to_download = ToDownload { let to_download = ToDownload {
path: path.clone(), path: path.clone(),
@@ -327,7 +333,9 @@ impl MyEguiApp {
let image = load_image_from_path(&path); let image = load_image_from_path(&path);
if let Some(image) = image { if let Some(image) = image {
let texture = ui.ctx().load_texture(&key, image); let texture = ui.ctx().load_texture(&key, image);
state.image_handles.insert(key, TextureState::Loaded(texture)); state
.image_handles
.insert(key, TextureState::Loaded(texture));
} }
} }
} }
@@ -395,17 +403,12 @@ impl MyEguiApp {
let _ = self.image_selected_state.image_handles.remove(&old_key); let _ = self.image_selected_state.image_handles.remove(&old_key);
let swap = self.image_selected_state.image_handles.get(&new_key); let swap = self.image_selected_state.image_handles.get(&new_key);
if let Some(swp) = swap { if let Some(swp) = swap {
self.image_selected_state.image_handles.insert(old_key, swp.value().clone()); self.image_selected_state
.image_handles
.insert(old_key, swp.value().clone());
} }
} }
let app_name = selected_image.app_name.clone(); let app_name = selected_image.app_name.clone();
let to_download = ToDownload { let to_download = ToDownload {
path: to, path: to,
@@ -425,14 +428,13 @@ impl MyEguiApp {
} }
fn clear_loaded_images(&mut self) { fn clear_loaded_images(&mut self) {
match &*self.image_selected_state.image_options.borrow() { match &*self.image_selected_state.image_options.borrow() {
FetcStatus::Fetched(options) => { FetcStatus::Fetched(options) => {
for option in options { for option in options {
let key = option.thumbnail_path.to_string_lossy().to_string(); let key = option.thumbnail_path.to_string_lossy().to_string();
self.image_selected_state.image_handles.remove(&key); self.image_selected_state.image_handles.remove(&key);
} }
}, }
_ => {} _ => {}
} }
} }
@@ -452,13 +454,14 @@ impl MyEguiApp {
} }
state.selected_shortcut = Some(shortcut.clone()); state.selected_shortcut = Some(shortcut.clone());
for image_type in ImageType::all() { for image_type in ImageType::all() {
let (path, key) = shortcut.key(image_type, &Path::new(&user.steam_user_data_folder)); let (path, key) = shortcut.key(image_type, &Path::new(&user.steam_user_data_folder));
let image = load_image_from_path(&path); let image = load_image_from_path(&path);
if let Some(image) = image { if let Some(image) = image {
let texture = ui.ctx().load_texture(&key, image); let texture = ui.ctx().load_texture(&key, image);
state.image_handles.insert(key,TextureState::Loaded(texture)); state
.image_handles
.insert(key, TextureState::Loaded(texture));
} }
} }
state.selected_shortcut = Some(shortcut); state.selected_shortcut = Some(shortcut);
@@ -511,18 +514,17 @@ fn render_shortcut_images(ui: &mut egui::Ui, state: &ImageSelectState) -> Option
for image_type in ImageType::all() { for image_type in ImageType::all() {
ui.label(image_type.name()); ui.label(image_type.name());
let (_path, key) = shortcut.key(&image_type, Path::new(&user_path)); let (_path, key) = shortcut.key(&image_type, Path::new(&user_path));
let texture = state.image_handles.get(&key).map(|k| { let texture = state
match k.value(){ .image_handles
.get(&key)
.map(|k| match k.value() {
TextureState::Loaded(texture) => Some(texture.clone()), TextureState::Loaded(texture) => Some(texture.clone()),
_ => { _ => None,
None })
} .flatten();
}
}).flatten();
if render_thumbnail(ui, texture, &image_type) { if render_thumbnail(ui, texture, &image_type) {
return Some(UserAction::ImageTypeSelected(*image_type)); return Some(UserAction::ImageTypeSelected(*image_type));
} }
} }
None None
} }
@@ -542,7 +544,11 @@ fn render_user_select(state: &ImageSelectState, ui: &mut egui::Ui) -> UserAction
const MAX_WIDTH: f32 = 300.; const MAX_WIDTH: f32 = 300.;
fn render_thumbnail(ui: &mut egui::Ui, image: Option<egui::TextureHandle>, image_type:&ImageType) -> bool { fn render_thumbnail(
ui: &mut egui::Ui,
image: Option<egui::TextureHandle>,
image_type: &ImageType,
) -> bool {
if let Some(texture) = image { if let Some(texture) = image {
let mut size = texture.size_vec2(); let mut size = texture.size_vec2();
clamp_to_width(&mut size, MAX_WIDTH); clamp_to_width(&mut size, MAX_WIDTH);
@@ -550,16 +556,15 @@ fn render_thumbnail(ui: &mut egui::Ui, image: Option<egui::TextureHandle>, image
let added = ui.add(image_button); let added = ui.add(image_button);
match image_type { match image_type {
ImageType::Icon => false, ImageType::Icon => false,
_=> added.on_hover_text("Click to change image").clicked() _ => added.on_hover_text("Click to change image").clicked(),
} }
} else { } else {
match image_type { match image_type {
ImageType::Icon => { ImageType::Icon => {
ui.label("No icon found"); ui.label("No icon found");
false false
}, }
_=> _ => ui.button("Pick an image").clicked(),
ui.button("Pick an image").clicked(),
} }
} }
} }
+4 -1
View File
@@ -292,5 +292,8 @@ impl MyEguiApp {
} }
fn looks_like_auth_key(content: &String) -> bool { fn looks_like_auth_key(content: &String) -> bool {
content.len() == 32 && content.is_ascii() && content.chars().all(char::is_alphanumeric) && content.chars().all(char::is_lowercase) content.len() == 32
&& content.is_ascii()
&& content.chars().all(char::is_alphanumeric)
&& content.chars().all(char::is_lowercase)
} }
-4
View File
@@ -83,10 +83,6 @@ impl epi::App for MyEguiApp {
let mut style: egui::Style = (*ctx.style()).clone(); let mut style: egui::Style = (*ctx.style()).clone();
create_style(&mut style); create_style(&mut style);
ctx.set_style(style); ctx.set_style(style);
//Clean up thumbnails
} }
fn update(&mut self, ctx: &egui::Context, _frame: &epi::Frame) { fn update(&mut self, ctx: &egui::Context, _frame: &epi::Frame) {