Move title_bar, util into workspace.

This commit is contained in:
Jason Lee 2024-07-01 23:51:47 +08:00
parent f84e8b82ef
commit f2703122b8
36 changed files with 50 additions and 81 deletions

38
Cargo.lock generated
View file

@ -2132,7 +2132,7 @@ dependencies = [
"thiserror", "thiserror",
"time", "time",
"usvg", "usvg",
"util 0.1.0 (git+https://github.com/zed-industries/zed.git)", "util",
"uuid", "uuid",
"waker-fn", "waker-fn",
"wayland-backend", "wayland-backend",
@ -2867,9 +2867,8 @@ dependencies = [
"gpui", "gpui",
"log", "log",
"rust-embed", "rust-embed",
"story",
"ui", "ui",
"ui-story",
"util 0.1.0",
"workspace", "workspace",
] ]
@ -4583,6 +4582,18 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "story"
version = "0.1.0"
dependencies = [
"anyhow",
"fake",
"gpui",
"serde",
"ui",
"workspace",
]
[[package]] [[package]]
name = "strict-num" name = "strict-num"
version = "0.1.1" version = "0.1.1"
@ -5164,18 +5175,6 @@ dependencies = [
"wry", "wry",
] ]
[[package]]
name = "ui-story"
version = "0.1.0"
dependencies = [
"anyhow",
"fake",
"gpui",
"serde",
"ui",
"workspace",
]
[[package]] [[package]]
name = "unicase" name = "unicase"
version = "2.7.0" version = "2.7.0"
@ -5297,13 +5296,6 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
[[package]]
name = "util"
version = "0.1.0"
dependencies = [
"log",
]
[[package]] [[package]]
name = "util" name = "util"
version = "0.1.0" version = "0.1.0"
@ -6034,7 +6026,7 @@ dependencies = [
"serde", "serde",
"smallvec", "smallvec",
"ui", "ui",
"util 0.1.0", "windows",
] ]
[[package]] [[package]]

View file

@ -1,11 +1,5 @@
[workspace] [workspace]
members = [ members = ["crates/app", "crates/ui", "crates/story", "crates/workspace"]
"crates/app",
"crates/ui",
"crates/ui-story",
"crates/workspace",
"crates/util",
]
default-members = ["crates/app"] default-members = ["crates/app"]
resolver = "2" resolver = "2"
@ -13,9 +7,8 @@ resolver = "2"
[workspace.dependencies] [workspace.dependencies]
gpui = { git = "https://github.com/zed-industries/zed.git" } gpui = { git = "https://github.com/zed-industries/zed.git" }
ui = { path = "crates/ui" } ui = { path = "crates/ui" }
ui-story = { path = "crates/ui-story" } story = { path = "crates/story" }
workspace = { path = "crates/workspace" } workspace = { path = "crates/workspace" }
util = { path = "crates/util" }
anyhow = "1" anyhow = "1"
log = "0.4" log = "0.4"
serde = "1.0.203" serde = "1.0.203"

View file

@ -64,11 +64,8 @@ cargo run
There have a part of UI components from [Zed](https://github.com/zed-industries/zed/tree/main/crates/ui), that are under GPL v3.0 license. There have a part of UI components from [Zed](https://github.com/zed-industries/zed/tree/main/crates/ui), that are under GPL v3.0 license.
- workspace (crate) - workspace
- title_bar
- picker
- scrollbar - scrollbar
- picker
> I think we can discuss them with Zed team to change the license to MIT or Apache License for share to community.
Other code are under Apache License. Other code are under Apache License.

View file

@ -10,8 +10,8 @@ rust-embed = "8"
log.workspace = true log.workspace = true
workspace.workspace = true workspace.workspace = true
ui.workspace = true ui.workspace = true
ui-story.workspace = true story.workspace = true
util.workspace = true
[lints] [lints]
workspace = true workspace = true

View file

@ -1 +0,0 @@
../../LICENSE-APACHE

View file

@ -1,19 +1,17 @@
use gpui::*; use gpui::*;
use prelude::FluentBuilder as _; use prelude::FluentBuilder as _;
use ui_story::{ use story::{
ButtonStory, CheckboxStory, DropdownStory, InputStory, ListStory, PickerStory, PopoverStory, ButtonStory, CheckboxStory, DropdownStory, InputStory, ListStory, PickerStory, PopoverStory,
StoryContainer, SwitchStory, TooltipStory, StoryContainer, SwitchStory, TooltipStory,
}; };
use workspace::Workspace; use workspace::{TitleBar, Workspace};
use std::sync::Arc; use std::sync::Arc;
use ui::{ use ui::{
button::ButtonSize, button::ButtonSize,
switch::{LabelSide, Switch}, switch::{LabelSide, Switch},
theme::{ActiveTheme, Theme}, theme::{ActiveTheme, Theme},
title_bar::TitleBar,
}; };
use util::ResultExt as _;
use crate::app_state::AppState; use crate::app_state::AppState;
@ -162,7 +160,7 @@ impl StoryWorkspace {
}) })
.detach(); .detach();
}) })
.log_err(); .expect("failed to update window");
Ok(window) Ok(window)
}) })
@ -177,10 +175,10 @@ pub fn open_new(
let task: Task<std::result::Result<WindowHandle<StoryWorkspace>, anyhow::Error>> = let task: Task<std::result::Result<WindowHandle<StoryWorkspace>, anyhow::Error>> =
StoryWorkspace::new_local(app_state, cx); StoryWorkspace::new_local(app_state, cx);
cx.spawn(|mut cx| async move { cx.spawn(|mut cx| async move {
if let Some(workspace) = task.await.log_err() { if let Some(workspace) = task.await.ok() {
workspace workspace
.update(&mut cx, |workspace, cx| init(workspace, cx)) .update(&mut cx, |workspace, cx| init(workspace, cx))
.log_err(); .expect("failed to init workspace");
} }
}) })
} }

View file

@ -1,5 +1,5 @@
[package] [package]
name = "ui-story" name = "story"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"

View file

@ -1,6 +1,6 @@
use gpui::{ use gpui::{
div, ClickEvent, Div, IntoElement, ParentElement as _, Render, SharedString, Styled as _, View, ClickEvent, IntoElement, ParentElement as _, Render, Styled as _, View, ViewContext,
ViewContext, VisualContext as _, WindowContext, VisualContext as _, WindowContext,
}; };
use ui::{ use ui::{

View file

@ -3,7 +3,7 @@ use gpui::{
VisualContext, WindowContext, VisualContext, WindowContext,
}; };
use ui::{input::TextInput, v_flex, Icon, IconName}; use ui::{input::TextInput, v_flex, IconName};
use crate::section; use crate::section;

View file

@ -1 +0,0 @@
../../LICENSE-APACHE

View file

@ -1,8 +1,6 @@
use std::ops::Deref;
use crate::{button::ButtonSize, theme::ActiveTheme}; use crate::{button::ButtonSize, theme::ActiveTheme};
use gpui::{ use gpui::{
prelude::FluentBuilder as _, svg, AnyElement, AnyView, Hsla, IntoElement, Render, RenderOnce, prelude::FluentBuilder as _, svg, AnyElement, Hsla, IntoElement, Render, RenderOnce,
SharedString, StyleRefinement, Styled, Svg, View, VisualContext, WindowContext, SharedString, StyleRefinement, Styled, Svg, View, VisualContext, WindowContext,
}; };

View file

@ -2,8 +2,6 @@ mod clickable;
mod disableable; mod disableable;
mod event; mod event;
mod icon; mod icon;
mod platform;
mod prelude;
mod scrollbar; mod scrollbar;
mod selectable; mod selectable;
mod stock; mod stock;
@ -13,8 +11,8 @@ pub mod button;
pub mod checkbox; pub mod checkbox;
pub mod empty; pub mod empty;
pub mod label; pub mod label;
pub mod prelude;
pub mod theme; pub mod theme;
pub mod title_bar;
pub use styled_ext::StyledExt; pub use styled_ext::StyledExt;
pub mod divider; pub mod divider;
pub mod dropdown; pub mod dropdown;

View file

@ -32,8 +32,6 @@ impl Scrollbar {
) -> Option<Self> { ) -> Option<Self> {
let cloned_handle = handle.clone(); let cloned_handle = handle.clone();
// Ref from: Zed crates\project_panel\src\project_panel.rs
// render_scrollbar method
let scroll_state = handle.0.borrow(); let scroll_state = handle.0.borrow();
let last_item_height = scroll_state let last_item_height = scroll_state
.last_item_height .last_item_height

View file

@ -1,11 +1,11 @@
use crate::selectable::Selectable; use crate::selectable::Selectable;
use crate::theme::{ActiveTheme, Colorize}; use crate::theme::{ActiveTheme, Colorize};
use gpui::prelude::FluentBuilder as _; use gpui::prelude::FluentBuilder as _;
use gpui::InteractiveElement;
use gpui::{ use gpui::{
div, px, AnyElement, Div, ElementId, IntoElement, ParentElement as _, RenderOnce, Stateful, div, px, AnyElement, Div, ElementId, IntoElement, ParentElement as _, RenderOnce, Stateful,
StatefulInteractiveElement, WindowContext, StatefulInteractiveElement, Styled, WindowContext,
}; };
use gpui::{InteractiveElement, Styled as _};
#[derive(IntoElement)] #[derive(IntoElement)]
pub struct Tab { pub struct Tab {
@ -70,6 +70,8 @@ impl RenderOnce for Tab {
.items_center() .items_center()
.gap_2() .gap_2()
.h_full() .h_full()
.flex_shrink_0()
.overflow_scroll()
.cursor_pointer() .cursor_pointer()
.py_1() .py_1()
.px_3() .px_3()

View file

@ -1,10 +0,0 @@
[package]
name = "util"
version = "0.1.0"
edition = "2021"
[dependencies]
log.workspace = true
[lints]
workspace = true

View file

@ -1 +0,0 @@
../../LICENSE-APACHE

View file

@ -7,7 +7,7 @@ edition = "2021"
gpui.workspace = true gpui.workspace = true
ui.workspace = true ui.workspace = true
anyhow.workspace = true anyhow.workspace = true
util.workspace = true windows = "0.57.0"
schemars = "0.7.0" schemars = "0.7.0"
parking_lot = "0.12.1" parking_lot = "0.12.1"
serde = "1.0.203" serde = "1.0.203"

View file

@ -4,6 +4,9 @@ pub mod model_layer;
pub mod notification; pub mod notification;
pub mod pane; pub mod pane;
pub mod pane_group; pub mod pane_group;
mod title_bar;
mod util;
mod workspace; mod workspace;
pub use title_bar::TitleBar;
pub use workspace::*; pub use workspace::*;

View file

@ -19,6 +19,7 @@ use gpui::{
}; };
use serde::Deserialize; use serde::Deserialize;
use crate::util::ResultExt;
use ui::{ use ui::{
label::Label, label::Label,
tab::{Tab, TabBar}, tab::{Tab, TabBar},
@ -26,7 +27,6 @@ use ui::{
tooltip::Tooltip, tooltip::Tooltip,
v_flex, Icon, IconName, Selectable, StyledExt as _, v_flex, Icon, IconName, Selectable, StyledExt as _,
}; };
use util::ResultExt;
use super::{ use super::{
item::{ItemHandle, TabContentParams}, item::{ItemHandle, TabContentParams},

View file

@ -455,6 +455,7 @@ mod element {
use std::mem; use std::mem;
use std::{cell::RefCell, iter, rc::Rc, sync::Arc}; use std::{cell::RefCell, iter, rc::Rc, sync::Arc};
use crate::util::ResultExt;
use gpui::{ use gpui::{
px, relative, Along, AnyElement, Axis, Bounds, Element, ElementId, GlobalElementId, px, relative, Along, AnyElement, Axis, Bounds, Element, ElementId, GlobalElementId,
IntoElement, MouseDownEvent, MouseMoveEvent, MouseUpEvent, ParentElement, Pixels, Point, IntoElement, MouseDownEvent, MouseMoveEvent, MouseUpEvent, ParentElement, Pixels, Point,
@ -464,7 +465,6 @@ mod element {
use parking_lot::Mutex; use parking_lot::Mutex;
use smallvec::SmallVec; use smallvec::SmallVec;
use ui::theme::ActiveTheme; use ui::theme::ActiveTheme;
use util::ResultExt;
use crate::Workspace; use crate::Workspace;

View file

@ -1,4 +1,5 @@
mod linux_window_controls; mod linux_window_controls;
mod platform;
mod title_bar; mod title_bar;
mod windows_window_controls; mod windows_window_controls;

View file

@ -1,6 +1,5 @@
use gpui::{prelude::*, Action, Rgba, WindowAppearance}; use gpui::{prelude::*, Action, Rgba, WindowAppearance};
use ui::{h_flex, prelude::*, Icon, IconName};
use crate::{prelude::*, stock::h_flex, Icon, IconName};
#[derive(IntoElement)] #[derive(IntoElement)]
pub struct LinuxWindowControls { pub struct LinuxWindowControls {

View file

@ -1,10 +1,11 @@
use gpui::{Action, AnyElement, Interactivity, Stateful}; use gpui::{Action, AnyElement, Interactivity, Stateful};
use smallvec::SmallVec; use smallvec::SmallVec;
use crate::{platform::PlatformStyle, prelude::*, stock::h_flex, theme::ActiveTheme}; use ui::{h_flex, prelude::*, theme::ActiveTheme};
use super::{ use super::{
linux_window_controls::LinuxWindowControls, windows_window_controls::WindowsWindowControls, linux_window_controls::LinuxWindowControls, platform::PlatformStyle,
windows_window_controls::WindowsWindowControls,
}; };
#[derive(IntoElement)] #[derive(IntoElement)]

View file

@ -1,6 +1,6 @@
use gpui::{hsla, prelude::*, Hsla}; use gpui::{hsla, prelude::*, Hsla};
use crate::{prelude::*, stock::h_flex, theme::ActiveTheme}; use ui::{h_flex, prelude::*, theme::ActiveTheme};
#[derive(IntoElement)] #[derive(IntoElement)]
pub struct WindowsWindowControls { pub struct WindowsWindowControls {

View file

@ -17,6 +17,7 @@ macro_rules! debug_panic {
}; };
} }
#[allow(unused)]
pub trait ResultExt<E> { pub trait ResultExt<E> {
type Ok; type Ok;

View file

@ -1,3 +1,4 @@
#[allow(unused)]
mod log; mod log;
pub use log::*; pub use log::*;