mod.rs (2344B)
1 pub mod account_login_view; 2 pub mod account_management; 3 pub mod add_column; 4 pub mod anim; 5 pub mod mention; 6 pub mod note; 7 pub mod preview; 8 pub mod profile; 9 pub mod relay; 10 pub mod side_panel; 11 pub mod support; 12 pub mod thread; 13 pub mod timeline; 14 pub mod username; 15 16 pub use account_management::AccountsView; 17 pub use mention::Mention; 18 pub use note::{NoteResponse, NoteView, PostReplyView, PostView}; 19 pub use preview::{Preview, PreviewApp, PreviewConfig}; 20 pub use profile::{ProfilePic, ProfilePreview}; 21 pub use relay::RelayView; 22 pub use side_panel::{DesktopSidePanel, SidePanelAction}; 23 pub use thread::ThreadView; 24 pub use timeline::TimelineView; 25 pub use username::Username; 26 27 use egui::Margin; 28 29 /// This is kind of like the Widget trait but is meant for larger top-level 30 /// views that are typically stateful. 31 /// 32 /// The Widget trait forces us to add mutable 33 /// implementations at the type level, which screws us when generating Previews 34 /// for a Widget. I would have just Widget instead of making this Trait otherwise. 35 /// 36 /// There is some precendent for this, it looks like there's a similar trait 37 /// in the egui demo library. 38 pub trait View { 39 fn ui(&mut self, ui: &mut egui::Ui); 40 } 41 42 pub fn padding<R>( 43 amount: impl Into<Margin>, 44 ui: &mut egui::Ui, 45 add_contents: impl FnOnce(&mut egui::Ui) -> R, 46 ) -> egui::InnerResponse<R> { 47 egui::Frame::none() 48 .inner_margin(amount) 49 .show(ui, add_contents) 50 } 51 52 pub fn hline(ui: &egui::Ui) { 53 // pixel perfect horizontal line 54 let rect = ui.available_rect_before_wrap(); 55 let resize_y = ui.painter().round_to_pixel(rect.top()) - 0.5; 56 let stroke = ui.style().visuals.widgets.noninteractive.bg_stroke; 57 ui.painter().hline(rect.x_range(), resize_y, stroke); 58 } 59 60 #[inline] 61 #[allow(unreachable_code)] 62 pub fn is_compiled_as_mobile() -> bool { 63 #[cfg(any(target_os = "android", target_os = "ios"))] 64 { 65 true 66 } 67 68 #[cfg(not(any(target_os = "android", target_os = "ios")))] 69 { 70 false 71 } 72 } 73 74 /// Determine if the screen is narrow. This is useful for detecting mobile 75 /// contexts, but with the nuance that we may also have a wide android tablet. 76 pub fn is_narrow(ctx: &egui::Context) -> bool { 77 let screen_size = ctx.input(|c| c.screen_rect().size()); 78 screen_size.x < 550.0 79 } 80 81 pub fn is_oled() -> bool { 82 is_compiled_as_mobile() 83 }