notedeck

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

toolbar.rs (2008B)


      1 use egui::{Color32, Layout};
      2 use notedeck_ui::icons::{home_button, notifications_button};
      3 
      4 use crate::{toolbar::ToolbarAction, ui::side_panel::search_button_impl, Damus};
      5 
      6 #[profiling::function]
      7 pub fn toolbar(ui: &mut egui::Ui, unseen_notification: bool) -> Option<ToolbarAction> {
      8     use egui_tabs::{TabColor, Tabs};
      9 
     10     let rect = ui.available_rect_before_wrap();
     11     ui.painter().hline(
     12         rect.x_range(),
     13         rect.top(),
     14         ui.visuals().widgets.noninteractive.bg_stroke,
     15     );
     16 
     17     if !ui.visuals().dark_mode {
     18         ui.painter().rect(
     19             rect,
     20             0,
     21             notedeck_ui::colors::ALMOST_WHITE,
     22             egui::Stroke::new(0.0, Color32::TRANSPARENT),
     23             egui::StrokeKind::Inside,
     24         );
     25     }
     26 
     27     let rs = Tabs::new(3)
     28         .selected(Damus::initially_selected_toolbar_index())
     29         .hover_bg(TabColor::none())
     30         .selected_fg(TabColor::none())
     31         .selected_bg(TabColor::none())
     32         .height(Damus::toolbar_height())
     33         .layout(Layout::centered_and_justified(egui::Direction::TopDown))
     34         .show(ui, |ui, state| {
     35             let index = state.index();
     36 
     37             let mut action: Option<ToolbarAction> = None;
     38 
     39             let btn_size: f32 = 20.0;
     40             if index == 0 {
     41                 if home_button(ui, btn_size).clicked() {
     42                     action = Some(ToolbarAction::Home);
     43                 }
     44             } else if index == 1
     45                 && ui
     46                     .add(search_button_impl(ui.visuals().text_color(), 2.0))
     47                     .clicked()
     48             {
     49                 action = Some(ToolbarAction::Search)
     50             } else if index == 2
     51                 && notifications_button(ui, btn_size, unseen_notification).clicked()
     52             {
     53                 action = Some(ToolbarAction::Notifications);
     54             }
     55 
     56             action
     57         })
     58         .inner();
     59 
     60     for maybe_r in rs {
     61         if maybe_r.inner.is_some() {
     62             return maybe_r.inner;
     63         }
     64     }
     65 
     66     None
     67 }