ea4419076e
This PR implements the preview tabs feature from VSCode. More details and thanks for the head start of the implementation here #6782. Here is what I have observed from using the vscode implementation ([x] -> already implemented): - [x] Single click on project file opens tab as preview - [x] Double click on item in project panel opens tab as permanent - [x] Double click on the tab makes it permanent - [x] Navigating away from the tab makes the tab permanent and the new tab is shown as preview (e.g. GoToReference) - [x] Existing preview tab is reused when opening a new tab - [x] Dragging tab to the same/another panel makes the tab permanent - [x] Opening a tab from the file finder makes the tab permanent - [x] Editing a preview tab will make the tab permanent - [x] Using the space key in the project panel opens the tab as preview - [x] Handle navigation history correctly (restore a preview tab as preview as well) - [x] Restore preview tabs after restarting - [x] Support opening files from file finder in preview mode (vscode: "Enable Preview From Quick Open") I need to do some more testing of the vscode implementation, there might be other behaviors/workflows which im not aware of that open an item as preview/make them permanent. Showcase: https://github.com/zed-industries/zed/assets/53836821/9be16515-c740-4905-bea1-88871112ef86 TODOs - [x] Provide `enable_preview_tabs` setting - [x] Write some tests - [x] How should we handle this in collaboration mode (have not tested the behavior so far) - [x] Keyboard driven usage (probably need workspace commands) - [x] Register `TogglePreviewTab` only when setting enabled? - [x] Render preview tabs in tab switcher as italic - [x] Render preview tabs in image viewer as italic - [x] Should this be enabled by default (it is the default behavior in VSCode)? - [x] Docs Future improvements (out of scope for now): - Support preview mode for find all references and possibly other multibuffers (VSCode: "Enable Preview From Code Navigation") Release Notes: - Added preview tabs ([#4922](https://github.com/zed-industries/zed/issues/4922)). --------- Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com> |
||
---|---|---|
.. | ||
docs | ||
examples | ||
src | ||
tests | ||
build.rs | ||
Cargo.toml | ||
LICENSE-APACHE | ||
README.md |
Welcome to GPUI!
GPUI is a hybrid immediate and retained mode, GPU accelerated, UI framework for Rust, designed to support a wide variety of applications.
Getting Started
GPUI is still in active development as we work on the Zed code editor and isn't yet on crates.io. You'll also need to use the latest version of stable rust and be on macOS. Add the following to your Cargo.toml:
gpui = { git = "https://github.com/zed-industries/zed" }
Everything in GPUI starts with an App
. You can create one with App::new()
, and kick off your application by passing a callback to App::run()
. Inside this callback, you can create a new window with AppContext::open_window()
, and register your first root view. See gpui.rs for a complete example.
The Big Picture
GPUI offers three different registers depending on your needs:
-
State management and communication with Models. Whenever you need to store application state that communicates between different parts of your application, you'll want to use GPUI's models. Models are owned by GPUI and are only accessible through an owned smart pointer similar to an
Rc
. See theapp::model_context
module for more information. -
High level, declarative UI with Views. All UI in GPUI starts with a View. A view is simply a model that can be rendered, via the
Render
trait. At the start of each frame, GPUI will call this render method on the root view of a given window. Views build a tree ofelements
, lay them out and style them with a tailwind-style API, and then give them to GPUI to turn into pixels. See thediv
element for an all purpose swiss-army knife of rendering. -
Low level, imperative UI with Elements. Elements are the building blocks of UI in GPUI, and they provide a nice wrapper around an imperative API that provides as much flexibility and control as you need. Elements have total control over how they and their child elements are rendered and can be used for making efficient views into large lists, implement custom layouting for a code editor, and anything else you can think of. See the
element
module for more information.
Each of these registers has one or more corresponding contexts that can be accessed from all GPUI services. This context is your main interface to GPUI, and is used extensively throughout the framework.
Other Resources
In addition to the systems above, GPUI provides a range of smaller services that are useful for building complex applications:
-
Actions are user-defined structs that are used for converting keystrokes into logical operations in your UI. Use this for implementing keyboard shortcuts, such as cmd-q. See the
action
module for more information. -
Platform services, such as
quit the app
oropen a URL
are available as methods on theapp::AppContext
. -
An async executor that is integrated with the platform's event loop. See the
executor
module for more information., -
The
[gpui::test]
macro provides a convenient way to write tests for your GPUI applications. Tests also have their own kind of context, aTestAppContext
which provides ways of simulating common platform input. Seeapp::test_context
andtest
modules for more details.
Currently, the best way to learn about these APIs is to read the Zed source code, ask us about it at a fireside hack, or drop a question in the Zed Discord. We're working on improving the documentation, creating more examples, and will be publishing more guides to GPUI on our blog.