Add Sized bound to StyledExt trait (#3309)

This PR moves the `Sized` bound to the `StyledExt` trait so we don't
have to repeat it on each of the methods.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2023-11-13 11:22:49 -05:00 committed by GitHub
commit 71790b338b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 34 deletions

View File

@ -401,7 +401,7 @@ impl List {
v_stack() v_stack()
.w_full() .w_full()
.py_1() .py_1()
.children(self.header.map(|header| header)) .children(self.header)
.child(list_content) .child(list_content)
} }
} }

View File

@ -12,31 +12,22 @@ fn elevated<E: Styled, V: 'static>(this: E, cx: &mut ViewContext<V>, index: Elev
} }
/// Extends [`Styled`](gpui::Styled) with Zed specific styling methods. /// Extends [`Styled`](gpui::Styled) with Zed specific styling methods.
pub trait StyledExt: Styled { pub trait StyledExt: Styled + Sized {
/// Horizontally stacks elements. /// Horizontally stacks elements.
/// ///
/// Sets `flex()`, `flex_row()`, `items_center()` /// Sets `flex()`, `flex_row()`, `items_center()`
fn h_flex(self) -> Self fn h_flex(self) -> Self {
where
Self: Sized,
{
self.flex().flex_row().items_center() self.flex().flex_row().items_center()
} }
/// Vertically stacks elements. /// Vertically stacks elements.
/// ///
/// Sets `flex()`, `flex_col()` /// Sets `flex()`, `flex_col()`
fn v_flex(self) -> Self fn v_flex(self) -> Self {
where
Self: Sized,
{
self.flex().flex_col() self.flex().flex_col()
} }
fn text_ui_size(self, size: UITextSize) -> Self fn text_ui_size(self, size: UITextSize) -> Self {
where
Self: Sized,
{
let size = size.rems(); let size = size.rems();
self.text_size(size) self.text_size(size)
@ -49,10 +40,7 @@ pub trait StyledExt: Styled {
/// Note: The absolute size of this text will change based on a user's `ui_scale` setting. /// Note: The absolute size of this text will change based on a user's `ui_scale` setting.
/// ///
/// Use [`text_ui_sm`] for regular-sized text. /// Use [`text_ui_sm`] for regular-sized text.
fn text_ui(self) -> Self fn text_ui(self) -> Self {
where
Self: Sized,
{
let size = UITextSize::default().rems(); let size = UITextSize::default().rems();
self.text_size(size) self.text_size(size)
@ -65,10 +53,7 @@ pub trait StyledExt: Styled {
/// Note: The absolute size of this text will change based on a user's `ui_scale` setting. /// Note: The absolute size of this text will change based on a user's `ui_scale` setting.
/// ///
/// Use [`text_ui`] for regular-sized text. /// Use [`text_ui`] for regular-sized text.
fn text_ui_sm(self) -> Self fn text_ui_sm(self) -> Self {
where
Self: Sized,
{
let size = UITextSize::Small.rems(); let size = UITextSize::Small.rems();
self.text_size(size) self.text_size(size)
@ -79,10 +64,7 @@ pub trait StyledExt: Styled {
/// Sets `bg()`, `rounded_lg()`, `border()`, `border_color()`, `shadow()` /// Sets `bg()`, `rounded_lg()`, `border()`, `border_color()`, `shadow()`
/// ///
/// Example Elements: Title Bar, Panel, Tab Bar, Editor /// Example Elements: Title Bar, Panel, Tab Bar, Editor
fn elevation_1<V: 'static>(self, cx: &mut ViewContext<V>) -> Self fn elevation_1<V: 'static>(self, cx: &mut ViewContext<V>) -> Self {
where
Self: Styled + Sized,
{
elevated(self, cx, ElevationIndex::Surface) elevated(self, cx, ElevationIndex::Surface)
} }
@ -91,10 +73,7 @@ pub trait StyledExt: Styled {
/// Sets `bg()`, `rounded_lg()`, `border()`, `border_color()`, `shadow()` /// Sets `bg()`, `rounded_lg()`, `border()`, `border_color()`, `shadow()`
/// ///
/// Examples: Notifications, Palettes, Detached/Floating Windows, Detached/Floating Panels /// Examples: Notifications, Palettes, Detached/Floating Windows, Detached/Floating Panels
fn elevation_2<V: 'static>(self, cx: &mut ViewContext<V>) -> Self fn elevation_2<V: 'static>(self, cx: &mut ViewContext<V>) -> Self {
where
Self: Styled + Sized,
{
elevated(self, cx, ElevationIndex::ElevatedSurface) elevated(self, cx, ElevationIndex::ElevatedSurface)
} }
@ -109,10 +88,7 @@ pub trait StyledExt: Styled {
/// Sets `bg()`, `rounded_lg()`, `border()`, `border_color()`, `shadow()` /// Sets `bg()`, `rounded_lg()`, `border()`, `border_color()`, `shadow()`
/// ///
/// Examples: Settings Modal, Channel Management, Wizards/Setup UI, Dialogs /// Examples: Settings Modal, Channel Management, Wizards/Setup UI, Dialogs
fn elevation_4<V: 'static>(self, cx: &mut ViewContext<V>) -> Self fn elevation_4<V: 'static>(self, cx: &mut ViewContext<V>) -> Self {
where
Self: Styled + Sized,
{
elevated(self, cx, ElevationIndex::ModalSurface) elevated(self, cx, ElevationIndex::ModalSurface)
} }
} }