Add tooltips for sidebar buttons
This commit is contained in:
parent
0c8d33bd2d
commit
f2a48c6b02
2 changed files with 43 additions and 26 deletions
|
@ -68,6 +68,7 @@ pub enum Side {
|
||||||
|
|
||||||
struct Item {
|
struct Item {
|
||||||
icon_path: &'static str,
|
icon_path: &'static str,
|
||||||
|
tooltip: String,
|
||||||
view: Rc<dyn SidebarItemHandle>,
|
view: Rc<dyn SidebarItemHandle>,
|
||||||
_subscriptions: [Subscription; 2],
|
_subscriptions: [Subscription; 2],
|
||||||
}
|
}
|
||||||
|
@ -104,6 +105,7 @@ impl Sidebar {
|
||||||
pub fn add_item<T: SidebarItem>(
|
pub fn add_item<T: SidebarItem>(
|
||||||
&mut self,
|
&mut self,
|
||||||
icon_path: &'static str,
|
icon_path: &'static str,
|
||||||
|
tooltip: String,
|
||||||
view: ViewHandle<T>,
|
view: ViewHandle<T>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) {
|
) {
|
||||||
|
@ -123,6 +125,7 @@ impl Sidebar {
|
||||||
];
|
];
|
||||||
self.items.push(Item {
|
self.items.push(Item {
|
||||||
icon_path,
|
icon_path,
|
||||||
|
tooltip,
|
||||||
view: Rc::new(view),
|
view: Rc::new(view),
|
||||||
_subscriptions: subscriptions,
|
_subscriptions: subscriptions,
|
||||||
});
|
});
|
||||||
|
@ -239,12 +242,9 @@ impl View for SidebarButtons {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
|
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||||
let theme = &cx
|
let theme = &cx.global::<Settings>().theme;
|
||||||
.global::<Settings>()
|
let tooltip_style = theme.tooltip.clone();
|
||||||
.theme
|
let theme = &theme.workspace.status_bar.sidebar_buttons;
|
||||||
.workspace
|
|
||||||
.status_bar
|
|
||||||
.sidebar_buttons;
|
|
||||||
let sidebar = self.sidebar.read(cx);
|
let sidebar = self.sidebar.read(cx);
|
||||||
let item_style = theme.item;
|
let item_style = theme.item;
|
||||||
let badge_style = theme.badge;
|
let badge_style = theme.badge;
|
||||||
|
@ -257,15 +257,19 @@ impl View for SidebarButtons {
|
||||||
let items = sidebar
|
let items = sidebar
|
||||||
.items
|
.items
|
||||||
.iter()
|
.iter()
|
||||||
.map(|item| (item.icon_path, item.view.clone()))
|
.map(|item| (item.icon_path, item.tooltip.clone(), item.view.clone()))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
Flex::row()
|
Flex::row()
|
||||||
.with_children(
|
.with_children(items.into_iter().enumerate().map(
|
||||||
items
|
|(ix, (icon_path, tooltip, item_view))| {
|
||||||
.into_iter()
|
let action = ToggleSidebarItem {
|
||||||
.enumerate()
|
side,
|
||||||
.map(|(ix, (icon_path, item_view))| {
|
item_index: ix,
|
||||||
MouseEventHandler::new::<Self, _, _>(ix, cx, move |state, cx| {
|
};
|
||||||
|
MouseEventHandler::new::<Self, _, _>(ix, cx, {
|
||||||
|
let action = action.clone();
|
||||||
|
let tooltip_style = tooltip_style.clone();
|
||||||
|
move |state, cx| {
|
||||||
let is_active = Some(ix) == active_ix;
|
let is_active = Some(ix) == active_ix;
|
||||||
let style = item_style.style_for(state, is_active);
|
let style = item_style.style_for(state, is_active);
|
||||||
Stack::new()
|
Stack::new()
|
||||||
|
@ -291,18 +295,21 @@ impl View for SidebarButtons {
|
||||||
.with_height(style.icon_size)
|
.with_height(style.icon_size)
|
||||||
.contained()
|
.contained()
|
||||||
.with_style(style.container)
|
.with_style(style.container)
|
||||||
|
.with_tooltip(
|
||||||
|
ix,
|
||||||
|
tooltip,
|
||||||
|
Some(Box::new(action.clone())),
|
||||||
|
tooltip_style.clone(),
|
||||||
|
cx,
|
||||||
|
)
|
||||||
.boxed()
|
.boxed()
|
||||||
})
|
}
|
||||||
.with_cursor_style(CursorStyle::PointingHand)
|
})
|
||||||
.on_click(move |_, _, cx| {
|
.with_cursor_style(CursorStyle::PointingHand)
|
||||||
cx.dispatch_action(ToggleSidebarItem {
|
.on_click(move |_, _, cx| cx.dispatch_action(action.clone()))
|
||||||
side,
|
.boxed()
|
||||||
item_index: ix,
|
},
|
||||||
})
|
))
|
||||||
})
|
|
||||||
.boxed()
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.contained()
|
.contained()
|
||||||
.with_style(group_style)
|
.with_style(group_style)
|
||||||
.boxed()
|
.boxed()
|
||||||
|
|
|
@ -191,10 +191,20 @@ pub fn initialize_workspace(
|
||||||
});
|
});
|
||||||
|
|
||||||
workspace.left_sidebar().update(cx, |sidebar, cx| {
|
workspace.left_sidebar().update(cx, |sidebar, cx| {
|
||||||
sidebar.add_item("icons/folder-tree-solid-14.svg", project_panel.into(), cx)
|
sidebar.add_item(
|
||||||
|
"icons/folder-tree-solid-14.svg",
|
||||||
|
"Project Panel".to_string(),
|
||||||
|
project_panel.into(),
|
||||||
|
cx,
|
||||||
|
)
|
||||||
});
|
});
|
||||||
workspace.right_sidebar().update(cx, |sidebar, cx| {
|
workspace.right_sidebar().update(cx, |sidebar, cx| {
|
||||||
sidebar.add_item("icons/contacts-solid-14.svg", contact_panel.into(), cx)
|
sidebar.add_item(
|
||||||
|
"icons/contacts-solid-14.svg",
|
||||||
|
"Contacts Panel".to_string(),
|
||||||
|
contact_panel.into(),
|
||||||
|
cx,
|
||||||
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let diagnostic_summary =
|
let diagnostic_summary =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue