Mainline GPUI2 UI work (#3062)
This PR mainlines the current state of new GPUI2-based UI from the `gpui2-ui` branch. Release Notes: - N/A --------- Co-authored-by: Nate Butler <iamnbutler@gmail.com> Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com> Co-authored-by: Marshall Bowers <1486634+maxdeviant@users.noreply.github.com> Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Co-authored-by: Nate <nate@zed.dev> Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
parent
e7ee8a95f6
commit
f26ca0866c
85 changed files with 4658 additions and 1623 deletions
65
crates/ui/src/components/context_menu.rs
Normal file
65
crates/ui/src/components/context_menu.rs
Normal file
|
@ -0,0 +1,65 @@
|
|||
use crate::prelude::*;
|
||||
use crate::theme::theme;
|
||||
use crate::{
|
||||
v_stack, Label, List, ListEntry, ListItem, ListItemVariant, ListSeparator, ListSubHeader,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum ContextMenuItem {
|
||||
Header(&'static str),
|
||||
Entry(Label),
|
||||
Separator,
|
||||
}
|
||||
|
||||
impl ContextMenuItem {
|
||||
fn to_list_item(self) -> ListItem {
|
||||
match self {
|
||||
ContextMenuItem::Header(label) => ListSubHeader::new(label).into(),
|
||||
ContextMenuItem::Entry(label) => {
|
||||
ListEntry::new(label).variant(ListItemVariant::Inset).into()
|
||||
}
|
||||
ContextMenuItem::Separator => ListSeparator::new().into(),
|
||||
}
|
||||
}
|
||||
pub fn header(label: &'static str) -> Self {
|
||||
Self::Header(label)
|
||||
}
|
||||
pub fn separator() -> Self {
|
||||
Self::Separator
|
||||
}
|
||||
pub fn entry(label: Label) -> Self {
|
||||
Self::Entry(label)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Element)]
|
||||
pub struct ContextMenu {
|
||||
items: Vec<ContextMenuItem>,
|
||||
}
|
||||
|
||||
impl ContextMenu {
|
||||
pub fn new(items: impl IntoIterator<Item = ContextMenuItem>) -> Self {
|
||||
Self {
|
||||
items: items.into_iter().collect(),
|
||||
}
|
||||
}
|
||||
fn render<V: 'static>(&mut self, view: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
|
||||
let theme = theme(cx);
|
||||
v_stack()
|
||||
.flex()
|
||||
.fill(theme.lowest.base.default.background)
|
||||
.border()
|
||||
.border_color(theme.lowest.base.default.border)
|
||||
.child(
|
||||
List::new(
|
||||
self.items
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(ContextMenuItem::to_list_item)
|
||||
.collect(),
|
||||
)
|
||||
.set_toggle(ToggleState::Toggled),
|
||||
)
|
||||
//div().p_1().children(self.items.clone())
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue