Start on context_menu crate

This commit is contained in:
Nathan Sobo 2022-05-24 19:59:43 -06:00 committed by Antonio Scandurra
parent b428d0de38
commit dcee8439b6
3 changed files with 48 additions and 0 deletions

8
Cargo.lock generated
View File

@ -974,6 +974,14 @@ dependencies = [
"workspace",
]
[[package]]
name = "context_menu"
version = "0.1.0"
dependencies = [
"gpui",
"theme",
]
[[package]]
name = "core-foundation"
version = "0.9.3"

View File

@ -0,0 +1,12 @@
[package]
name = "context_menu"
version = "0.1.0"
edition = "2021"
[lib]
path = "src/context_menu.rs"
doctest = false
[dependencies]
gpui = { path = "../gpui" }
theme = { path = "../theme" }

View File

@ -0,0 +1,28 @@
use gpui::{Entity, View};
enum ContextMenuItem {
Item {
label: String,
action: Box<dyn Action>,
},
Separator,
}
pub struct ContextMenu {
position: Vector2F,
items: Vec<ContextMenuItem>,
}
impl Entity for ContextMenu {
type Event = ();
}
impl View for ContextMenu {
fn ui_name() -> &'static str {
"ContextMenu"
}
fn render(&mut self, cx: &mut gpui::RenderContext<'_, Self>) -> gpui::ElementBox {
Overlay::new().with_abs_position(self.position).boxed()
}
}