diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index e05837740d4c50fbe7e02e51272bd6340884ec8a..151b65f0fc394f743d36c92e6e161f343b98a28c 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -8305,6 +8305,7 @@ fn build_style( font_size, font_properties, underline: Default::default(), + soft_wrap: false, }, placeholder_text: None, line_height_scalar, diff --git a/crates/gpui/playground/ui/src/playground_ui.rs b/crates/gpui/playground/ui/src/playground_ui.rs index f29333a67ee54b39b01dee14080a2890bce27737..cf5559da2881051fee9accaa65dfc71a09d13512 100644 --- a/crates/gpui/playground/ui/src/playground_ui.rs +++ b/crates/gpui/playground/ui/src/playground_ui.rs @@ -1,6 +1,6 @@ use gpui::{ elements::node::{column, length::auto, row, text}, - AnyElement, Element, View, ViewContext, + AnyElement, Element, LayoutContext, View, ViewContext, }; use std::{borrow::Cow, marker::PhantomData}; use tokens::{margin::m4, text::lg}; @@ -58,22 +58,78 @@ impl> Dialog { } } -struct Button)> { +#[derive(Element)] +struct Button> { label: Cow<'static, str>, - on_click: Option, + click_handler: Option, + data: Option, view_type: PhantomData, } -fn button)>( - label: impl Into>, -) -> Button { +pub trait ClickHandler: 'static { + fn handle(&self, view: &mut V, data: &D, cx: &mut ViewContext); +} + +impl)> ClickHandler for F { + fn handle(&self, view: &mut V, data: &M, cx: &mut ViewContext) { + self(view, data, cx) + } +} + +impl ClickHandler for () { + fn handle(&self, view: &mut V, data: &D, cx: &mut ViewContext) {} +} + +fn button(label: impl Into>) -> Button +where + V: View, +{ Button { label: label.into(), - on_click: None, + click_handler: None, + data: None, view_type: PhantomData, } } +impl Button +where + V: View, + F: ClickHandler, +{ + fn render(&mut self, _: &mut V, _: &mut LayoutContext) -> AnyElement { + todo!() + } +} + +impl Button { + fn data(self, data: D) -> Button + where + D: 'static + FnOnce(&mut V, &D, &mut ViewContext), + { + Button { + label: self.label, + click_handler: self.click_handler, + data: Some(data), + view_type: self.view_type, + } + } +} + +impl Button { + fn click(self, handler: H) -> Button + where + H: 'static + Fn(&mut V, &D, &mut ViewContext), + { + Button { + label: self.label, + click_handler: Some(handler), + data: self.data, + view_type: self.view_type, + } + } +} + impl> Dialog { pub fn render(&mut self, _: &mut V, _: &mut gpui::ViewContext) -> AnyElement { column() diff --git a/crates/gpui/src/elements.rs b/crates/gpui/src/elements.rs index 88bea44a5dc6b10e887e305951abd23e600ad8da..34dffd9803aea662c7b60de84da3146539d24703 100644 --- a/crates/gpui/src/elements.rs +++ b/crates/gpui/src/elements.rs @@ -28,7 +28,11 @@ pub use self::{ }; pub use crate::window::ChildView; -use self::{clipped::Clipped, expanded::Expanded}; +use self::{ + clipped::Clipped, + expanded::Expanded, + node::{length::Length, node, Node}, +}; use crate::{ geometry::{ rect::RectF, @@ -200,6 +204,13 @@ pub trait Element: 'static { { MouseEventHandler::for_child(self.into_any(), region_id) } + + fn margin_left(self, margin_left: impl Into) -> Node + where + Self: Sized, + { + node(self).margin_left(margin_left) + } } trait AnyElementState { diff --git a/crates/gpui/src/elements/node.rs b/crates/gpui/src/elements/node.rs index c74032018aedabc06c8b0c45cdf086896e7c90bc..c324a4d55b5c178cd181de951b7eb2e56be1058e 100644 --- a/crates/gpui/src/elements/node.rs +++ b/crates/gpui/src/elements/node.rs @@ -24,6 +24,10 @@ pub struct Node { content: Vec>, } +pub fn node(child: impl Element) -> Node { + Node::default().child(child) +} + pub fn column() -> Node { Node::default() } @@ -119,13 +123,13 @@ impl Node { self } - pub fn margin_left(mut self, left: Length) -> Self { - self.style.margin.left = left; + pub fn margin_left(mut self, left: impl Into) -> Self { + self.style.margin.left = left.into(); self } - pub fn margin_right(mut self, right: Length) -> Self { - self.style.margin.right = right; + pub fn margin_right(mut self, right: impl Into) -> Self { + self.style.margin.right = right.into(); self } diff --git a/crates/language_tools/src/syntax_tree_view.rs b/crates/language_tools/src/syntax_tree_view.rs index 3e6727bbf4794eba1dc81d363c2b56a23c5e6a95..7a1e8ace6310ac991aac5cd3a0f5ce5acc631c67 100644 --- a/crates/language_tools/src/syntax_tree_view.rs +++ b/crates/language_tools/src/syntax_tree_view.rs @@ -373,6 +373,7 @@ impl View for SyntaxTreeView { font_size, font_properties: Default::default(), underline: Default::default(), + soft_wrap: false, }; let line_height = cx.font_cache().line_height(font_size); diff --git a/crates/terminal_view/src/terminal_element.rs b/crates/terminal_view/src/terminal_element.rs index 9c402d139a0d35f906f175da27334db4a60d28c1..a0dbd5e084a3d231e7724cb4a347e79c2e138002 100644 --- a/crates/terminal_view/src/terminal_element.rs +++ b/crates/terminal_view/src/terminal_element.rs @@ -562,6 +562,7 @@ impl Element for TerminalElement { font_size, font_properties: Default::default(), underline: Default::default(), + soft_wrap: false, }; let selection_color = settings.theme.editor.selection.selection; let match_color = settings.theme.search.match_background;