notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

mod.rs (2327B)


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