notedeck

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

messages.rs (4838B)


      1 use egui::{Frame, Layout, Margin};
      2 use egui_extras::{Size, StripBuilder};
      3 use enostr::Pubkey;
      4 use nostrdb::Ndb;
      5 use notedeck::{
      6     ui::is_narrow, ContactState, Images, Localization, MediaJobSender, Router, Settings,
      7 };
      8 
      9 use crate::{
     10     cache::{ConversationCache, ConversationStates},
     11     nav::{MessagesUiResponse, Route},
     12     ui::{conversation_header_impl, convo::conversation_ui, nav::render_nav},
     13 };
     14 
     15 #[allow(clippy::too_many_arguments)]
     16 pub fn desktop_messages_ui(
     17     cache: &ConversationCache,
     18     states: &mut ConversationStates,
     19     jobs: &MediaJobSender,
     20     ndb: &Ndb,
     21     selected_pubkey: &Pubkey,
     22     ui: &mut egui::Ui,
     23     img_cache: &mut Images,
     24     router: &Router<Route>,
     25     settings: &Settings,
     26     contacts: &ContactState,
     27     i18n: &mut Localization,
     28 ) -> MessagesUiResponse {
     29     let mut nav_resp = None;
     30     let mut convo_resp = None;
     31 
     32     StripBuilder::new(ui)
     33         .size(Size::exact(300.0))
     34         .size(Size::remainder())
     35         .horizontal(|mut strip| {
     36             strip.cell(|ui| {
     37                 nav_resp = Some(render_nav(
     38                     ui,
     39                     router,
     40                     settings,
     41                     cache,
     42                     states,
     43                     jobs,
     44                     ndb,
     45                     selected_pubkey,
     46                     img_cache,
     47                     contacts,
     48                     i18n,
     49                 ));
     50             });
     51 
     52             strip.strip(|strip| {
     53                 strip
     54                     .size(Size::exact(64.0))
     55                     .size(Size::remainder())
     56                     .vertical(|mut strip| {
     57                         strip.cell(|ui| {
     58                             ui.with_layout(Layout::left_to_right(egui::Align::Center), |ui| {
     59                                 Frame::new().inner_margin(Margin::symmetric(16, 4)).show(
     60                                     ui,
     61                                     |ui| {
     62                                         conversation_header_impl(
     63                                             ui,
     64                                             i18n,
     65                                             cache,
     66                                             selected_pubkey,
     67                                             ndb,
     68                                             jobs,
     69                                             img_cache,
     70                                         );
     71                                     },
     72                                 );
     73                             });
     74                         });
     75                         strip.cell(|ui| {
     76                             convo_resp = conversation_ui(
     77                                 cache,
     78                                 states,
     79                                 jobs,
     80                                 ndb,
     81                                 ui,
     82                                 img_cache,
     83                                 i18n,
     84                                 selected_pubkey,
     85                             );
     86                         });
     87                     });
     88             });
     89         });
     90 
     91     MessagesUiResponse {
     92         nav_response: nav_resp,
     93         conversation_panel_response: convo_resp,
     94     }
     95 }
     96 
     97 #[allow(clippy::too_many_arguments)]
     98 pub fn narrow_messages_ui(
     99     cache: &ConversationCache,
    100     states: &mut ConversationStates,
    101     jobs: &MediaJobSender,
    102     ndb: &Ndb,
    103     selected_pubkey: &Pubkey,
    104     ui: &mut egui::Ui,
    105     img_cache: &mut Images,
    106     router: &Router<Route>,
    107     settings: &Settings,
    108     contacts: &ContactState,
    109     i18n: &mut Localization,
    110 ) -> MessagesUiResponse {
    111     let nav = render_nav(
    112         ui,
    113         router,
    114         settings,
    115         cache,
    116         states,
    117         jobs,
    118         ndb,
    119         selected_pubkey,
    120         img_cache,
    121         contacts,
    122         i18n,
    123     );
    124 
    125     MessagesUiResponse {
    126         nav_response: Some(nav),
    127         conversation_panel_response: None,
    128     }
    129 }
    130 
    131 #[allow(clippy::too_many_arguments)]
    132 pub fn messages_ui(
    133     cache: &ConversationCache,
    134     states: &mut ConversationStates,
    135     jobs: &MediaJobSender,
    136     ndb: &Ndb,
    137     selected_pubkey: &Pubkey,
    138     ui: &mut egui::Ui,
    139     img_cache: &mut Images,
    140     router: &Router<Route>,
    141     settings: &Settings,
    142     contacts: &ContactState,
    143     i18n: &mut Localization,
    144 ) -> MessagesUiResponse {
    145     if is_narrow(ui.ctx()) {
    146         narrow_messages_ui(
    147             cache,
    148             states,
    149             jobs,
    150             ndb,
    151             selected_pubkey,
    152             ui,
    153             img_cache,
    154             router,
    155             settings,
    156             contacts,
    157             i18n,
    158         )
    159     } else {
    160         desktop_messages_ui(
    161             cache,
    162             states,
    163             jobs,
    164             ndb,
    165             selected_pubkey,
    166             ui,
    167             img_cache,
    168             router,
    169             settings,
    170             contacts,
    171             i18n,
    172         )
    173     }
    174 }