Merge branch 'main' into add-collab-tests

This commit is contained in:
Mikayla Maki 2023-11-03 18:04:31 -07:00 committed by Mikayla
commit 123439adc2
No known key found for this signature in database
52 changed files with 422 additions and 581 deletions

1
Cargo.lock generated
View file

@ -2533,6 +2533,7 @@ dependencies = [
"editor",
"gpui",
"language",
"log",
"lsp",
"postage",
"project",

View file

@ -76,24 +76,22 @@ impl ChannelView {
let project = workspace.project().to_owned();
let channel_store = ChannelStore::global(cx);
let language_registry = workspace.app_state().languages.clone();
let markdown = workspace
.app_state()
.languages
.language_for_name("Markdown");
let markdown = language_registry.language_for_name("Markdown");
let channel_buffer =
channel_store.update(cx, |store, cx| store.open_channel_buffer(channel_id, cx));
cx.spawn(|mut cx| async move {
let channel_buffer = channel_buffer.await?;
let markdown = markdown.await.log_err();
if let Some(markdown) = markdown.await.log_err() {
channel_buffer.update(&mut cx, |buffer, cx| {
buffer.buffer().update(cx, |buffer, cx| {
channel_buffer.update(&mut cx, |buffer, cx| {
buffer.buffer().update(cx, |buffer, cx| {
buffer.set_language_registry(language_registry);
if let Some(markdown) = markdown {
buffer.set_language(Some(markdown), cx);
buffer.set_language_registry(language_registry);
})
});
}
}
})
});
pane.update(&mut cx, |pane, cx| {
let buffer_id = channel_buffer.read(cx).remote_id(cx);

View file

@ -20,6 +20,7 @@ theme = { path = "../theme" }
util = { path = "../util" }
workspace = { path = "../workspace" }
log.workspace = true
anyhow.workspace = true
schemars.workspace = true
serde.workspace = true

View file

@ -151,6 +151,7 @@ impl ProjectDiagnosticsEditor {
) -> Self {
cx.subscribe(&project_handle, |this, _, event, cx| match event {
project::Event::DiskBasedDiagnosticsFinished { language_server_id } => {
log::debug!("Disk based diagnostics finished for server {language_server_id}");
this.update_excerpts(Some(*language_server_id), cx);
this.update_title(cx);
}
@ -158,8 +159,11 @@ impl ProjectDiagnosticsEditor {
language_server_id,
path,
} => {
log::debug!("Adding path {path:?} to update for server {language_server_id}");
this.paths_to_update
.insert((path.clone(), *language_server_id));
this.update_excerpts(Some(*language_server_id), cx);
this.update_title(cx);
}
_ => {}
})
@ -229,6 +233,7 @@ impl ProjectDiagnosticsEditor {
language_server_id: Option<LanguageServerId>,
cx: &mut ViewContext<Self>,
) {
log::debug!("Updating excerpts for server {language_server_id:?}");
let mut paths = Vec::new();
self.paths_to_update.retain(|(path, server_id)| {
if language_server_id
@ -1301,25 +1306,6 @@ mod tests {
cx,
)
.unwrap();
project
.update_diagnostic_entries(
server_id_2,
PathBuf::from("/test/main.js"),
None,
vec![DiagnosticEntry {
range: Unclipped(PointUtf16::new(1, 0))..Unclipped(PointUtf16::new(1, 1)),
diagnostic: Diagnostic {
message: "warning 1".to_string(),
severity: DiagnosticSeverity::ERROR,
is_primary: true,
is_disk_based: true,
group_id: 2,
..Default::default()
},
}],
cx,
)
.unwrap();
});
// The first language server finishes
@ -1353,6 +1339,25 @@ mod tests {
// The second language server finishes
project.update(cx, |project, cx| {
project
.update_diagnostic_entries(
server_id_2,
PathBuf::from("/test/main.js"),
None,
vec![DiagnosticEntry {
range: Unclipped(PointUtf16::new(1, 0))..Unclipped(PointUtf16::new(1, 1)),
diagnostic: Diagnostic {
message: "warning 1".to_string(),
severity: DiagnosticSeverity::ERROR,
is_primary: true,
is_disk_based: true,
group_id: 2,
..Default::default()
},
}],
cx,
)
.unwrap();
project.disk_based_diagnostics_finished(server_id_2, cx);
});

View file

@ -33,9 +33,9 @@ use util::{
paths::{PathExt, FILE_ROW_COLUMN_DELIMITER},
ResultExt, TryFutureExt,
};
use workspace::item::{BreadcrumbText, FollowableItemHandle};
use workspace::item::{BreadcrumbText, FollowableItemHandle, ItemHandle};
use workspace::{
item::{FollowableItem, Item, ItemEvent, ItemHandle, ProjectItem},
item::{FollowableItem, Item, ItemEvent, ProjectItem},
searchable::{Direction, SearchEvent, SearchableItem, SearchableItemHandle},
ItemId, ItemNavHistory, Pane, StatusItemView, ToolbarItemLocation, ViewId, Workspace,
WorkspaceId,

View file

@ -16,9 +16,33 @@ pub fn derive_refineable(input: TokenStream) -> TokenStream {
..
} = parse_macro_input!(input);
let impl_debug_on_refinement = attrs
.iter()
.any(|attr| attr.path.is_ident("refineable") && attr.tokens.to_string().contains("debug"));
let refineable_attr = attrs.iter().find(|attr| attr.path.is_ident("refineable"));
let mut impl_debug_on_refinement = false;
let mut derive_serialize_on_refinement = false;
let mut derive_deserialize_on_refinement = false;
if let Some(refineable_attr) = refineable_attr {
if let Ok(syn::Meta::List(meta_list)) = refineable_attr.parse_meta() {
for nested in meta_list.nested {
let syn::NestedMeta::Meta(syn::Meta::Path(path)) = nested else {
continue;
};
if path.is_ident("debug") {
impl_debug_on_refinement = true;
}
if path.is_ident("serialize") {
derive_serialize_on_refinement = true;
}
if path.is_ident("deserialize") {
derive_deserialize_on_refinement = true;
}
}
}
}
let refinement_ident = format_ident!("{}Refinement", ident);
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
@ -235,8 +259,22 @@ pub fn derive_refineable(input: TokenStream) -> TokenStream {
quote! {}
};
let derive_serialize = if derive_serialize_on_refinement {
quote! { #[derive(serde::Serialize)]}
} else {
quote! {}
};
let derive_deserialize = if derive_deserialize_on_refinement {
quote! { #[derive(serde::Deserialize)]}
} else {
quote! {}
};
let gen = quote! {
#[derive(Clone)]
#derive_serialize
#derive_deserialize
pub struct #refinement_ident #impl_generics {
#( #field_visibilities #field_names: #wrapped_types ),*
}

View file

@ -1,97 +0,0 @@
use gpui2::{
div, ArcCow, Element, EventContext, Interactive, IntoElement, MouseButton, ParentElement,
StyleHelpers, ViewContext,
};
use std::{marker::PhantomData, rc::Rc};
struct ButtonHandlers<V, D> {
click: Option<Rc<dyn Fn(&mut V, &D, &mut EventContext<V>)>>,
}
impl<V, D> Default for ButtonHandlers<V, D> {
fn default() -> Self {
Self { click: None }
}
}
#[derive(Component)]
pub struct Button<V: 'static, D: 'static> {
handlers: ButtonHandlers<V, D>,
label: Option<ArcCow<'static, str>>,
icon: Option<ArcCow<'static, str>>,
data: Rc<D>,
view_type: PhantomData<V>,
}
// Impl block for buttons without data.
// See below for an impl block for any button.
impl<V: 'static> Button<V, ()> {
fn new() -> Self {
Self {
handlers: ButtonHandlers::default(),
label: None,
icon: None,
data: Rc::new(()),
view_type: PhantomData,
}
}
pub fn data<D: 'static>(self, data: D) -> Button<V, D> {
Button {
handlers: ButtonHandlers::default(),
label: self.label,
icon: self.icon,
data: Rc::new(data),
view_type: PhantomData,
}
}
}
// Impl block for button regardless of its data type.
impl<V: 'static, D: 'static> Button<V, D> {
pub fn label(mut self, label: impl Into<ArcCow<'static, str>>) -> Self {
self.label = Some(label.into());
self
}
pub fn icon(mut self, icon: impl Into<ArcCow<'static, str>>) -> Self {
self.icon = Some(icon.into());
self
}
pub fn on_click(
mut self,
handler: impl Fn(&mut V, &D, &mut EventContext<V>) + 'static,
) -> Self {
self.handlers.click = Some(Rc::new(handler));
self
}
}
pub fn button<V>() -> Button<V, ()> {
Button::new()
}
impl<V: 'static, D: 'static> Button<V, D> {
fn render(
&mut self,
view: &mut V,
cx: &mut ViewContext<V>,
) -> impl IntoElement<V> + Interactive<V> {
// let colors = &cx.theme::<Theme>().colors;
let button = div()
// .fill(colors.error(0.5))
.h_4()
.children(self.label.clone());
if let Some(handler) = self.handlers.click.clone() {
let data = self.data.clone();
button.on_mouse_down(MouseButton::Left, move |view, event, cx| {
handler(view, data.as_ref(), cx)
})
} else {
button
}
}
}

View file

@ -1,7 +1,4 @@
use crate::{
story::Story,
story_selector::{ComponentStory, ElementStory},
};
use crate::{story::Story, story_selector::ComponentStory};
use gpui2::{Div, Render, StatefulInteraction, View, VisualContext};
use strum::IntoEnumIterator;
use ui::prelude::*;
@ -18,9 +15,6 @@ impl Render for KitchenSinkStory {
type Element = Div<Self, StatefulInteraction<Self>>;
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
let element_stories = ElementStory::iter()
.map(|selector| selector.story(cx))
.collect::<Vec<_>>();
let component_stories = ComponentStory::iter()
.map(|selector| selector.story(cx))
.collect::<Vec<_>>();
@ -29,8 +23,6 @@ impl Render for KitchenSinkStory {
.id("kitchen-sink")
.overflow_y_scroll()
.child(Story::title(cx, "Kitchen Sink"))
.child(Story::label(cx, "Elements"))
.child(div().flex().flex_col().children(element_stories))
.child(Story::label(cx, "Components"))
.child(div().flex().flex_col().children(component_stories))
// Add a bit of space at the bottom of the kitchen sink so elements

View file

@ -7,55 +7,30 @@ use clap::builder::PossibleValue;
use clap::ValueEnum;
use gpui2::{AnyView, VisualContext};
use strum::{EnumIter, EnumString, IntoEnumIterator};
use ui::{prelude::*, AvatarStory, ButtonStory, DetailsStory, IconStory, InputStory, LabelStory};
#[derive(Debug, PartialEq, Eq, Clone, Copy, strum::Display, EnumString, EnumIter)]
#[strum(serialize_all = "snake_case")]
pub enum ElementStory {
Avatar,
Button,
Colors,
Details,
Focus,
Icon,
Input,
Label,
Scroll,
Text,
ZIndex,
}
impl ElementStory {
pub fn story(&self, cx: &mut WindowContext) -> AnyView {
match self {
Self::Colors => cx.build_view(|_| ColorsStory).into(),
Self::Avatar => cx.build_view(|_| AvatarStory).into(),
Self::Button => cx.build_view(|_| ButtonStory).into(),
Self::Details => cx.build_view(|_| DetailsStory).into(),
Self::Focus => FocusStory::view(cx).into(),
Self::Icon => cx.build_view(|_| IconStory).into(),
Self::Input => cx.build_view(|_| InputStory).into(),
Self::Label => cx.build_view(|_| LabelStory).into(),
Self::Scroll => ScrollStory::view(cx).into(),
Self::Text => TextStory::view(cx).into(),
Self::ZIndex => cx.build_view(|_| ZIndexStory).into(),
}
}
}
use ui::prelude::*;
use ui::{AvatarStory, ButtonStory, DetailsStory, IconStory, InputStory, LabelStory};
#[derive(Debug, PartialEq, Eq, Clone, Copy, strum::Display, EnumString, EnumIter)]
#[strum(serialize_all = "snake_case")]
pub enum ComponentStory {
AssistantPanel,
Avatar,
Breadcrumb,
Buffer,
Button,
ChatPanel,
CollabPanel,
Colors,
CommandPalette,
Copilot,
ContextMenu,
Copilot,
Details,
Facepile,
Focus,
Icon,
Input,
Keybinding,
Label,
LanguageSelector,
MultiBuffer,
NotificationsPanel,
@ -63,29 +38,41 @@ pub enum ComponentStory {
Panel,
ProjectPanel,
RecentProjects,
Scroll,
Tab,
TabBar,
Terminal,
Text,
ThemeSelector,
TitleBar,
Toast,
Toolbar,
TrafficLights,
Workspace,
ZIndex,
}
impl ComponentStory {
pub fn story(&self, cx: &mut WindowContext) -> AnyView {
match self {
Self::AssistantPanel => cx.build_view(|_| ui::AssistantPanelStory).into(),
Self::Buffer => cx.build_view(|_| ui::BufferStory).into(),
Self::Avatar => cx.build_view(|_| AvatarStory).into(),
Self::Breadcrumb => cx.build_view(|_| ui::BreadcrumbStory).into(),
Self::Buffer => cx.build_view(|_| ui::BufferStory).into(),
Self::Button => cx.build_view(|_| ButtonStory).into(),
Self::ChatPanel => cx.build_view(|_| ui::ChatPanelStory).into(),
Self::CollabPanel => cx.build_view(|_| ui::CollabPanelStory).into(),
Self::Colors => cx.build_view(|_| ColorsStory).into(),
Self::CommandPalette => cx.build_view(|_| ui::CommandPaletteStory).into(),
Self::ContextMenu => cx.build_view(|_| ui::ContextMenuStory).into(),
Self::Copilot => cx.build_view(|_| ui::CopilotModalStory).into(),
Self::Details => cx.build_view(|_| DetailsStory).into(),
Self::Facepile => cx.build_view(|_| ui::FacepileStory).into(),
Self::Focus => FocusStory::view(cx).into(),
Self::Icon => cx.build_view(|_| IconStory).into(),
Self::Input => cx.build_view(|_| InputStory).into(),
Self::Keybinding => cx.build_view(|_| ui::KeybindingStory).into(),
Self::Label => cx.build_view(|_| LabelStory).into(),
Self::LanguageSelector => cx.build_view(|_| ui::LanguageSelectorStory).into(),
Self::MultiBuffer => cx.build_view(|_| ui::MultiBufferStory).into(),
Self::NotificationsPanel => cx.build_view(|cx| ui::NotificationsPanelStory).into(),
@ -93,23 +80,24 @@ impl ComponentStory {
Self::Panel => cx.build_view(|cx| ui::PanelStory).into(),
Self::ProjectPanel => cx.build_view(|_| ui::ProjectPanelStory).into(),
Self::RecentProjects => cx.build_view(|_| ui::RecentProjectsStory).into(),
Self::Scroll => ScrollStory::view(cx).into(),
Self::Tab => cx.build_view(|_| ui::TabStory).into(),
Self::TabBar => cx.build_view(|_| ui::TabBarStory).into(),
Self::Terminal => cx.build_view(|_| ui::TerminalStory).into(),
Self::Text => TextStory::view(cx).into(),
Self::ThemeSelector => cx.build_view(|_| ui::ThemeSelectorStory).into(),
Self::TitleBar => ui::TitleBarStory::view(cx).into(),
Self::Toast => cx.build_view(|_| ui::ToastStory).into(),
Self::Toolbar => cx.build_view(|_| ui::ToolbarStory).into(),
Self::TrafficLights => cx.build_view(|_| ui::TrafficLightsStory).into(),
Self::Copilot => cx.build_view(|_| ui::CopilotModalStory).into(),
Self::TitleBar => ui::TitleBarStory::view(cx).into(),
Self::Workspace => ui::WorkspaceStory::view(cx).into(),
Self::ZIndex => cx.build_view(|_| ZIndexStory).into(),
}
}
}
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum StorySelector {
Element(ElementStory),
Component(ComponentStory),
KitchenSink,
}
@ -126,13 +114,6 @@ impl FromStr for StorySelector {
return Ok(Self::KitchenSink);
}
if let Some((_, story)) = story.split_once("elements/") {
let element_story = ElementStory::from_str(story)
.with_context(|| format!("story not found for element '{story}'"))?;
return Ok(Self::Element(element_story));
}
if let Some((_, story)) = story.split_once("components/") {
let component_story = ComponentStory::from_str(story)
.with_context(|| format!("story not found for component '{story}'"))?;
@ -147,7 +128,6 @@ impl FromStr for StorySelector {
impl StorySelector {
pub fn story(&self, cx: &mut WindowContext) -> AnyView {
match self {
Self::Element(element_story) => element_story.story(cx),
Self::Component(component_story) => component_story.story(cx),
Self::KitchenSink => KitchenSinkStory::view(cx).into(),
}
@ -160,11 +140,9 @@ static ALL_STORY_SELECTORS: OnceLock<Vec<StorySelector>> = OnceLock::new();
impl ValueEnum for StorySelector {
fn value_variants<'a>() -> &'a [Self] {
let stories = ALL_STORY_SELECTORS.get_or_init(|| {
let element_stories = ElementStory::iter().map(StorySelector::Element);
let component_stories = ComponentStory::iter().map(StorySelector::Component);
element_stories
.chain(component_stories)
component_stories
.chain(std::iter::once(StorySelector::KitchenSink))
.collect::<Vec<_>>()
});
@ -174,7 +152,6 @@ impl ValueEnum for StorySelector {
fn to_possible_value(&self) -> Option<clap::builder::PossibleValue> {
let value = match self {
Self::Element(story) => format!("elements/{story}"),
Self::Component(story) => format!("components/{story}"),
Self::KitchenSink => "kitchen_sink".to_string(),
};

View file

@ -48,8 +48,8 @@ pub struct GitStatusColors {
pub renamed: Hsla,
}
#[derive(Refineable, Clone, Debug, Default)]
#[refineable(debug)]
#[derive(Refineable, Clone, Debug)]
#[refineable(debug, deserialize)]
pub struct ThemeColors {
pub border: Hsla,
pub border_variant: Hsla,
@ -94,6 +94,8 @@ pub struct ThemeColors {
#[derive(Refineable, Clone)]
pub struct ThemeStyles {
pub system: SystemColors,
#[refineable]
pub colors: ThemeColors,
pub status: StatusColors,
pub git: GitStatusColors,
@ -103,6 +105,8 @@ pub struct ThemeStyles {
#[cfg(test)]
mod tests {
use serde_json::json;
use super::*;
#[test]
@ -144,4 +148,16 @@ mod tests {
assert_eq!(colors.text, magenta);
assert_eq!(colors.background, green);
}
#[test]
fn deserialize_theme_colors_refinement_from_json() {
let colors: ThemeColorsRefinement = serde_json::from_value(json!({
"background": "#ff00ff",
"text": "#ff0000"
}))
.unwrap();
assert_eq!(colors.background, Some(gpui::rgb(0xff00ff)));
assert_eq!(colors.text, Some(gpui::rgb(0xff0000)));
}
}

View file

@ -0,0 +1,39 @@
# Building UI with GPUI
## Common patterns
### Using the Label Component to Create UI Text
The `Label` component helps in displaying text on user interfaces. It creates an interface where specific parameters such as label color, line height style, and strikethrough can be set.
Firstly, to create a `Label` instance, use the `Label::new()` function. This function takes a string that will be displayed as text in the interface.
```rust
Label::new("Hello, world!");
```
Now let's dive a bit deeper into how to customize `Label` instances:
- **Setting Color:** To set the color of the label using various predefined color options such as `Default`, `Muted`, `Created`, `Modified`, `Deleted`, etc, the `color()` function is called on the `Label` instance:
```rust
Label::new("Hello, world!").color(LabelColor::Default);
```
- **Setting Line Height Style:** To set the line height style, the `line_height_style()` function is utilized:
```rust
Label::new("Hello, world!").line_height_style(LineHeightStyle::TextLabel);
```
- **Adding a Strikethrough:** To add a strikethrough in a `Label`, the `set_strikethrough()` function is used:
```rust
Label::new("Hello, world!").set_strikethrough(true);
```
That's it! Now you can use the `Label` component to create and customize text on your application's interface.
## Building a new component
TODO

View file

@ -1,57 +0,0 @@
# Elevation
Elevation in Zed applies to all surfaces and components. Elevation is categorized into levels.
Elevation accomplishes the following:
- Allows surfaces to move in front of or behind others, such as content scrolling beneath app top bars.
- Reflects spatial relationships, for instance, how a floating action buttons shadow intimates its disconnection from a collection of cards.
- Directs attention to structures at the highest elevation, like a temporary dialog arising in front of other surfaces.
Elevations are the initial elevation values assigned to components by default.
Components may transition to a higher elevation in some cases, like user interations.
On such occasions, components transition to predetermined dynamic elevation offsets. These are the typical elevations to which components move when they are not at rest.
## Understanding Elevation
Elevation can be thought of as the physical closeness of an element to the user. Elements with lower elevations are physically further away from the user on the z-axis and appear to be underneath elements with higher elevations.
Material Design 3 has a some great visualizations of elevation that may be helpful to understanding the mental modal of elevation. [Material Design Elevation](https://m3.material.io/styles/elevation/overview)
## Elevation Levels
Zed integrates six unique elevation levels in its design system. The elevation of a surface is expressed as a whole number ranging from 0 to 5, both numbers inclusive. A components elevation is ascertained by combining the components resting elevation with any dynamic elevation offsets.
The levels are detailed as follows:
0. App Background
1. UI Surface
2. Elevated Elements
3. Wash
4. Focused Element
5. Dragged Element
### 0. App Background
The app background constitutes the lowest elevation layer, appearing behind all other surfaces and components. It is predominantly used for the background color of the app.
### 1. UI Surface
The UI Surface is the standard elevation for components and is placed above the app background. It is generally used for the background color of the app bar, card, and sheet.
### 2. Elevated Elements
Elevated elements appear above the UI surface layer surfaces and components. Elevated elements are predominantly used for creating popovers, context menus, and tooltips.
### 3. Wash
Wash denotes a distinct elevation reserved to isolate app UI layers from high elevation components such as modals, notifications, and overlaid panels. The wash may not consistently be visible when these components are active. This layer is often referred to as a scrim or overlay and the background color of the wash is typically deployed in its design.
### 4. Focused Element
Focused elements obtain a higher elevation above surfaces and components at wash elevation. They are often used for modals, notifications, and overlaid panels and indicate that they are the sole element the user is interacting with at the moment.
### 5. Dragged Element
Dragged elements gain the highest elevation, thus appearing above surfaces and components at the elevation of focused elements. These are typically used for elements that are being dragged, following the cursor

View file

@ -0,0 +1,160 @@
# Hello World
Let's work through the prototypical "Build a todo app" example to showcase how we might build a simple component from scratch.
## Setup
We'll create a headline, a list of todo items, and a form to add new items.
~~~rust
struct TodoList<V: 'static> {
headline: SharedString,
items: Vec<TodoItem>,
submit_form: ClickHandler<V>
}
struct TodoItem<V: 'static> {
text: SharedString,
completed: bool,
delete: ClickHandler<V>
}
impl<V: 'static> TodoList<V> {
pub fn new(
// Here we impl Into<SharedString>
headline: impl Into<SharedString>,
items: Vec<TodoItem>,
submit_form: ClickHandler<V>
) -> Self {
Self {
// and here we call .into() so we can simply pass a string
// when creating the headline. This pattern is used throughout
// outr components
headline: headline.into(),
items: Vec::new(),
submit_form,
}
}
}
~~~
All of this is relatively straightforward.
We use [gpui2::SharedString] in components instead of [std::string::String]. This allows us to [TODO: someone who actually knows please explain why we use SharedString].
When we want to pass an action we pass a `ClickHandler`. Whenever we want to add an action, the struct it belongs to needs to be generic over the view type `V`.
~~~rust
use gpui2::hsla
impl<V: 'static> TodoList<V> {
// ...
fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
div().size_4().bg(hsla(50.0/360.0, 1.0, 0.5, 1.0))
}
}
~~~
Every component needs a render method, and it should return `impl Component<V>`. This basic component will render a 16x16px yellow square on the screen.
A couple of questions might come to mind:
**Why is `size_4()` 16px, not 4px?**
gpui's style system is based on conventions created by [Tailwind CSS](https://tailwindcss.com/). Here is an example of the list of sizes for `width`: [Width - TailwindCSS Docs](https://tailwindcss.com/docs/width).
I'll quote from the Tailwind [Core Concepts](https://tailwindcss.com/docs/utility-first) docs here:
> Now I know what youre thinking, “this is an atrocity, what a horrible mess!”
> and youre right, its kind of ugly. In fact its just about impossible to
> think this is a good idea the first time you see it —
> you have to actually try it.
As you start using the Tailwind-style conventions you will be surprised how quick it makes it to build out UIs.
**Why `50.0/360.0` in `hsla()`?**
gpui [gpui2::Hsla] use `0.0-1.0` for all it's values, but it is common for tools to use `0-360` for hue.
This may change in the future, but this is a little trick that let's you use familiar looking values.
## Building out the container
Let's grab our [theme2::colors::ThemeColors] from the theme and start building out a basic container.
We can access the current theme's colors like this:
~~~rust
impl<V: 'static> TodoList<V> {
// ...
fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let color = cx.theme().colors()
div().size_4().hsla(50.0/360.0, 1.0, 0.5, 1.0)
}
}
~~~
Now we have access to the complete set of colors defined in the theme.
~~~rust
use gpui2::hsla
impl<V: 'static> TodoList<V> {
// ...
fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let color = cx.theme().colors()
div().size_4().bg(color.surface)
}
}
~~~
Let's finish up some basic styles for the container then move on to adding the other elements.
~~~rust
use gpui2::hsla
impl<V: 'static> TodoList<V> {
// ...
fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
let color = cx.theme().colors()
div()
// Flex properties
.flex()
.flex_col() // Stack elements vertically
.gap_2() // Add 8px of space between elements
// Size properties
.w_96() // Set width to 384px
.p_4() // Add 16px of padding on all sides
// Color properties
.bg(color.surface) // Set background color
.text_color(color.text) // Set text color
// Border properties
.rounded_md() // Add 4px of border radius
.border() // Add a 1px border
.border_color(color.border)
.child(
"Hello, world!"
)
}
}
~~~
### Headline
TODO
### List of todo items
TODO
### Input
TODO
### End result
TODO

25
crates/ui2/docs/todo.md Normal file
View file

@ -0,0 +1,25 @@
## Documentation priorities:
These are the priorities to get documented, in a rough stack rank order:
- [ ] label
- [ ] button
- [ ] icon_button
- [ ] icon
- [ ] list
- [ ] avatar
- [ ] panel
- [ ] modal
- [ ] palette
- [ ] input
- [ ] facepile
- [ ] player
- [ ] stacks
- [ ] context menu
- [ ] input
- [ ] textarea/multiline input (not built - not an editor)
- [ ] indicator
- [ ] public actor
- [ ] keybinding
- [ ] tab
- [ ] toast

View file

@ -1,71 +1,45 @@
mod assistant_panel;
mod breadcrumb;
mod buffer;
mod buffer_search;
mod chat_panel;
mod collab_panel;
mod command_palette;
mod avatar;
mod button;
mod context_menu;
mod copilot;
mod editor_pane;
mod details;
mod facepile;
mod icon;
mod icon_button;
mod indicator;
mod input;
mod keybinding;
mod language_selector;
mod label;
mod list;
mod modal;
mod multi_buffer;
mod notification_toast;
mod notifications_panel;
mod palette;
mod panel;
mod panes;
mod player;
mod player_stack;
mod project_panel;
mod recent_projects;
mod status_bar;
mod stack;
mod tab;
mod tab_bar;
mod terminal;
mod theme_selector;
mod title_bar;
mod toast;
mod toolbar;
mod traffic_lights;
mod workspace;
mod tool_divider;
pub use assistant_panel::*;
pub use breadcrumb::*;
pub use buffer::*;
pub use buffer_search::*;
pub use chat_panel::*;
pub use collab_panel::*;
pub use command_palette::*;
pub use avatar::*;
pub use button::*;
pub use context_menu::*;
pub use copilot::*;
pub use editor_pane::*;
pub use details::*;
pub use facepile::*;
pub use icon::*;
pub use icon_button::*;
pub use indicator::*;
pub use input::*;
pub use keybinding::*;
pub use language_selector::*;
pub use label::*;
pub use list::*;
pub use modal::*;
pub use multi_buffer::*;
pub use notification_toast::*;
pub use notifications_panel::*;
pub use palette::*;
pub use panel::*;
pub use panes::*;
pub use player::*;
pub use player_stack::*;
pub use project_panel::*;
pub use recent_projects::*;
pub use status_bar::*;
pub use stack::*;
pub use tab::*;
pub use tab_bar::*;
pub use terminal::*;
pub use theme_selector::*;
pub use title_bar::*;
pub use toast::*;
pub use toolbar::*;
pub use traffic_lights::*;
pub use workspace::*;
pub use tool_divider::*;

View file

@ -1,21 +0,0 @@
mod avatar;
mod button;
mod details;
mod icon;
mod indicator;
mod input;
mod label;
mod player;
mod stack;
mod tool_divider;
pub use avatar::*;
pub use button::*;
pub use details::*;
pub use icon::*;
pub use indicator::*;
pub use input::*;
pub use label::*;
pub use player::*;
pub use stack::*;
pub use tool_divider::*;

View file

@ -7,28 +7,25 @@
//! This crate is still a work in progress. The initial primitives and components are built for getting all the UI on the screen,
//! much of the state and functionality is mocked or hard codeded, and performance has not been a focus.
//!
//! Expect some inconsistencies from component to component as we work out the best way to build these components.
//!
//! ## Design Philosophy
//!
//! Work in Progress!
//!
#![doc = include_str!("../docs/hello-world.md")]
#![doc = include_str!("../docs/building-ui.md")]
#![doc = include_str!("../docs/todo.md")]
// TODO: Fix warnings instead of supressing.
#![allow(dead_code, unused_variables)]
mod components;
mod elements;
mod elevation;
pub mod prelude;
pub mod settings;
mod static_data;
mod to_extract;
pub mod utils;
pub use components::*;
pub use elements::*;
pub use prelude::*;
pub use static_data::*;
pub use to_extract::*;
// This needs to be fully qualified with `crate::` otherwise we get a panic
// at:

View file

@ -0,0 +1,47 @@
mod assistant_panel;
mod breadcrumb;
mod buffer;
mod buffer_search;
mod chat_panel;
mod collab_panel;
mod command_palette;
mod copilot;
mod editor_pane;
mod language_selector;
mod multi_buffer;
mod notifications_panel;
mod panes;
mod project_panel;
mod recent_projects;
mod status_bar;
mod tab_bar;
mod terminal;
mod theme_selector;
mod title_bar;
mod toolbar;
mod traffic_lights;
mod workspace;
pub use assistant_panel::*;
pub use breadcrumb::*;
pub use buffer::*;
pub use buffer_search::*;
pub use chat_panel::*;
pub use collab_panel::*;
pub use command_palette::*;
pub use copilot::*;
pub use editor_pane::*;
pub use language_selector::*;
pub use multi_buffer::*;
pub use notifications_panel::*;
pub use panes::*;
pub use project_panel::*;
pub use recent_projects::*;
pub use status_bar::*;
pub use tab_bar::*;
pub use terminal::*;
pub use theme_selector::*;
pub use title_bar::*;
pub use toolbar::*;
pub use traffic_lights::*;
pub use workspace::*;

254
theme.txt
View file

@ -1,254 +0,0 @@
Finished dev [unoptimized + debuginfo] target(s) in 0.39s
Running `target/debug/storybook`
[crates/ui2/src/components/workspace.rs:182] color = [crates/ui2/src/color.rs:162] "ThemeColor debug" = "ThemeColor debug"
ThemeColor {
transparent: "rgba(0x00000000).into()",
mac_os_traffic_light_red: "rgba(0xec695eff).into()",
mac_os_traffic_light_yellow: "rgba(0xf4bf4eff).into()",
mac_os_traffic_light_green: "rgba(0x61c553ff).into()",
border: "rgba(0x464b57ff).into()",
border_variant: "rgba(0x464b57ff).into()",
border_focused: "rgba(0x293b5bff).into()",
border_transparent: "rgba(0x00000000).into()",
elevated_surface: "rgba(0x3b414dff).into()",
surface: "rgba(0x2f343eff).into()",
background: "rgba(0x3b414dff).into()",
filled_element: "rgba(0x3b414dff).into()",
filled_element_hover: "rgba(0xffffff1e).into()",
filled_element_active: "rgba(0xffffff28).into()",
filled_element_selected: "rgba(0x18243dff).into()",
filled_element_disabled: "rgba(0x00000000).into()",
ghost_element: "rgba(0x00000000).into()",
ghost_element_hover: "rgba(0xffffff14).into()",
ghost_element_active: "rgba(0xffffff1e).into()",
ghost_element_selected: "rgba(0x18243dff).into()",
ghost_element_disabled: "rgba(0x00000000).into()",
text: "rgba(0xc8ccd4ff).into()",
text_muted: "rgba(0x838994ff).into()",
text_placeholder: "rgba(0xd07277ff).into()",
text_disabled: "rgba(0x555a63ff).into()",
text_accent: "rgba(0x74ade8ff).into()",
icon_muted: "rgba(0x838994ff).into()",
syntax: SyntaxColor {
comment: "rgba(0x5d636fff).into()",
string: "rgba(0xa1c181ff).into()",
function: "rgba(0x73ade9ff).into()",
keyword: "rgba(0xb477cfff).into()",
},
status_bar: "rgba(0x3b414dff).into()",
title_bar: "rgba(0x3b414dff).into()",
toolbar: "rgba(0x282c33ff).into()",
tab_bar: "rgba(0x2f343eff).into()",
editor_subheader: "rgba(0x2f343eff).into()",
editor_active_line: "rgba(0x2f343eff).into()",
terminal: "rgba(0x282c33ff).into()",
image_fallback_background: "rgba(0x3b414dff).into()",
git_created: "rgba(0xa1c181ff).into()",
git_modified: "rgba(0x74ade8ff).into()",
git_deleted: "rgba(0xd07277ff).into()",
git_conflict: "rgba(0xdec184ff).into()",
git_ignored: "rgba(0x555a63ff).into()",
git_renamed: "rgba(0xdec184ff).into()",
player: [
PlayerThemeColors {
cursor: "rgba(0x74ade8ff).into()",
selection: "rgba(0x74ade83d).into()",
},
PlayerThemeColors {
cursor: "rgba(0xa1c181ff).into()",
selection: "rgba(0xa1c1813d).into()",
},
PlayerThemeColors {
cursor: "rgba(0xbe5046ff).into()",
selection: "rgba(0xbe50463d).into()",
},
PlayerThemeColors {
cursor: "rgba(0xbf956aff).into()",
selection: "rgba(0xbf956a3d).into()",
},
PlayerThemeColors {
cursor: "rgba(0xb477cfff).into()",
selection: "rgba(0xb477cf3d).into()",
},
PlayerThemeColors {
cursor: "rgba(0x6eb4bfff).into()",
selection: "rgba(0x6eb4bf3d).into()",
},
PlayerThemeColors {
cursor: "rgba(0xd07277ff).into()",
selection: "rgba(0xd072773d).into()",
},
PlayerThemeColors {
cursor: "rgba(0xdec184ff).into()",
selection: "rgba(0xdec1843d).into()",
},
],
}
[crates/ui2/src/components/workspace.rs:182] color = [crates/ui2/src/color.rs:162] "ThemeColor debug" = "ThemeColor debug"
ThemeColor {
transparent: "rgba(0x00000000).into()",
mac_os_traffic_light_red: "rgba(0xec695eff).into()",
mac_os_traffic_light_yellow: "rgba(0xf4bf4eff).into()",
mac_os_traffic_light_green: "rgba(0x61c553ff).into()",
border: "rgba(0x464b57ff).into()",
border_variant: "rgba(0x464b57ff).into()",
border_focused: "rgba(0x293b5bff).into()",
border_transparent: "rgba(0x00000000).into()",
elevated_surface: "rgba(0x3b414dff).into()",
surface: "rgba(0x2f343eff).into()",
background: "rgba(0x3b414dff).into()",
filled_element: "rgba(0x3b414dff).into()",
filled_element_hover: "rgba(0xffffff1e).into()",
filled_element_active: "rgba(0xffffff28).into()",
filled_element_selected: "rgba(0x18243dff).into()",
filled_element_disabled: "rgba(0x00000000).into()",
ghost_element: "rgba(0x00000000).into()",
ghost_element_hover: "rgba(0xffffff14).into()",
ghost_element_active: "rgba(0xffffff1e).into()",
ghost_element_selected: "rgba(0x18243dff).into()",
ghost_element_disabled: "rgba(0x00000000).into()",
text: "rgba(0xc8ccd4ff).into()",
text_muted: "rgba(0x838994ff).into()",
text_placeholder: "rgba(0xd07277ff).into()",
text_disabled: "rgba(0x555a63ff).into()",
text_accent: "rgba(0x74ade8ff).into()",
icon_muted: "rgba(0x838994ff).into()",
syntax: SyntaxColor {
comment: "rgba(0x5d636fff).into()",
string: "rgba(0xa1c181ff).into()",
function: "rgba(0x73ade9ff).into()",
keyword: "rgba(0xb477cfff).into()",
},
status_bar: "rgba(0x3b414dff).into()",
title_bar: "rgba(0x3b414dff).into()",
toolbar: "rgba(0x282c33ff).into()",
tab_bar: "rgba(0x2f343eff).into()",
editor_subheader: "rgba(0x2f343eff).into()",
editor_active_line: "rgba(0x2f343eff).into()",
terminal: "rgba(0x282c33ff).into()",
image_fallback_background: "rgba(0x3b414dff).into()",
git_created: "rgba(0xa1c181ff).into()",
git_modified: "rgba(0x74ade8ff).into()",
git_deleted: "rgba(0xd07277ff).into()",
git_conflict: "rgba(0xdec184ff).into()",
git_ignored: "rgba(0x555a63ff).into()",
git_renamed: "rgba(0xdec184ff).into()",
player: [
PlayerThemeColors {
cursor: "rgba(0x74ade8ff).into()",
selection: "rgba(0x74ade83d).into()",
},
PlayerThemeColors {
cursor: "rgba(0xa1c181ff).into()",
selection: "rgba(0xa1c1813d).into()",
},
PlayerThemeColors {
cursor: "rgba(0xbe5046ff).into()",
selection: "rgba(0xbe50463d).into()",
},
PlayerThemeColors {
cursor: "rgba(0xbf956aff).into()",
selection: "rgba(0xbf956a3d).into()",
},
PlayerThemeColors {
cursor: "rgba(0xb477cfff).into()",
selection: "rgba(0xb477cf3d).into()",
},
PlayerThemeColors {
cursor: "rgba(0x6eb4bfff).into()",
selection: "rgba(0x6eb4bf3d).into()",
},
PlayerThemeColors {
cursor: "rgba(0xd07277ff).into()",
selection: "rgba(0xd072773d).into()",
},
PlayerThemeColors {
cursor: "rgba(0xdec184ff).into()",
selection: "rgba(0xdec1843d).into()",
},
],
}
[crates/ui2/src/components/workspace.rs:182] color = [crates/ui2/src/color.rs:162] "ThemeColor debug" = "ThemeColor debug"
ThemeColor {
transparent: "rgba(0x00000000).into()",
mac_os_traffic_light_red: "rgba(0xec695eff).into()",
mac_os_traffic_light_yellow: "rgba(0xf4bf4eff).into()",
mac_os_traffic_light_green: "rgba(0x61c553ff).into()",
border: "rgba(0x464b57ff).into()",
border_variant: "rgba(0x464b57ff).into()",
border_focused: "rgba(0x293b5bff).into()",
border_transparent: "rgba(0x00000000).into()",
elevated_surface: "rgba(0x3b414dff).into()",
surface: "rgba(0x2f343eff).into()",
background: "rgba(0x3b414dff).into()",
filled_element: "rgba(0x3b414dff).into()",
filled_element_hover: "rgba(0xffffff1e).into()",
filled_element_active: "rgba(0xffffff28).into()",
filled_element_selected: "rgba(0x18243dff).into()",
filled_element_disabled: "rgba(0x00000000).into()",
ghost_element: "rgba(0x00000000).into()",
ghost_element_hover: "rgba(0xffffff14).into()",
ghost_element_active: "rgba(0xffffff1e).into()",
ghost_element_selected: "rgba(0x18243dff).into()",
ghost_element_disabled: "rgba(0x00000000).into()",
text: "rgba(0xc8ccd4ff).into()",
text_muted: "rgba(0x838994ff).into()",
text_placeholder: "rgba(0xd07277ff).into()",
text_disabled: "rgba(0x555a63ff).into()",
text_accent: "rgba(0x74ade8ff).into()",
icon_muted: "rgba(0x838994ff).into()",
syntax: SyntaxColor {
comment: "rgba(0x5d636fff).into()",
string: "rgba(0xa1c181ff).into()",
function: "rgba(0x73ade9ff).into()",
keyword: "rgba(0xb477cfff).into()",
},
status_bar: "rgba(0x3b414dff).into()",
title_bar: "rgba(0x3b414dff).into()",
toolbar: "rgba(0x282c33ff).into()",
tab_bar: "rgba(0x2f343eff).into()",
editor_subheader: "rgba(0x2f343eff).into()",
editor_active_line: "rgba(0x2f343eff).into()",
terminal: "rgba(0x282c33ff).into()",
image_fallback_background: "rgba(0x3b414dff).into()",
git_created: "rgba(0xa1c181ff).into()",
git_modified: "rgba(0x74ade8ff).into()",
git_deleted: "rgba(0xd07277ff).into()",
git_conflict: "rgba(0xdec184ff).into()",
git_ignored: "rgba(0x555a63ff).into()",
git_renamed: "rgba(0xdec184ff).into()",
player: [
PlayerThemeColors {
cursor: "rgba(0x74ade8ff).into()",
selection: "rgba(0x74ade83d).into()",
},
PlayerThemeColors {
cursor: "rgba(0xa1c181ff).into()",
selection: "rgba(0xa1c1813d).into()",
},
PlayerThemeColors {
cursor: "rgba(0xbe5046ff).into()",
selection: "rgba(0xbe50463d).into()",
},
PlayerThemeColors {
cursor: "rgba(0xbf956aff).into()",
selection: "rgba(0xbf956a3d).into()",
},
PlayerThemeColors {
cursor: "rgba(0xb477cfff).into()",
selection: "rgba(0xb477cf3d).into()",
},
PlayerThemeColors {
cursor: "rgba(0x6eb4bfff).into()",
selection: "rgba(0x6eb4bf3d).into()",
},
PlayerThemeColors {
cursor: "rgba(0xd07277ff).into()",
selection: "rgba(0xd072773d).into()",
},
PlayerThemeColors {
cursor: "rgba(0xdec184ff).into()",
selection: "rgba(0xdec1843d).into()",
},
],
}