mirror of
https://github.com/djibux/BoilR.git
synced 2026-09-01 05:53:41 +02:00
Clean up whitespace
This commit is contained in:
@@ -80,7 +80,9 @@ pub async fn download_images_for_users<'b>(
|
||||
|
||||
//Validate that the downloads where ok
|
||||
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 {
|
||||
// Image is too small, something went wrong
|
||||
//Try to delete file again, don't care if it fails
|
||||
|
||||
+35
-30
@@ -87,7 +87,8 @@ impl MyEguiApp {
|
||||
fn render_ui_image_action(&self, ui: &mut egui::Ui) -> UserAction {
|
||||
let state = &self.image_selected_state;
|
||||
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()
|
||||
{
|
||||
return UserAction::BackButton;
|
||||
@@ -124,7 +125,10 @@ impl MyEguiApp {
|
||||
Some(shortcuts) => {
|
||||
let user_info = &self.image_selected_state.steam_user.as_ref().unwrap();
|
||||
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 mut clicked = false;
|
||||
if let Some(texture) = texture {
|
||||
@@ -134,7 +138,7 @@ impl MyEguiApp {
|
||||
clamp_to_width(&mut size, 100.);
|
||||
let image_button = ImageButton::new(texture, size);
|
||||
clicked = clicked || ui.add(image_button).clicked();
|
||||
},
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@@ -200,7 +204,9 @@ impl MyEguiApp {
|
||||
let image_handles = &self.image_selected_state.image_handles;
|
||||
let path = &image.thumbnail_path;
|
||||
//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);
|
||||
let to_download = ToDownload {
|
||||
path: path.clone(),
|
||||
@@ -327,7 +333,9 @@ impl MyEguiApp {
|
||||
let image = load_image_from_path(&path);
|
||||
if let Some(image) = 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 swap = self.image_selected_state.image_handles.get(&new_key);
|
||||
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 to_download = ToDownload {
|
||||
path: to,
|
||||
@@ -425,14 +428,13 @@ impl MyEguiApp {
|
||||
}
|
||||
|
||||
fn clear_loaded_images(&mut self) {
|
||||
|
||||
match &*self.image_selected_state.image_options.borrow() {
|
||||
FetcStatus::Fetched(options) => {
|
||||
for option in options {
|
||||
let key = option.thumbnail_path.to_string_lossy().to_string();
|
||||
self.image_selected_state.image_handles.remove(&key);
|
||||
}
|
||||
},
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@@ -452,13 +454,14 @@ impl MyEguiApp {
|
||||
}
|
||||
state.selected_shortcut = Some(shortcut.clone());
|
||||
|
||||
|
||||
for image_type in ImageType::all() {
|
||||
let (path, key) = shortcut.key(image_type, &Path::new(&user.steam_user_data_folder));
|
||||
let image = load_image_from_path(&path);
|
||||
if let Some(image) = 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);
|
||||
@@ -511,18 +514,17 @@ fn render_shortcut_images(ui: &mut egui::Ui, state: &ImageSelectState) -> Option
|
||||
for image_type in ImageType::all() {
|
||||
ui.label(image_type.name());
|
||||
let (_path, key) = shortcut.key(&image_type, Path::new(&user_path));
|
||||
let texture = state.image_handles.get(&key).map(|k| {
|
||||
match k.value(){
|
||||
let texture = state
|
||||
.image_handles
|
||||
.get(&key)
|
||||
.map(|k| match k.value() {
|
||||
TextureState::Loaded(texture) => Some(texture.clone()),
|
||||
_ => {
|
||||
None
|
||||
}
|
||||
}
|
||||
}).flatten();
|
||||
_ => None,
|
||||
})
|
||||
.flatten();
|
||||
if render_thumbnail(ui, texture, &image_type) {
|
||||
return Some(UserAction::ImageTypeSelected(*image_type));
|
||||
}
|
||||
|
||||
}
|
||||
None
|
||||
}
|
||||
@@ -542,7 +544,11 @@ fn render_user_select(state: &ImageSelectState, ui: &mut egui::Ui) -> UserAction
|
||||
|
||||
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 {
|
||||
let mut size = texture.size_vec2();
|
||||
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);
|
||||
match image_type {
|
||||
ImageType::Icon => false,
|
||||
_=> added.on_hover_text("Click to change image").clicked()
|
||||
_ => added.on_hover_text("Click to change image").clicked(),
|
||||
}
|
||||
} else {
|
||||
match image_type {
|
||||
ImageType::Icon => {
|
||||
ui.label("No icon found");
|
||||
false
|
||||
},
|
||||
_=>
|
||||
ui.button("Pick an image").clicked(),
|
||||
}
|
||||
_ => ui.button("Pick an image").clicked(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,5 +292,8 @@ impl MyEguiApp {
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -83,10 +83,6 @@ impl epi::App for MyEguiApp {
|
||||
let mut style: egui::Style = (*ctx.style()).clone();
|
||||
create_style(&mut style);
|
||||
ctx.set_style(style);
|
||||
|
||||
//Clean up thumbnails
|
||||
|
||||
|
||||
}
|
||||
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &epi::Frame) {
|
||||
|
||||
Reference in New Issue
Block a user