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