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