wip
Some checks failed
Rust / build (ubuntu-latest, stable) (push) Failing after 1m59s

This commit is contained in:
2026-02-14 16:43:28 +07:00
parent e327178161
commit a1aaa30a48
8 changed files with 153 additions and 230 deletions

View File

@@ -51,6 +51,7 @@ pub enum IconName {
PanelRightOpen,
PanelBottom,
PanelBottomOpen,
PaperPlaneFill,
Warning,
WindowClose,
WindowMaximize,
@@ -106,6 +107,7 @@ impl IconName {
Self::PanelRightOpen => "icons/panel-right-open.svg",
Self::PanelBottom => "icons/panel-bottom.svg",
Self::PanelBottomOpen => "icons/panel-bottom-open.svg",
Self::PaperPlaneFill => "icons/paper-plane-fill.svg",
Self::Warning => "icons/warning.svg",
Self::WindowClose => "icons/window-close.svg",
Self::WindowMaximize => "icons/window-maximize.svg",

View File

@@ -2,11 +2,11 @@ use std::rc::Rc;
use gpui::prelude::FluentBuilder;
use gpui::{
anchored, canvas, div, px, rems, Action, AnyElement, App, AppContext, Bounds, Context, Corner,
DismissEvent, Edges, Entity, EventEmitter, FocusHandle, Focusable, Half, InteractiveElement,
IntoElement, KeyBinding, MouseDownEvent, OwnedMenuItem, ParentElement, Pixels, Render,
ScrollHandle, SharedString, StatefulInteractiveElement, Styled, Subscription, WeakEntity,
Window,
anchored, canvas, div, px, rems, Action, AnyElement, App, AppContext, Axis, Bounds, Context,
Corner, DismissEvent, Edges, Entity, EventEmitter, FocusHandle, Focusable, Half,
InteractiveElement, IntoElement, KeyBinding, MouseDownEvent, OwnedMenuItem, ParentElement,
Pixels, Render, ScrollHandle, SharedString, StatefulInteractiveElement, Styled, Subscription,
WeakEntity, Window,
};
use theme::ActiveTheme;
@@ -119,6 +119,8 @@ pub struct PopupMenu {
pub(crate) menu_items: Vec<PopupMenuItem>,
/// The focus handle of Entity to handle actions.
pub(crate) action_context: Option<FocusHandle>,
axis_items: Axis,
has_icon: bool,
selected_index: Option<usize>,
min_width: Option<Pixels>,
@@ -126,13 +128,14 @@ pub struct PopupMenu {
max_height: Option<Pixels>,
bounds: Bounds<Pixels>,
size: Size,
/// The parent menu of this menu, if this is a submenu
parent_menu: Option<WeakEntity<Self>>,
scrollable: bool,
external_link_icon: bool,
scroll_handle: ScrollHandle,
scroll_state: ScrollbarState,
/// The parent menu of this menu, if this is a submenu
parent_menu: Option<WeakEntity<Self>>,
// This will update on render
submenu_anchor: (Corner, Pixels),
@@ -144,6 +147,7 @@ impl PopupMenu {
Self {
focus_handle: cx.focus_handle(),
action_context: None,
axis_items: Axis::Vertical,
parent_menu: None,
menu_items: Vec::new(),
selected_index: None,
@@ -180,6 +184,12 @@ impl PopupMenu {
self
}
/// Set the axis of the popup menu, default is vertical
pub fn axis(mut self, axis: Axis) -> Self {
self.axis_items = axis;
self
}
/// Set min width of the popup menu, default is 120px
pub fn min_w(mut self, width: impl Into<Pixels>) -> Self {
self.min_width = Some(width.into());
@@ -1131,8 +1141,15 @@ impl Render for PopupMenu {
.text_color(cx.theme().text)
.relative()
.child(
v_flex()
div()
.id("items")
.map(|this| {
if self.axis_items == Axis::Vertical {
this.flex().flex_col()
} else {
this.flex().flex_row().items_center()
}
})
.p_1()
.gap_y_0p5()
.min_w(rems(8.))