lib.rs (1880B)
1 pub mod anim; 2 pub mod app_images; 3 pub mod colors; 4 pub mod constants; 5 pub mod context_menu; 6 pub mod icons; 7 pub mod images; 8 pub mod media; 9 pub mod mention; 10 pub mod note; 11 pub mod profile; 12 mod username; 13 pub mod widgets; 14 15 pub use anim::{AnimationHelper, PulseAlpha}; 16 pub use mention::Mention; 17 pub use note::{NoteContents, NoteOptions, NoteView}; 18 pub use profile::{ProfilePic, ProfilePreview}; 19 pub use username::Username; 20 21 use egui::{Label, Margin, RichText}; 22 23 /// This is kind of like the Widget trait but is meant for larger top-level 24 /// views that are typically stateful. 25 /// 26 /// The Widget trait forces us to add mutable 27 /// implementations at the type level, which screws us when generating Previews 28 /// for a Widget. I would have just Widget instead of making this Trait otherwise. 29 /// 30 /// There is some precendent for this, it looks like there's a similar trait 31 /// in the egui demo library. 32 pub trait View { 33 fn ui(&mut self, ui: &mut egui::Ui); 34 } 35 36 pub fn padding<R>( 37 amount: impl Into<Margin>, 38 ui: &mut egui::Ui, 39 add_contents: impl FnOnce(&mut egui::Ui) -> R, 40 ) -> egui::InnerResponse<R> { 41 egui::Frame::new() 42 .inner_margin(amount) 43 .show(ui, add_contents) 44 } 45 46 pub fn hline(ui: &egui::Ui) { 47 hline_with_width(ui, ui.available_rect_before_wrap().x_range()); 48 } 49 50 pub fn hline_with_width(ui: &egui::Ui, range: egui::Rangef) { 51 // pixel perfect horizontal line 52 let rect = ui.available_rect_before_wrap(); 53 #[allow(deprecated)] 54 let resize_y = ui.painter().round_to_pixel(rect.top()) - 0.5; 55 let stroke = ui.style().visuals.widgets.noninteractive.bg_stroke; 56 ui.painter().hline(range, resize_y, stroke); 57 } 58 59 pub fn secondary_label(ui: &mut egui::Ui, s: impl Into<String>) { 60 let color = ui.style().visuals.noninteractive().fg_stroke.color; 61 ui.add(Label::new(RichText::new(s).size(10.0).color(color)).selectable(false)); 62 }