Add Toolbar component

This commit is contained in:
Marshall Bowers 2023-10-07 11:21:09 -04:00
parent b118e60160
commit 63e834ce73
5 changed files with 133 additions and 0 deletions

View file

@ -6,4 +6,5 @@ pub mod project_panel;
pub mod tab;
pub mod tab_bar;
pub mod terminal;
pub mod toolbar;
pub mod workspace;

View file

@ -0,0 +1,79 @@
use std::marker::PhantomData;
use std::path::PathBuf;
use std::str::FromStr;
use std::sync::Arc;
use ui::prelude::*;
use ui::{theme, Breadcrumb, HighlightColor, HighlightedText, Icon, IconButton, Symbol, Toolbar};
use crate::story::Story;
#[derive(Element)]
pub struct ToolbarStory<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
}
impl<S: 'static + Send + Sync + Clone> ToolbarStory<S> {
pub fn new() -> Self {
Self {
state_type: PhantomData,
}
}
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<State = S> {
let theme = theme(cx);
struct LeftItemsPayload {
pub theme: Arc<Theme>,
}
Story::container(cx)
.child(Story::title_for::<_, Toolbar<S>>(cx))
.child(Story::label(cx, "Default"))
.child(Toolbar::new(
|_, payload| {
let payload = payload.downcast_ref::<LeftItemsPayload>().unwrap();
let theme = payload.theme.clone();
vec![Breadcrumb::new(
PathBuf::from_str("crates/ui/src/components/toolbar.rs").unwrap(),
vec![
Symbol(vec![
HighlightedText {
text: "impl ".to_string(),
color: HighlightColor::Keyword.hsla(&theme),
},
HighlightedText {
text: "ToolbarStory".to_string(),
color: HighlightColor::Function.hsla(&theme),
},
]),
Symbol(vec![
HighlightedText {
text: "fn ".to_string(),
color: HighlightColor::Keyword.hsla(&theme),
},
HighlightedText {
text: "render".to_string(),
color: HighlightColor::Function.hsla(&theme),
},
]),
],
)
.into_any()]
},
Box::new(LeftItemsPayload {
theme: theme.clone(),
}),
|_, _| {
vec![
IconButton::new(Icon::InlayHint).into_any(),
IconButton::new(Icon::MagnifyingGlass).into_any(),
IconButton::new(Icon::MagicWand).into_any(),
]
},
Box::new(()),
))
}
}

View file

@ -42,6 +42,7 @@ pub enum ComponentStory {
Tab,
TabBar,
Terminal,
Toolbar,
Workspace,
}
@ -60,6 +61,7 @@ impl ComponentStory {
Self::Tab => components::tab::TabStory::new().into_any(),
Self::TabBar => components::tab_bar::TabBarStory::new().into_any(),
Self::Terminal => components::terminal::TerminalStory::new().into_any(),
Self::Toolbar => components::toolbar::ToolbarStory::new().into_any(),
Self::Workspace => components::workspace::WorkspaceStory::new().into_any(),
}
}