chore: bump gpui-pre to 0.3.8 and clean up unused code
This commit is contained in:
@@ -391,18 +391,6 @@ impl Avatar {
|
||||
self.seed = Some(seed.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Applies a grayscale filter to the avatar image.
|
||||
pub fn grayscale(mut self, grayscale: bool) -> Self {
|
||||
self.grayscale = grayscale;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the border color of the avatar.
|
||||
pub fn border_color(mut self, color: impl Into<Hsla>) -> Self {
|
||||
self.border_color = Some(color.into());
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Sizable for Avatar {
|
||||
|
||||
@@ -208,12 +208,6 @@ impl Button {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set true to show the indicator.
|
||||
pub fn indicator(mut self) -> Self {
|
||||
self.indicator = true;
|
||||
self
|
||||
}
|
||||
|
||||
/// Add click handler.
|
||||
pub fn on_click(
|
||||
mut self,
|
||||
@@ -223,20 +217,6 @@ impl Button {
|
||||
self
|
||||
}
|
||||
|
||||
/// Add hover handler, the bool parameter indicates whether the mouse is hovering.
|
||||
pub fn on_hover(mut self, handler: impl Fn(&bool, &mut Window, &mut App) + 'static) -> Self {
|
||||
self.on_hover = Some(Rc::new(handler));
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the tab index of the button, it will be used to focus the button by tab key.
|
||||
///
|
||||
/// Default is 0.
|
||||
pub fn tab_index(mut self, tab_index: isize) -> Self {
|
||||
self.tab_index = tab_index;
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the tab stop of the button, if true, the button will be focusable by tab key.
|
||||
///
|
||||
/// Default is true.
|
||||
|
||||
@@ -58,12 +58,6 @@ impl DialogButtonProps {
|
||||
self.cancel_text = Some(cancel_text.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the variant of the Cancel button. Default is `ButtonVariant::default()`.
|
||||
pub fn cancel_variant(mut self, cancel_variant: ButtonVariant) -> Self {
|
||||
self.cancel_variant = cancel_variant;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(IntoElement)]
|
||||
@@ -145,23 +139,12 @@ impl Dialog {
|
||||
}
|
||||
|
||||
/// Set to use confirm dialog, with OK and Cancel buttons.
|
||||
///
|
||||
/// See also [`Self::alert`]
|
||||
pub fn confirm(self) -> Self {
|
||||
self.footer(|ok, cancel, window, cx| vec![cancel(window, cx), ok(window, cx)])
|
||||
.overlay_closable(false)
|
||||
.show_close(false)
|
||||
}
|
||||
|
||||
/// Set to as a alter dialog, with OK button.
|
||||
///
|
||||
/// See also [`Self::confirm`]
|
||||
pub fn alert(self) -> Self {
|
||||
self.footer(|ok, _, window, cx| vec![ok(window, cx)])
|
||||
.overlay_closable(false)
|
||||
.show_close(false)
|
||||
}
|
||||
|
||||
/// Set the button props of the dialog.
|
||||
pub fn button_props(mut self, button_props: DialogButtonProps) -> Self {
|
||||
self.button_props = button_props;
|
||||
@@ -207,30 +190,12 @@ impl Dialog {
|
||||
self
|
||||
}
|
||||
|
||||
/// Shift the dialog down from the window centre, defaults to `None`.
|
||||
pub fn margin_top(mut self, margin_top: Pixels) -> Self {
|
||||
self.margin_top = Some(margin_top);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the width of the dialog, defaults to 480px.
|
||||
pub fn width(mut self, width: Pixels) -> Self {
|
||||
self.width = width;
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the maximum width of the dialog, defaults to `None`.
|
||||
pub fn max_w(mut self, max_width: Pixels) -> Self {
|
||||
self.max_width = Some(max_width);
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the overlay of the dialog, defaults to `true`.
|
||||
pub fn overlay(mut self, overlay: bool) -> Self {
|
||||
self.overlay = overlay;
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the overlay closable of the dialog, defaults to `true`.
|
||||
///
|
||||
/// When the overlay is clicked, the dialog will be closed.
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use gpui::prelude::FluentBuilder;
|
||||
use gpui::{
|
||||
div, relative, AnyElement, App, ElementId, InteractiveElement as _, IntoElement, ParentElement,
|
||||
RenderOnce, StyleRefinement, Styled, Window,
|
||||
AnyElement, App, ElementId, InteractiveElement as _, IntoElement, ParentElement, RenderOnce,
|
||||
StyleRefinement, Styled, Window, div, relative,
|
||||
};
|
||||
use smallvec::SmallVec;
|
||||
use theme::ActiveTheme;
|
||||
|
||||
use crate::{v_flex, StyledExt as _};
|
||||
use crate::{StyledExt as _, v_flex};
|
||||
|
||||
/// The variant of the GroupBox.
|
||||
#[derive(Debug, Clone, Default, Copy, PartialEq, Eq, Hash)]
|
||||
@@ -37,27 +35,6 @@ pub trait GroupBoxVariants: Sized {
|
||||
}
|
||||
}
|
||||
|
||||
impl GroupBoxVariant {
|
||||
/// Convert the GroupBoxVariant to a string.
|
||||
pub const fn as_str(&self) -> &str {
|
||||
match self {
|
||||
GroupBoxVariant::Normal => "normal",
|
||||
GroupBoxVariant::Fill => "fill",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for GroupBoxVariant {
|
||||
type Err = ();
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s.to_lowercase().as_str() {
|
||||
"fill" => Ok(GroupBoxVariant::Fill),
|
||||
_ => Ok(GroupBoxVariant::Normal),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// GroupBox is a styled container element that with
|
||||
/// an optional title to groups related content together.
|
||||
#[derive(IntoElement)]
|
||||
@@ -98,20 +75,6 @@ impl GroupBox {
|
||||
self.title = Some(title.into_any_element());
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the style of the title of the group box to override the default style, default is None.
|
||||
#[must_use]
|
||||
pub fn title_style(mut self, style: StyleRefinement) -> Self {
|
||||
self.title_style = style;
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the style of the content of the group box to override the default style, default is None.
|
||||
#[must_use]
|
||||
pub fn content_style(mut self, style: StyleRefinement) -> Self {
|
||||
self.content_style = style;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for GroupBox {
|
||||
|
||||
+5
-30
@@ -1,19 +1,14 @@
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AnyElement, App, AppContext, Context, Entity, Hsla, IntoElement, Radians, Render, RenderOnce,
|
||||
SharedString, StyleRefinement, Styled, Svg, Transformation, Window, svg,
|
||||
AnyElement, App, Context, Hsla, IntoElement, Radians, Render, RenderOnce, SharedString,
|
||||
StyleRefinement, Styled, Svg, Transformation, Window, svg,
|
||||
};
|
||||
use theme::ActiveTheme;
|
||||
|
||||
use crate::{Sizable, Size};
|
||||
|
||||
pub trait IconNamed {
|
||||
/// Returns the embedded path of the icon.
|
||||
fn path(self) -> SharedString;
|
||||
}
|
||||
|
||||
impl<T: IconNamed> From<T> for Icon {
|
||||
fn from(value: T) -> Self {
|
||||
impl From<IconName> for Icon {
|
||||
fn from(value: IconName) -> Self {
|
||||
Icon::build(value)
|
||||
}
|
||||
}
|
||||
@@ -95,13 +90,6 @@ pub enum IconName {
|
||||
}
|
||||
|
||||
impl IconName {
|
||||
/// Return the icon as a Entity<Icon>
|
||||
pub fn view(self, cx: &mut App) -> Entity<Icon> {
|
||||
Icon::build(self).view(cx)
|
||||
}
|
||||
}
|
||||
|
||||
impl IconNamed for IconName {
|
||||
fn path(self) -> SharedString {
|
||||
match self {
|
||||
Self::ArrowLeft => "icons/arrow-left.svg",
|
||||
@@ -232,7 +220,7 @@ impl Icon {
|
||||
icon.into()
|
||||
}
|
||||
|
||||
fn build(name: impl IconNamed) -> Self {
|
||||
fn build(name: IconName) -> Self {
|
||||
Self::default().path(name.path())
|
||||
}
|
||||
|
||||
@@ -244,11 +232,6 @@ impl Icon {
|
||||
self
|
||||
}
|
||||
|
||||
/// Create a new view for the icon
|
||||
pub fn view(self, cx: &mut App) -> Entity<Icon> {
|
||||
cx.new(|_| self)
|
||||
}
|
||||
|
||||
pub fn transform(mut self, transformation: gpui::Transformation) -> Self {
|
||||
self.base = self.base.with_transformation(transformation);
|
||||
self
|
||||
@@ -257,14 +240,6 @@ impl Icon {
|
||||
pub fn empty() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
/// Rotate the icon by the given angle
|
||||
pub fn rotate(mut self, radians: impl Into<Radians>) -> Self {
|
||||
self.base = self
|
||||
.base
|
||||
.with_transformation(Transformation::rotate(radians));
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Styled for Icon {
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
use instant::Duration;
|
||||
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
div, ease_in_out, percentage, Animation, AnimationExt as _, App, Hsla, IntoElement,
|
||||
ParentElement, RenderOnce, Styled as _, Transformation, Window,
|
||||
Animation, AnimationExt as _, App, Hsla, IntoElement, ParentElement, RenderOnce, Styled as _,
|
||||
Transformation, Window, div, ease_in_out, percentage,
|
||||
};
|
||||
use instant::Duration;
|
||||
|
||||
use crate::{Icon, IconName, Sizable, Size};
|
||||
|
||||
@@ -26,11 +25,6 @@ impl Indicator {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn icon(mut self, icon: impl Into<Icon>) -> Self {
|
||||
self.icon = icon.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn color(mut self, color: Hsla) -> Self {
|
||||
self.color = Some(color);
|
||||
self
|
||||
|
||||
@@ -2,7 +2,7 @@ use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AnyElement, App, DefiniteLength, Edges, Entity, Hsla, InteractiveElement as _, IntoElement,
|
||||
MouseButton, ParentElement as _, Pixels, Rems, RenderOnce, StyleRefinement, Styled, TextAlign,
|
||||
Window, div, px, relative,
|
||||
Window, div, px,
|
||||
};
|
||||
use gpui_base::InputBase;
|
||||
use gpui_base::input::{InputBaseState, InputEditorStyle, InputMode, InputModeKind, TextareaMode};
|
||||
@@ -134,18 +134,6 @@ impl<M: InputModeKind> Input<M> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set full height of the input (Multi-line only).
|
||||
pub fn h_full(mut self) -> Self {
|
||||
self.height = Some(relative(1.));
|
||||
self
|
||||
}
|
||||
|
||||
/// Set height of the input (Multi-line only).
|
||||
pub fn h(mut self, height: impl Into<DefiniteLength>) -> Self {
|
||||
self.height = Some(height.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the appearance of the input field, if false the input field will no border, background.
|
||||
pub fn appearance(mut self, appearance: bool) -> Self {
|
||||
self.appearance = appearance;
|
||||
@@ -158,24 +146,12 @@ impl<M: InputModeKind> Input<M> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set to enable toggle button for password mask state.
|
||||
pub fn mask_toggle(mut self) -> Self {
|
||||
self.mask_toggle = true;
|
||||
self
|
||||
}
|
||||
|
||||
/// Set to disable the input field.
|
||||
pub fn disabled(mut self, disabled: bool) -> Self {
|
||||
self.disabled = disabled;
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the tab index for the input, default is 0.
|
||||
pub fn tab_index(mut self, index: isize) -> Self {
|
||||
self.tab_index = index;
|
||||
self
|
||||
}
|
||||
|
||||
fn render_toggle_mask_button(state: &Entity<InputBaseState<M>>) -> impl IntoElement {
|
||||
Button::new("toggle-mask")
|
||||
.icon(IconName::Eye)
|
||||
|
||||
@@ -7,7 +7,7 @@ use gpui::{
|
||||
use smallvec::SmallVec;
|
||||
use theme::ActiveTheme;
|
||||
|
||||
use crate::{h_flex, Disableable, StyledExt};
|
||||
use crate::{Disableable, StyledExt, h_flex};
|
||||
|
||||
#[derive(IntoElement)]
|
||||
pub(crate) struct MenuItemElement {
|
||||
@@ -61,7 +61,6 @@ impl MenuItemElement {
|
||||
}
|
||||
|
||||
/// Set a handler for when the mouse enters the MenuItem.
|
||||
#[allow(unused)]
|
||||
pub fn on_hover(mut self, handler: impl Fn(&bool, &mut Window, &mut App) + 'static) -> Self {
|
||||
self.on_hover = Some(Box::new(handler));
|
||||
self
|
||||
|
||||
@@ -85,23 +85,6 @@ impl PopupMenuItem {
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new menu item with custom element render.
|
||||
#[inline]
|
||||
pub fn element<F, E>(builder: F) -> Self
|
||||
where
|
||||
F: Fn(&mut Window, &mut App) -> E + 'static,
|
||||
E: IntoElement,
|
||||
{
|
||||
PopupMenuItem::ElementItem {
|
||||
icon: None,
|
||||
disabled: false,
|
||||
checked: false,
|
||||
action: None,
|
||||
render: Box::new(move |window, cx| builder(window, cx).into_any_element()),
|
||||
handler: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new submenu item that opens another popup menu.
|
||||
#[inline]
|
||||
pub fn submenu(label: impl Into<SharedString>, menu: Entity<PopupMenu>) -> Self {
|
||||
@@ -214,21 +197,6 @@ impl PopupMenuItem {
|
||||
self
|
||||
}
|
||||
|
||||
/// Create a link menu item.
|
||||
#[inline]
|
||||
pub fn link(label: impl Into<SharedString>, href: impl Into<String>) -> Self {
|
||||
let href = href.into();
|
||||
PopupMenuItem::Item {
|
||||
icon: None,
|
||||
label: label.into(),
|
||||
disabled: false,
|
||||
checked: false,
|
||||
action: None,
|
||||
is_link: true,
|
||||
handler: Some(Rc::new(move |_, _, cx| cx.open_url(&href))),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_clickable(&self) -> bool {
|
||||
!matches!(self, PopupMenuItem::Separator)
|
||||
@@ -334,28 +302,12 @@ impl PopupMenu {
|
||||
cx.new(|cx| f(Self::new(cx), window, cx))
|
||||
}
|
||||
|
||||
/// Set the focus handle of Entity to handle actions.
|
||||
///
|
||||
/// When the menu is dismissed or before an action is triggered, the focus will be returned to this handle.
|
||||
///
|
||||
/// Then the action will be dispatched to this handle.
|
||||
pub fn action_context(mut self, handle: FocusHandle) -> Self {
|
||||
self.action_context = Some(handle);
|
||||
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());
|
||||
self
|
||||
}
|
||||
|
||||
/// Set max width of the popup menu, default is 500px
|
||||
pub fn max_w(mut self, width: impl Into<Pixels>) -> Self {
|
||||
self.max_width = Some(width.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Set max height of the popup menu, default is half of the window height
|
||||
pub fn max_h(mut self, height: impl Into<Pixels>) -> Self {
|
||||
self.max_height = Some(height.into());
|
||||
@@ -376,34 +328,11 @@ impl PopupMenu {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the side to show check icon, default is `Side::Left`.
|
||||
pub fn check_side(mut self, side: Side) -> Self {
|
||||
self.check_side = side;
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the menu to show external link icon, default is true.
|
||||
pub fn external_link_icon(mut self, visible: bool) -> Self {
|
||||
self.external_link_icon = visible;
|
||||
self
|
||||
}
|
||||
|
||||
/// Add Menu Item
|
||||
pub fn menu(self, label: impl Into<SharedString>, action: Box<dyn Action>) -> Self {
|
||||
self.menu_with_disabled(label, action, false)
|
||||
}
|
||||
|
||||
/// Add Menu Item with enable state
|
||||
pub fn menu_with_enable(
|
||||
mut self,
|
||||
label: impl Into<SharedString>,
|
||||
action: Box<dyn Action>,
|
||||
enable: bool,
|
||||
) -> Self {
|
||||
self.add_menu_item(label, None, action, !enable, false);
|
||||
self
|
||||
}
|
||||
|
||||
/// Add Menu Item with disabled state
|
||||
pub fn menu_with_disabled(
|
||||
mut self,
|
||||
@@ -421,70 +350,14 @@ impl PopupMenu {
|
||||
self
|
||||
}
|
||||
|
||||
/// Add Menu to open link
|
||||
pub fn link(self, label: impl Into<SharedString>, href: impl Into<String>) -> Self {
|
||||
self.link_with_disabled(label, href, false)
|
||||
}
|
||||
|
||||
/// Add Menu to open link with disabled state
|
||||
pub fn link_with_disabled(
|
||||
mut self,
|
||||
label: impl Into<SharedString>,
|
||||
href: impl Into<String>,
|
||||
disabled: bool,
|
||||
) -> Self {
|
||||
let href = href.into();
|
||||
self.menu_items
|
||||
.push(PopupMenuItem::link(label, href).disabled(disabled));
|
||||
self
|
||||
}
|
||||
|
||||
/// Add Menu to open link
|
||||
pub fn link_with_icon(
|
||||
self,
|
||||
label: impl Into<SharedString>,
|
||||
icon: impl Into<Icon>,
|
||||
href: impl Into<String>,
|
||||
) -> Self {
|
||||
self.link_with_icon_and_disabled(label, icon, href, false)
|
||||
}
|
||||
|
||||
/// Add Menu to open link with icon and disabled state
|
||||
fn link_with_icon_and_disabled(
|
||||
mut self,
|
||||
label: impl Into<SharedString>,
|
||||
icon: impl Into<Icon>,
|
||||
href: impl Into<String>,
|
||||
disabled: bool,
|
||||
) -> Self {
|
||||
let href = href.into();
|
||||
self.menu_items.push(
|
||||
PopupMenuItem::link(label, href)
|
||||
.icon(icon)
|
||||
.disabled(disabled),
|
||||
);
|
||||
self
|
||||
}
|
||||
|
||||
/// Add Menu Item with Icon.
|
||||
pub fn menu_with_icon(
|
||||
self,
|
||||
label: impl Into<SharedString>,
|
||||
icon: impl Into<Icon>,
|
||||
action: Box<dyn Action>,
|
||||
) -> Self {
|
||||
self.menu_with_icon_and_disabled(label, icon, action, false)
|
||||
}
|
||||
|
||||
/// Add Menu Item with Icon and disabled state
|
||||
pub fn menu_with_icon_and_disabled(
|
||||
mut self,
|
||||
label: impl Into<SharedString>,
|
||||
icon: impl Into<Icon>,
|
||||
action: Box<dyn Action>,
|
||||
disabled: bool,
|
||||
) -> Self {
|
||||
self.add_menu_item(label, Some(icon.into()), action, disabled, false);
|
||||
self.add_menu_item(label, Some(icon.into()), action, false, false);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -510,41 +383,6 @@ impl PopupMenu {
|
||||
self
|
||||
}
|
||||
|
||||
/// Add Menu Item with custom element render with check state
|
||||
pub fn menu_element_with_check<F, E>(
|
||||
self,
|
||||
checked: bool,
|
||||
action: Box<dyn Action>,
|
||||
builder: F,
|
||||
) -> Self
|
||||
where
|
||||
F: Fn(&mut Window, &mut App) -> E + 'static,
|
||||
E: IntoElement,
|
||||
{
|
||||
self.menu_element_with_check_and_disabled(checked, action, false, builder)
|
||||
}
|
||||
|
||||
/// Add Menu Item with custom element render with check state and disabled state
|
||||
fn menu_element_with_check_and_disabled<F, E>(
|
||||
mut self,
|
||||
checked: bool,
|
||||
action: Box<dyn Action>,
|
||||
disabled: bool,
|
||||
builder: F,
|
||||
) -> Self
|
||||
where
|
||||
F: Fn(&mut Window, &mut App) -> E + 'static,
|
||||
E: IntoElement,
|
||||
{
|
||||
self.menu_items.push(
|
||||
PopupMenuItem::element(builder)
|
||||
.action(action)
|
||||
.checked(checked)
|
||||
.disabled(disabled),
|
||||
);
|
||||
self
|
||||
}
|
||||
|
||||
/// Add a separator Menu Item
|
||||
pub fn separator(mut self) -> Self {
|
||||
if self.menu_items.is_empty() {
|
||||
@@ -636,10 +474,6 @@ impl PopupMenu {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.menu_items.is_empty()
|
||||
}
|
||||
|
||||
fn clickable_menu_items(&self) -> impl Iterator<Item = (usize, &PopupMenuItem)> {
|
||||
self.menu_items
|
||||
.iter()
|
||||
|
||||
@@ -156,13 +156,6 @@ impl Notification {
|
||||
self
|
||||
}
|
||||
|
||||
/// Create an info notification with the given message.
|
||||
pub fn info(message: impl Into<SharedString>) -> Self {
|
||||
Self::new()
|
||||
.message(message)
|
||||
.with_kind(NotificationKind::Info)
|
||||
}
|
||||
|
||||
/// Create a success notification with the given message.
|
||||
pub fn success(message: impl Into<SharedString>) -> Self {
|
||||
Self::new()
|
||||
@@ -209,14 +202,6 @@ impl Notification {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the icon of the notification.
|
||||
///
|
||||
/// If icon is None, the notification will use the default icon of the type.
|
||||
pub fn icon(mut self, icon: impl Into<Icon>) -> Self {
|
||||
self.icon = Some(icon.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the type of the notification, default is NotificationType::Info.
|
||||
pub fn with_kind(mut self, kind: NotificationKind) -> Self {
|
||||
self.kind = Some(kind);
|
||||
@@ -229,15 +214,6 @@ impl Notification {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the click callback of the notification.
|
||||
pub fn on_click(
|
||||
mut self,
|
||||
on_click: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
|
||||
) -> Self {
|
||||
self.on_click = Some(Rc::new(on_click));
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the action button of the notification.
|
||||
///
|
||||
/// When an action is set, the notification will not autohide.
|
||||
@@ -611,13 +587,6 @@ impl NotificationList {
|
||||
}
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn notifications(&self) -> Vec<Entity<Notification>> {
|
||||
self.notifications
|
||||
.iter()
|
||||
.map(|(_, note, _)| note.clone())
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for NotificationList {
|
||||
|
||||
@@ -31,23 +31,6 @@ pub trait ScrollableElement: InteractiveElement + Styled + ParentElement + Eleme
|
||||
fn vertical_scrollbar<H: ScrollbarHandle + Clone>(self, scroll_handle: &H) -> Self {
|
||||
self.scrollbar(scroll_handle, ScrollbarAxis::Vertical)
|
||||
}
|
||||
/// Adds a horizontal scrollbar to the element.
|
||||
#[track_caller]
|
||||
fn horizontal_scrollbar<H: ScrollbarHandle + Clone>(self, scroll_handle: &H) -> Self {
|
||||
self.scrollbar(scroll_handle, ScrollbarAxis::Horizontal)
|
||||
}
|
||||
|
||||
/// Almost equivalent to [`StatefulInteractiveElement::overflow_scroll`], but adds scrollbars.
|
||||
#[track_caller]
|
||||
fn overflow_scrollbar(self) -> Scrollable<Self> {
|
||||
Scrollable::new(self, ScrollbarAxis::Both)
|
||||
}
|
||||
|
||||
/// Almost equivalent to [`StatefulInteractiveElement::overflow_x_scroll`], but adds Horizontal scrollbar.
|
||||
#[track_caller]
|
||||
fn overflow_x_scrollbar(self) -> Scrollable<Self> {
|
||||
Scrollable::new(self, ScrollbarAxis::Horizontal)
|
||||
}
|
||||
|
||||
/// Almost equivalent to [`StatefulInteractiveElement::overflow_y_scroll`], but adds Vertical scrollbar.
|
||||
#[track_caller]
|
||||
|
||||
@@ -63,11 +63,6 @@ impl Switch {
|
||||
self.on_click = Some(Rc::new(handler));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn label_side(mut self, label_side: Side) -> Self {
|
||||
self.label_side = label_side;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Sizable for Switch {
|
||||
|
||||
@@ -2,17 +2,15 @@ use std::rc::Rc;
|
||||
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
Anchor, AnyElement, App, Div, ElementId, InteractiveElement, IntoElement, ParentElement,
|
||||
RenderOnce, ScrollHandle, Stateful, StatefulInteractiveElement as _, StyleRefinement, Styled,
|
||||
Window, div, px,
|
||||
AnyElement, App, Div, ElementId, InteractiveElement, IntoElement, ParentElement, RenderOnce,
|
||||
ScrollHandle, Stateful, StatefulInteractiveElement as _, StyleRefinement, Styled, Window, div,
|
||||
px,
|
||||
};
|
||||
use smallvec::SmallVec;
|
||||
use theme::ActiveTheme;
|
||||
|
||||
use super::Tab;
|
||||
use crate::button::{Button, ButtonVariants as _};
|
||||
use crate::menu::{DropdownMenu as _, PopupMenuItem};
|
||||
use crate::{IconName, Selectable, Sizable, StyledExt, h_flex};
|
||||
use crate::{Selectable, StyledExt, h_flex};
|
||||
|
||||
/// A TabBar element that contains multiple [`Tab`] items.
|
||||
#[derive(IntoElement)]
|
||||
@@ -25,7 +23,6 @@ pub struct TabBar {
|
||||
children: SmallVec<[Tab; 2]>,
|
||||
last_empty_space: AnyElement,
|
||||
selected_index: Option<usize>,
|
||||
menu: bool,
|
||||
segmented: bool,
|
||||
#[allow(clippy::type_complexity)]
|
||||
on_click: Option<Rc<dyn Fn(&usize, &mut Window, &mut App) + 'static>>,
|
||||
@@ -44,7 +41,6 @@ impl TabBar {
|
||||
last_empty_space: div().w_3().into_any_element(),
|
||||
selected_index: None,
|
||||
on_click: None,
|
||||
menu: false,
|
||||
segmented: false,
|
||||
}
|
||||
}
|
||||
@@ -55,12 +51,6 @@ impl TabBar {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set whether to show the menu button when tabs overflow, default is false.
|
||||
pub fn menu(mut self, menu: bool) -> Self {
|
||||
self.menu = menu;
|
||||
self
|
||||
}
|
||||
|
||||
/// Track the scroll of the TabBar.
|
||||
pub fn track_scroll(mut self, scroll_handle: &ScrollHandle) -> Self {
|
||||
self.scroll_handle = Some(scroll_handle.clone());
|
||||
@@ -123,9 +113,6 @@ impl Styled for TabBar {
|
||||
|
||||
impl RenderOnce for TabBar {
|
||||
fn render(self, _: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let mut item_labels = Vec::new();
|
||||
let selected_index = self.selected_index;
|
||||
let on_click = self.on_click.clone();
|
||||
let segmented = self.segmented;
|
||||
let has_prefix = self.prefix.is_some();
|
||||
|
||||
@@ -155,7 +142,6 @@ impl RenderOnce for TabBar {
|
||||
})
|
||||
.gap_1()
|
||||
.children(self.children.into_iter().enumerate().map(|(ix, child)| {
|
||||
item_labels.push((child.label.clone(), child.disabled));
|
||||
let tab_bar_prefix = child.tab_bar_prefix.unwrap_or(true);
|
||||
child
|
||||
.ix(ix)
|
||||
@@ -168,36 +154,10 @@ impl RenderOnce for TabBar {
|
||||
this.on_click(move |_, window, cx| on_click(&ix, window, cx))
|
||||
})
|
||||
}))
|
||||
.when(self.suffix.is_some() || self.menu, |this| {
|
||||
.when(self.suffix.is_some(), |this| {
|
||||
this.child(self.last_empty_space)
|
||||
}),
|
||||
)
|
||||
.when(self.menu, |this| {
|
||||
this.child(
|
||||
Button::new("more")
|
||||
.xsmall()
|
||||
.ghost()
|
||||
.icon(IconName::ChevronDown)
|
||||
.dropdown_menu(move |mut this, _, _| {
|
||||
this = this.scrollable(true);
|
||||
for (ix, (label, disabled)) in item_labels.iter().enumerate() {
|
||||
this = this.item(
|
||||
PopupMenuItem::new(label.clone().unwrap_or_default())
|
||||
.checked(selected_index == Some(ix))
|
||||
.disabled(*disabled)
|
||||
.when_some(on_click.clone(), |this, on_click| {
|
||||
this.on_click(move |_, window, cx| {
|
||||
on_click(&ix, window, cx)
|
||||
})
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
this
|
||||
})
|
||||
.anchor(Anchor::TopRight),
|
||||
)
|
||||
})
|
||||
.when_some(self.suffix, |this, suffix| this.child(suffix))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use gpui::{App, ElementId, Entity, Window};
|
||||
use gpui::{App, ElementId, Window};
|
||||
|
||||
use crate::Root;
|
||||
use crate::dialog::Dialog;
|
||||
@@ -19,9 +17,6 @@ pub trait WindowExtension: Sized {
|
||||
/// Closes all active Dialogs.
|
||||
fn close_all_dialogs(&mut self, cx: &mut App);
|
||||
|
||||
/// Returns number of notifications.
|
||||
fn notifications(&mut self, cx: &mut App) -> Rc<Vec<Entity<Notification>>>;
|
||||
|
||||
/// Pushes a notification to the notification list.
|
||||
fn push_notification<T>(&mut self, note: T, cx: &mut App)
|
||||
where
|
||||
@@ -102,9 +97,4 @@ impl WindowExtension for Window {
|
||||
root.clear_notifications(window, cx);
|
||||
})
|
||||
}
|
||||
|
||||
fn notifications(&mut self, cx: &mut App) -> Rc<Vec<Entity<Notification>>> {
|
||||
let entity = Root::read(self, cx).notification.clone();
|
||||
Rc::new(entity.read(cx).notifications())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user