search_bar.rs

 1use gpui::{Action, IntoElement};
 2use ui::{prelude::*, Tooltip};
 3use ui::{Button, IconButton};
 4
 5use crate::mode::SearchMode;
 6
 7pub(super) fn render_nav_button(
 8    icon: ui::Icon,
 9    active: bool,
10    tooltip: &'static str,
11    action: &'static dyn Action,
12) -> impl IntoElement {
13    IconButton::new(
14        SharedString::from(format!("search-nav-button-{}", action.name())),
15        icon,
16    )
17    .on_click(|_, cx| cx.dispatch_action(action.boxed_clone()))
18    .tooltip(move |cx| Tooltip::for_action(tooltip, action, cx))
19    .disabled(!active)
20}
21
22pub(crate) fn render_search_mode_button(mode: SearchMode, is_active: bool) -> Button {
23    Button::new(mode.label(), mode.label())
24        .selected(is_active)
25        .on_click({
26            let action = mode.action();
27            move |_, cx| {
28                cx.dispatch_action(action.boxed_clone());
29            }
30        })
31        .tooltip({
32            let action = mode.action();
33            let tooltip_text = mode.tooltip();
34            move |cx| Tooltip::for_action(tooltip_text.clone(), &*action, cx)
35        })
36}