Merge branch 'main' into splits

This commit is contained in:
Mikayla 2023-12-11 10:16:32 -08:00
commit 3198eb6c6d
No known key found for this signature in database
137 changed files with 16769 additions and 11835 deletions

View file

@ -1,6 +1,6 @@
use gpui::{AnyView, DefiniteLength};
use crate::prelude::*;
use crate::{prelude::*, IconPosition};
use crate::{
ButtonCommon, ButtonLike, ButtonSize, ButtonStyle, Icon, IconSize, Label, LineHeightStyle,
};
@ -14,6 +14,7 @@ pub struct Button {
label_color: Option<Color>,
selected_label: Option<SharedString>,
icon: Option<Icon>,
icon_position: Option<IconPosition>,
icon_size: Option<IconSize>,
icon_color: Option<Color>,
selected_icon: Option<Icon>,
@ -27,6 +28,7 @@ impl Button {
label_color: None,
selected_label: None,
icon: None,
icon_position: None,
icon_size: None,
icon_color: None,
selected_icon: None,
@ -48,6 +50,11 @@ impl Button {
self
}
pub fn icon_position(mut self, icon_position: impl Into<Option<IconPosition>>) -> Self {
self.icon_position = icon_position.into();
self
}
pub fn icon_size(mut self, icon_size: impl Into<Option<IconSize>>) -> Self {
self.icon_size = icon_size.into();
self
@ -141,19 +148,29 @@ impl RenderOnce for Button {
self.label_color.unwrap_or_default()
};
self.base
.children(self.icon.map(|icon| {
ButtonIcon::new(icon)
.disabled(is_disabled)
.selected(is_selected)
.selected_icon(self.selected_icon)
.size(self.icon_size)
.color(self.icon_color)
}))
.child(
Label::new(label)
.color(label_color)
.line_height_style(LineHeightStyle::UILabel),
)
self.base.child(
h_stack()
.gap_1()
.map(|this| {
if self.icon_position == Some(IconPosition::End) {
this.flex_row_reverse()
} else {
this
}
})
.child(
Label::new(label)
.color(label_color)
.line_height_style(LineHeightStyle::UILabel),
)
.children(self.icon.map(|icon| {
ButtonIcon::new(icon)
.disabled(is_disabled)
.selected(is_selected)
.selected_icon(self.selected_icon)
.size(self.icon_size)
.color(self.icon_color)
})),
)
}
}

View file

@ -30,6 +30,13 @@ pub trait ButtonCommon: Clickable + Disableable {
fn tooltip(self, tooltip: impl Fn(&mut WindowContext) -> AnyView + 'static) -> Self;
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Default)]
pub enum IconPosition {
#[default]
Start,
End,
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Default)]
pub enum ButtonStyle {
/// A filled button with a solid background color. Provides emphasis versus
@ -347,6 +354,7 @@ impl RenderOnce for ButtonLike {
ButtonSize::None => this,
})
.bg(self.style.enabled(cx).background)
.when(self.disabled, |this| this.cursor_not_allowed())
.when(!self.disabled, |this| {
this.cursor_pointer()
.hover(|hover| hover.bg(self.style.hovered(cx).background))

View file

@ -239,7 +239,6 @@ impl Render for ContextMenu {
action,
} => {
let handler = handler.clone();
let dismiss = cx.listener(|_, _, cx| cx.emit(DismissEvent));
let label_element = if let Some(icon) = icon {
h_stack()
@ -263,10 +262,7 @@ impl Render for ContextMenu {
})),
)
.selected(Some(ix) == self.selected_index)
.on_click(move |event, cx| {
handler(cx);
dismiss(event, cx)
})
.on_click(move |_, cx| handler(cx))
.into_any_element()
}
},

View file

@ -51,6 +51,7 @@ pub enum Icon {
CopilotDisabled,
Dash,
Envelope,
ExternalLink,
ExclamationTriangle,
Exit,
File,
@ -61,6 +62,7 @@ pub enum Icon {
FileRust,
FileToml,
FileTree,
Filter,
Folder,
FolderOpen,
FolderX,
@ -80,6 +82,7 @@ pub enum Icon {
Quote,
Replace,
ReplaceAll,
ReplaceNext,
Screen,
SelectAll,
Split,
@ -122,13 +125,13 @@ impl Icon {
Icon::Close => "icons/x.svg",
Icon::Collab => "icons/user_group_16.svg",
Icon::Copilot => "icons/copilot.svg",
Icon::CopilotInit => "icons/copilot_init.svg",
Icon::CopilotError => "icons/copilot_error.svg",
Icon::CopilotDisabled => "icons/copilot_disabled.svg",
Icon::Dash => "icons/dash.svg",
Icon::Envelope => "icons/feedback.svg",
Icon::ExclamationTriangle => "icons/warning.svg",
Icon::ExternalLink => "icons/external_link.svg",
Icon::Exit => "icons/exit.svg",
Icon::File => "icons/file.svg",
Icon::FileDoc => "icons/file_icons/book.svg",
@ -138,6 +141,7 @@ impl Icon {
Icon::FileRust => "icons/file_icons/rust.svg",
Icon::FileToml => "icons/file_icons/toml.svg",
Icon::FileTree => "icons/project.svg",
Icon::Filter => "icons/filter.svg",
Icon::Folder => "icons/file_icons/folder.svg",
Icon::FolderOpen => "icons/file_icons/folder_open.svg",
Icon::FolderX => "icons/stop_sharing.svg",
@ -157,6 +161,7 @@ impl Icon {
Icon::Quote => "icons/quote.svg",
Icon::Replace => "icons/replace.svg",
Icon::ReplaceAll => "icons/replace_all.svg",
Icon::ReplaceNext => "icons/replace_next.svg",
Icon::Screen => "icons/desktop.svg",
Icon::SelectAll => "icons/select-all.svg",
Icon::Split => "icons/split.svg",

View file

@ -4,7 +4,7 @@ use story::Story;
use crate::prelude::*;
use crate::{right_click_menu, ContextMenu, Label};
actions!(PrintCurrentDate, PrintBestFood);
actions!(context_menu, [PrintCurrentDate, PrintBestFood]);
fn build_menu(cx: &mut WindowContext, header: impl Into<SharedString>) -> View<ContextMenu> {
ContextMenu::build(cx, |menu, _| {

View file

@ -1,4 +1,5 @@
use gpui::{actions, Div, Render};
use gpui::NoAction;
use gpui::{Div, Render};
use itertools::Itertools;
use story::Story;
@ -7,8 +8,6 @@ use crate::KeyBinding;
pub struct KeybindingStory;
actions!(NoAction);
pub fn binding(key: &str) -> gpui::KeyBinding {
gpui::KeyBinding::new(key, NoAction {}, None)
}