
There's still a bit more work to do on this, but this PR is compiling (with warnings) after eliminating the key types. When the tasks below are complete, this will be the new narrative for GPUI: - `Entity<T>` - This replaces `View<T>`/`Model<T>`. It represents a unit of state, and if `T` implements `Render`, then `Entity<T>` implements `Element`. - `&mut App` This replaces `AppContext` and represents the app. - `&mut Context<T>` This replaces `ModelContext` and derefs to `App`. It is provided by the framework when updating an entity. - `&mut Window` Broken out of `&mut WindowContext` which no longer exists. Every method that once took `&mut WindowContext` now takes `&mut Window, &mut App` and every method that took `&mut ViewContext<T>` now takes `&mut Window, &mut Context<T>` Not pictured here are the two other failed attempts. It's been quite a month! Tasks: - [x] Remove `View`, `ViewContext`, `WindowContext` and thread through `Window` - [x] [@cole-miller @mikayla-maki] Redraw window when entities change - [x] [@cole-miller @mikayla-maki] Get examples and Zed running - [x] [@cole-miller @mikayla-maki] Fix Zed rendering - [x] [@mikayla-maki] Fix todo! macros and comments - [x] Fix a bug where the editor would not be redrawn because of view caching - [x] remove publicness window.notify() and replace with `AppContext::notify` - [x] remove `observe_new_window_models`, replace with `observe_new_models` with an optional window - [x] Fix a bug where the project panel would not be redrawn because of the wrong refresh() call being used - [x] Fix the tests - [x] Fix warnings by eliminating `Window` params or using `_` - [x] Fix conflicts - [x] Simplify generic code where possible - [x] Rename types - [ ] Update docs ### issues post merge - [x] Issues switching between normal and insert mode - [x] Assistant re-rendering failure - [x] Vim test failures - [x] Mac build issue Release Notes: - N/A --------- Co-authored-by: Antonio Scandurra <me@as-cii.com> Co-authored-by: Cole Miller <cole@zed.dev> Co-authored-by: Mikayla <mikayla@zed.dev> Co-authored-by: Joseph <joseph@zed.dev> Co-authored-by: max <max@zed.dev> Co-authored-by: Michael Sloan <michael@zed.dev> Co-authored-by: Mikayla Maki <mikaylamaki@Mikaylas-MacBook-Pro.local> Co-authored-by: Mikayla <mikayla.c.maki@gmail.com> Co-authored-by: joão <joao@zed.dev>
181 lines
4.2 KiB
Rust
181 lines
4.2 KiB
Rust
#![allow(missing_docs)]
|
|
|
|
use gpui::{App, StyleRefinement, Window};
|
|
|
|
use crate::{prelude::*, LabelCommon, LabelLike, LabelSize, LineHeightStyle};
|
|
|
|
/// A struct representing a label element in the UI.
|
|
///
|
|
/// The `Label` struct stores the label text and common properties for a label element.
|
|
/// It provides methods for modifying these properties.
|
|
///
|
|
/// # Examples
|
|
///
|
|
/// ```
|
|
/// use ui::prelude::*;
|
|
///
|
|
/// Label::new("Hello, World!");
|
|
/// ```
|
|
///
|
|
/// **A colored label**, for example labeling a dangerous action:
|
|
///
|
|
/// ```
|
|
/// use ui::prelude::*;
|
|
///
|
|
/// let my_label = Label::new("Delete").color(Color::Error);
|
|
/// ```
|
|
///
|
|
/// **A label with a strikethrough**, for example labeling something that has been deleted:
|
|
///
|
|
/// ```
|
|
/// use ui::prelude::*;
|
|
///
|
|
/// let my_label = Label::new("Deleted").strikethrough(true);
|
|
/// ```
|
|
#[derive(IntoElement)]
|
|
pub struct Label {
|
|
base: LabelLike,
|
|
label: SharedString,
|
|
}
|
|
|
|
impl Label {
|
|
/// Creates a new [`Label`] with the given text.
|
|
///
|
|
/// # Examples
|
|
///
|
|
/// ```
|
|
/// use ui::prelude::*;
|
|
///
|
|
/// let my_label = Label::new("Hello, World!");
|
|
/// ```
|
|
pub fn new(label: impl Into<SharedString>) -> Self {
|
|
Self {
|
|
base: LabelLike::new(),
|
|
label: label.into(),
|
|
}
|
|
}
|
|
}
|
|
|
|
// Style methods.
|
|
impl Label {
|
|
fn style(&mut self) -> &mut StyleRefinement {
|
|
self.base.base.style()
|
|
}
|
|
|
|
gpui::margin_style_methods!({
|
|
visibility: pub
|
|
});
|
|
}
|
|
|
|
impl LabelCommon for Label {
|
|
/// Sets the size of the label using a [`LabelSize`].
|
|
///
|
|
/// # Examples
|
|
///
|
|
/// ```
|
|
/// use ui::prelude::*;
|
|
///
|
|
/// let my_label = Label::new("Hello, World!").size(LabelSize::Small);
|
|
/// ```
|
|
fn size(mut self, size: LabelSize) -> Self {
|
|
self.base = self.base.size(size);
|
|
self
|
|
}
|
|
|
|
fn weight(mut self, weight: gpui::FontWeight) -> Self {
|
|
self.base = self.base.weight(weight);
|
|
self
|
|
}
|
|
|
|
/// Sets the line height style of the label using a [`LineHeightStyle`].
|
|
///
|
|
/// # Examples
|
|
///
|
|
/// ```
|
|
/// use ui::prelude::*;
|
|
///
|
|
/// let my_label = Label::new("Hello, World!").line_height_style(LineHeightStyle::UiLabel);
|
|
/// ```
|
|
fn line_height_style(mut self, line_height_style: LineHeightStyle) -> Self {
|
|
self.base = self.base.line_height_style(line_height_style);
|
|
self
|
|
}
|
|
|
|
/// Sets the color of the label using a [`Color`].
|
|
///
|
|
/// # Examples
|
|
///
|
|
/// ```
|
|
/// use ui::prelude::*;
|
|
///
|
|
/// let my_label = Label::new("Hello, World!").color(Color::Accent);
|
|
/// ```
|
|
fn color(mut self, color: Color) -> Self {
|
|
self.base = self.base.color(color);
|
|
self
|
|
}
|
|
|
|
/// Sets the strikethrough property of the label.
|
|
///
|
|
/// # Examples
|
|
///
|
|
/// ```
|
|
/// use ui::prelude::*;
|
|
///
|
|
/// let my_label = Label::new("Hello, World!").strikethrough(true);
|
|
/// ```
|
|
fn strikethrough(mut self, strikethrough: bool) -> Self {
|
|
self.base = self.base.strikethrough(strikethrough);
|
|
self
|
|
}
|
|
|
|
/// Sets the italic property of the label.
|
|
///
|
|
/// # Examples
|
|
///
|
|
/// ```
|
|
/// use ui::prelude::*;
|
|
///
|
|
/// let my_label = Label::new("Hello, World!").italic(true);
|
|
/// ```
|
|
fn italic(mut self, italic: bool) -> Self {
|
|
self.base = self.base.italic(italic);
|
|
self
|
|
}
|
|
|
|
/// Sets the alpha property of the color of label.
|
|
///
|
|
/// # Examples
|
|
///
|
|
/// ```
|
|
/// use ui::prelude::*;
|
|
///
|
|
/// let my_label = Label::new("Hello, World!").alpha(0.5);
|
|
/// ```
|
|
fn alpha(mut self, alpha: f32) -> Self {
|
|
self.base = self.base.alpha(alpha);
|
|
self
|
|
}
|
|
|
|
fn underline(mut self, underline: bool) -> Self {
|
|
self.base = self.base.underline(underline);
|
|
self
|
|
}
|
|
|
|
fn text_ellipsis(mut self) -> Self {
|
|
self.base = self.base.text_ellipsis();
|
|
self
|
|
}
|
|
|
|
fn single_line(mut self) -> Self {
|
|
self.label = SharedString::from(self.label.replace('\n', ""));
|
|
self.base = self.base.single_line();
|
|
self
|
|
}
|
|
}
|
|
|
|
impl RenderOnce for Label {
|
|
fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement {
|
|
self.base.child(self.label)
|
|
}
|
|
}
|