Apply cargo fmt

Signed-off-by: kernelkind <kernelkind@gmail.com>
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
kernelkind 2024-04-17 13:36:19 -04:00 committed by William Casarin
parent ff5e5ed74a
commit c76f322a48
7 changed files with 49 additions and 41 deletions

View File

@ -2,8 +2,8 @@ use crate::app_style::NotedeckTextStyle;
use crate::key_parsing::{perform_key_retrieval, LoginError}; use crate::key_parsing::{perform_key_retrieval, LoginError};
use crate::login_manager::LoginManager; use crate::login_manager::LoginManager;
use egui::{ use egui::{
Align, Align2, Button, Color32, Frame, Id, LayerId, Margin, Pos2, Rect, Align, Align2, Button, Color32, Frame, Id, LayerId, Margin, Pos2, Rect, RichText, Rounding, Ui,
RichText, Rounding, Ui, Vec2, Window, Vec2, Window,
}; };
use egui::{Image, TextBuffer, TextEdit}; use egui::{Image, TextBuffer, TextEdit};
@ -149,9 +149,7 @@ impl<'a> DesktopAccountLoginView<'a> {
ui.add_space(8f32); ui.add_space(8f32);
ui.add( ui.add(login_textedit(&mut self.manager.login_key).min_size(Vec2::new(440.0, 40.0)));
login_textedit(&mut self.manager.login_key).min_size(Vec2::new(440.0, 40.0)),
);
ui.add_space(8.0); ui.add_space(8.0);
@ -193,7 +191,9 @@ impl<'a> DesktopAccountLoginView<'a> {
fn generate_group(&mut self, ui: &mut egui::Ui) { fn generate_group(&mut self, ui: &mut egui::Ui) {
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.label(RichText::new("New in nostr?").text_style(NotedeckTextStyle::Heading3.text_style())); ui.label(
RichText::new("New in nostr?").text_style(NotedeckTextStyle::Heading3.text_style()),
);
ui.label( ui.label(
RichText::new(" — we got you!") RichText::new(" — we got you!")
@ -266,7 +266,9 @@ fn login_button() -> Button<'static> {
fn login_textedit(text: &mut dyn TextBuffer) -> TextEdit { fn login_textedit(text: &mut dyn TextBuffer) -> TextEdit {
egui::TextEdit::singleline(text) egui::TextEdit::singleline(text)
.hint_text(RichText::new("Your key here...").text_style(NotedeckTextStyle::Body.text_style())) .hint_text(
RichText::new("Your key here...").text_style(NotedeckTextStyle::Body.text_style()),
)
.vertical_align(Align::Center) .vertical_align(Align::Center)
.min_size(Vec2::new(0.0, 40.0)) .min_size(Vec2::new(0.0, 40.0))
.margin(Margin::same(12.0)) .margin(Margin::same(12.0))

View File

@ -1,8 +1,7 @@
#![warn(clippy::all, rust_2018_idioms)] #![warn(clippy::all, rust_2018_idioms)]
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
use notedeck::Damus;
use notedeck::app_creation::generate_native_options; use notedeck::app_creation::generate_native_options;
use notedeck::Damus;
// Entry point for wasm // Entry point for wasm
//#[cfg(target_arch = "wasm32")] //#[cfg(target_arch = "wasm32")]

View File

@ -1,12 +1,11 @@
use crate::error::Error; use crate::error::Error;
use crate::result::Result;
use crate::imgcache::ImageCache; use crate::imgcache::ImageCache;
use crate::result::Result;
use egui::{Color32, ColorImage, SizeHint, TextureHandle}; use egui::{Color32, ColorImage, SizeHint, TextureHandle};
use image::imageops::FilterType; use image::imageops::FilterType;
use poll_promise::Promise; use poll_promise::Promise;
use tokio::fs;
use std::path; use std::path;
use tokio::fs;
//pub type ImageCacheKey = String; //pub type ImageCacheKey = String;
//pub type ImageCacheValue = Promise<Result<TextureHandle>>; //pub type ImageCacheValue = Promise<Result<TextureHandle>>;
@ -112,11 +111,15 @@ fn parse_img_response(response: ehttp::Response, size: u32) -> Result<ColorImage
} }
} }
fn fetch_img_from_disk(ctx: &egui::Context, url: &str, path: &path::Path) -> Promise<Result<TextureHandle>> { fn fetch_img_from_disk(
ctx: &egui::Context,
url: &str,
path: &path::Path,
) -> Promise<Result<TextureHandle>> {
let ctx = ctx.clone(); let ctx = ctx.clone();
let url = url.to_owned(); let url = url.to_owned();
let path = path.to_owned(); let path = path.to_owned();
Promise::spawn_async(async move { Promise::spawn_async(async move {
let data = fs::read(path).await?; let data = fs::read(path).await?;
let image_buffer = image::load_from_memory(&data)?; let image_buffer = image::load_from_memory(&data)?;
@ -152,7 +155,12 @@ pub fn fetch_img(
// TODO: fetch image from local cache // TODO: fetch image from local cache
} }
fn fetch_img_from_net(cache_path: &path::Path, ctx: &egui::Context, url: &str, size: u32) -> Promise<Result<TextureHandle>> { fn fetch_img_from_net(
cache_path: &path::Path,
ctx: &egui::Context,
url: &str,
size: u32,
) -> Promise<Result<TextureHandle>> {
let (sender, promise) = Promise::new(); let (sender, promise) = Promise::new();
let request = ehttp::Request::get(url); let request = ehttp::Request::get(url);
let ctx = ctx.clone(); let ctx = ctx.clone();
@ -166,9 +174,7 @@ fn fetch_img_from_net(cache_path: &path::Path, ctx: &egui::Context, url: &str, s
let texture_handle = ctx.load_texture(&cloned_url, img.clone(), Default::default()); let texture_handle = ctx.load_texture(&cloned_url, img.clone(), Default::default());
// write to disk // write to disk
std::thread::spawn(move || { std::thread::spawn(move || ImageCache::write(&cache_path, &cloned_url, img));
ImageCache::write(&cache_path, &cloned_url, img)
});
texture_handle texture_handle
}); });

View File

@ -4,24 +4,24 @@ mod error;
//mod note; //mod note;
//mod block; //mod block;
mod abbrev; mod abbrev;
mod fonts;
mod images;
mod result;
mod imgcache;
mod filter;
mod ui;
mod timecache;
mod time;
mod notecache;
mod frame_history;
mod timeline;
mod colors;
mod profile;
mod key_parsing;
pub mod login_manager;
pub mod account_login_view; pub mod account_login_view;
pub mod app_creation; pub mod app_creation;
mod app_style; mod app_style;
mod colors;
mod filter;
mod fonts;
mod frame_history;
mod images;
mod imgcache;
mod key_parsing;
pub mod login_manager;
mod notecache;
mod profile;
mod result;
mod time;
mod timecache;
mod timeline;
mod ui;
#[cfg(test)] #[cfg(test)]
#[macro_use] #[macro_use]

View File

@ -8,7 +8,7 @@ pub struct LoginManager {
pub login_key: String, pub login_key: String,
pub promise: Option<Promise<Result<Keys, LoginError>>>, pub promise: Option<Promise<Result<Keys, LoginError>>>,
pub error: Option<LoginError>, pub error: Option<LoginError>,
pub key_on_error: Option<String> pub key_on_error: Option<String>,
} }
impl LoginManager { impl LoginManager {
@ -17,7 +17,7 @@ impl LoginManager {
login_key: String::new(), login_key: String::new(),
promise: None, promise: None,
error: None, error: None,
key_on_error: None key_on_error: None,
} }
} }
} }

View File

@ -36,4 +36,4 @@ impl eframe::App for MobileAccountLoginPreview {
fn update(&mut self, ctx: &egui::Context, _: &mut eframe::Frame) { fn update(&mut self, ctx: &egui::Context, _: &mut eframe::Frame) {
MobileAccountLoginView::new(ctx, &mut self.manager).panel() MobileAccountLoginView::new(ctx, &mut self.manager).panel()
} }
} }

View File

@ -2,7 +2,7 @@ mod account_login_preview;
mod egui_preview_setup; mod egui_preview_setup;
use account_login_preview::{DesktopAccountLoginPreview, MobileAccountLoginPreview}; use account_login_preview::{DesktopAccountLoginPreview, MobileAccountLoginPreview};
use egui_preview_setup::{EguiPreviewCase, EguiPreviewSetup}; use egui_preview_setup::{EguiPreviewCase, EguiPreviewSetup};
use notedeck::app_creation::{generate_native_options, generate_mobile_emulator_native_options}; use notedeck::app_creation::{generate_mobile_emulator_native_options, generate_native_options};
use std::env; use std::env;
fn run_test_app<F, T, O>(create_supr: F, create_child: O, is_mobile: bool) fn run_test_app<F, T, O>(create_supr: F, create_child: O, is_mobile: bool)
@ -26,15 +26,16 @@ where
); );
} }
fn main() { fn main() {
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
if args.len() > 1 { if args.len() > 1 {
match args[1].as_str() { match args[1].as_str() {
"DesktopAccountLoginPreview" => { "DesktopAccountLoginPreview" => run_test_app(
run_test_app(EguiPreviewSetup::new, DesktopAccountLoginPreview::new, false) EguiPreviewSetup::new,
} DesktopAccountLoginPreview::new,
false,
),
"MobileAccountLoginPreview" => { "MobileAccountLoginPreview" => {
run_test_app(EguiPreviewSetup::new, MobileAccountLoginPreview::new, true) run_test_app(EguiPreviewSetup::new, MobileAccountLoginPreview::new, true)
} }