chore: Update to use Rust edition 2024. (#1669)

This commit is contained in:
Jason Lee 2025-11-24 14:38:43 +08:00 committed by GitHub
parent af51057d52
commit f2cbc16655
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 133 additions and 128 deletions

View file

@ -17,6 +17,10 @@ members = [
] ]
resolver = "2" resolver = "2"
[workspace.package]
publish = false
edition = "2024"
[workspace.dependencies] [workspace.dependencies]
gpui-component = { path = "crates/ui", version = "0.4.1" } gpui-component = { path = "crates/ui", version = "0.4.1" }
gpui-component-macros = { path = "crates/macros", version = "0.4.1" } gpui-component-macros = { path = "crates/macros", version = "0.4.1" }

View file

@ -1,14 +1,14 @@
[package] [package]
name = "gpui-component-assets" name = "gpui-component-assets"
description = "Default bundled assets for GPUI Component." description = "Default bundled assets for GPUI Component."
edition = "2021"
keywords = ["desktop", "gpui", "shadcn", "ui", "uikit"] keywords = ["desktop", "gpui", "shadcn", "ui", "uikit"]
license = "Apache-2.0" license = "Apache-2.0"
documentation = "https://docs.rs/gpui-component" documentation = "https://docs.rs/gpui-component"
homepage = "https://longbridge.github.io/gpui-component" homepage = "https://longbridge.github.io/gpui-component"
repository = "https://github.com/longbridge/gpui-component" repository = "https://github.com/longbridge/gpui-component"
publish = true
readme = "README.md" readme = "README.md"
edition.workspace = true
publish = true
version = "0.4.1" version = "0.4.1"
[lib] [lib]

View file

@ -1,10 +1,10 @@
[package] [package]
edition = "2021"
name = "gpui-component-macros" name = "gpui-component-macros"
description = "Macros for GPUI Component." description = "Macros for GPUI Component."
version = "0.4.1" version = "0.4.1"
publish = true
license = "Apache-2.0" license = "Apache-2.0"
publish = true
edition.workspace = true
[lib] [lib]
proc-macro = true proc-macro = true

View file

@ -1,9 +1,9 @@
[package] [package]
name = "reqwest_client" name = "reqwest_client"
version = "0.4.1" version = "0.4.1"
publish = false
license = "Apache-2.0" license = "Apache-2.0"
edition = "2024" publish = false
edition.workspace = true
[lints] [lints]
workspace = true workspace = true

View file

@ -1,8 +1,8 @@
[package] [package]
edition = "2024"
name = "gpui-component-story" name = "gpui-component-story"
publish = false
version = "0.4.1" version = "0.4.1"
publish = false
edition.workspace = true
[features] [features]
inspector = ["gpui-component/inspector"] inspector = ["gpui-component/inspector"]

View file

@ -1,15 +1,15 @@
[package] [package]
description = "UI components for building fantastic desktop application by using GPUI." description = "UI components for building fantastic desktop application by using GPUI."
edition = "2021"
keywords = ["desktop", "gpui", "shadcn", "ui", "uikit"] keywords = ["desktop", "gpui", "shadcn", "ui", "uikit"]
license = "Apache-2.0" license = "Apache-2.0"
name = "gpui-component" name = "gpui-component"
documentation = "https://docs.rs/gpui-component" documentation = "https://docs.rs/gpui-component"
homepage = "https://longbridge.github.io/gpui-component" homepage = "https://longbridge.github.io/gpui-component"
repository = "https://github.com/longbridge/gpui-component" repository = "https://github.com/longbridge/gpui-component"
publish = true
readme = "../../README.md" readme = "../../README.md"
version = "0.4.1" version = "0.4.1"
publish = true
edition.workspace = true
[lib] [lib]
doctest = false doctest = false

View file

@ -1,20 +1,21 @@
use gpui::{ use gpui::{
anchored, canvas, deferred, div, prelude::FluentBuilder as _, px, relative, App, AppContext, App, AppContext, Bounds, ClickEvent, Context, Corner, Div, ElementId, Entity, EventEmitter,
Bounds, ClickEvent, Context, Corner, ElementId, Entity, EventEmitter, FocusHandle, Focusable, FocusHandle, Focusable, Hsla, InteractiveElement as _, IntoElement, KeyBinding, MouseButton,
Hsla, InteractiveElement as _, IntoElement, KeyBinding, MouseButton, ParentElement, Pixels, ParentElement, Pixels, Point, Render, RenderOnce, SharedString, Stateful,
Point, Render, RenderOnce, SharedString, StatefulInteractiveElement as _, StyleRefinement, StatefulInteractiveElement as _, StyleRefinement, Styled, Subscription, Window, anchored,
Styled, Subscription, Window, canvas, deferred, div, prelude::FluentBuilder as _, px, relative,
}; };
use crate::{ use crate::{
ActiveTheme as _, Colorize as _, FocusableExt as _, Icon, Selectable as _, Sizable, Size,
StyleSized, StyledExt,
actions::{Cancel, Confirm}, actions::{Cancel, Confirm},
button::{Button, ButtonVariants}, button::{Button, ButtonVariants},
divider::Divider, divider::Divider,
h_flex, h_flex,
input::{Input, InputEvent, InputState}, input::{Input, InputEvent, InputState},
tooltip::Tooltip, tooltip::Tooltip,
v_flex, ActiveTheme as _, Colorize as _, FocusableExt as _, Icon, Selectable as _, Sizable, v_flex,
Size, StyleSized, StyledExt,
}; };
const CONTEXT: &'static str = "ColorPicker"; const CONTEXT: &'static str = "ColorPicker";
@ -250,7 +251,7 @@ impl ColorPicker {
clickable: bool, clickable: bool,
window: &mut Window, window: &mut Window,
_: &mut App, _: &mut App,
) -> impl IntoElement { ) -> Stateful<Div> {
let state = self.state.clone(); let state = self.state.clone();
div() div()
.id(SharedString::from(format!("color-{}", color.to_hex()))) .id(SharedString::from(format!("color-{}", color.to_hex())))

View file

@ -1,20 +1,21 @@
use std::sync::Arc; use std::sync::Arc;
use gpui::{ use gpui::{
div, prelude::FluentBuilder, px, relative, rems, App, AppContext, Context, Corner, App, AppContext, Context, Corner, DismissEvent, Div, DragMoveEvent, Empty, Entity,
DismissEvent, Div, DragMoveEvent, Empty, Entity, EventEmitter, FocusHandle, Focusable, EventEmitter, FocusHandle, Focusable, InteractiveElement as _, IntoElement, ParentElement,
InteractiveElement as _, IntoElement, ParentElement, Pixels, Render, ScrollHandle, Pixels, Render, ScrollHandle, SharedString, StatefulInteractiveElement, StyleRefinement,
SharedString, StatefulInteractiveElement, StyleRefinement, Styled, WeakEntity, Window, Styled, WeakEntity, Window, div, prelude::FluentBuilder, px, relative, rems,
}; };
use rust_i18n::t; use rust_i18n::t;
use crate::{ use crate::{
ActiveTheme, AxisExt, IconName, Placement, Selectable, Sizable,
button::{Button, ButtonVariants as _}, button::{Button, ButtonVariants as _},
dock::PanelInfo, dock::PanelInfo,
h_flex, h_flex,
menu::{DropdownMenu, PopupMenu}, menu::{DropdownMenu, PopupMenu},
tab::{Tab, TabBar}, tab::{Tab, TabBar},
v_flex, ActiveTheme, AxisExt, IconName, Placement, Selectable, Sizable, v_flex,
}; };
use super::{ use super::{
@ -508,7 +509,7 @@ impl TabPanel {
placement: DockPlacement, placement: DockPlacement,
_: &mut Window, _: &mut Window,
cx: &mut Context<Self>, cx: &mut Context<Self>,
) -> Option<impl IntoElement> { ) -> Option<Button> {
if self.zoomed { if self.zoomed {
return None; return None;
} }

View file

@ -5,21 +5,21 @@ use std::{
}; };
use crate::{ use crate::{
h_flex, ActiveTheme, Icon, IconName, h_flex,
history::{History, HistoryItem}, history::{History, HistoryItem},
scroll::{Scrollbar, ScrollbarShow, ScrollbarState}, scroll::{Scrollbar, ScrollbarShow, ScrollbarState},
v_flex, ActiveTheme, Icon, IconName, v_flex,
}; };
use super::{ use super::{
DockArea, Panel, PanelEvent, PanelInfo, PanelState, PanelView, StackPanel, TabPanel, TileMeta, DockArea, Panel, PanelEvent, PanelInfo, PanelState, PanelView, StackPanel, TabPanel, TileMeta,
}; };
use gpui::{ use gpui::{
actions, canvas, div, prelude::FluentBuilder, px, size, AnyElement, App, AppContext, Bounds, AnyElement, App, AppContext, Bounds, Context, DismissEvent, Div, DragMoveEvent, Empty,
Context, DismissEvent, DragMoveEvent, Empty, EntityId, EventEmitter, FocusHandle, Focusable, EntityId, EventEmitter, FocusHandle, Focusable, InteractiveElement, IntoElement, MouseButton,
InteractiveElement, IntoElement, MouseButton, MouseDownEvent, MouseUpEvent, ParentElement, MouseDownEvent, MouseUpEvent, ParentElement, Pixels, Point, Render, ScrollHandle, Size,
Pixels, Point, Render, ScrollHandle, Size, StatefulInteractiveElement, Styled, WeakEntity, StatefulInteractiveElement, Styled, WeakEntity, Window, actions, canvas, div,
Window, prelude::FluentBuilder, px, size,
}; };
actions!(tiles, [Undo, Redo]); actions!(tiles, [Undo, Redo]);
@ -1030,7 +1030,7 @@ impl Tiles {
item: &TileItem, item: &TileItem,
window: &mut Window, window: &mut Window,
cx: &mut Context<Self>, cx: &mut Context<Self>,
) -> impl IntoElement { ) -> Div {
let entity_id = cx.entity_id(); let entity_id = cx.entity_id();
let item_id = item.id; let item_id = item.id;
let panel_view = item.panel.view(); let panel_view = item.panel.view();

View file

@ -11,13 +11,13 @@ pub(crate) use diagnostic_popover::*;
pub(crate) use hover_popover::*; pub(crate) use hover_popover::*;
use gpui::{ use gpui::{
div, px, rems, App, Div, ElementId, Entity, InteractiveElement as _, IntoElement, SharedString, App, Div, ElementId, Entity, InteractiveElement as _, IntoElement, SharedString, Stateful,
Stateful, StyleRefinement, Styled as _, Window, StyleRefinement, Styled as _, Window, div, px, rems,
}; };
use crate::{ use crate::{
text::{TextView, TextViewStyle},
ActiveTheme, StyledExt as _, ActiveTheme, StyledExt as _,
text::{TextView, TextViewStyle},
}; };
pub(crate) enum ContextMenu { pub(crate) enum ContextMenu {
@ -49,7 +49,7 @@ pub(super) fn render_markdown(
markdown: impl Into<SharedString>, markdown: impl Into<SharedString>,
window: &mut Window, window: &mut Window,
cx: &mut App, cx: &mut App,
) -> impl IntoElement { ) -> TextView {
TextView::markdown(id, markdown, window, cx) TextView::markdown(id, markdown, window, cx)
.style( .style(
TextViewStyle::default() TextViewStyle::default()

View file

@ -2,13 +2,13 @@ use crate::actions::{Cancel, Confirm, SelectDown, SelectUp};
use crate::actions::{SelectLeft, SelectRight}; use crate::actions::{SelectLeft, SelectRight};
use crate::menu::menu_item::MenuItemElement; use crate::menu::menu_item::MenuItemElement;
use crate::scroll::{Scrollbar, ScrollbarState}; use crate::scroll::{Scrollbar, ScrollbarState};
use crate::{h_flex, v_flex, ActiveTheme, Icon, IconName, Sizable as _}; use crate::{ActiveTheme, Icon, IconName, Sizable as _, h_flex, v_flex};
use crate::{kbd::Kbd, Side, Size, StyledExt}; use crate::{Side, Size, StyledExt, kbd::Kbd};
use gpui::{ use gpui::{
anchored, canvas, div, prelude::FluentBuilder, px, rems, Action, AnyElement, App, AppContext, Action, AnyElement, App, AppContext, Bounds, Context, Corner, DismissEvent, Edges, Entity,
Bounds, Context, Corner, DismissEvent, Edges, Entity, EventEmitter, FocusHandle, Focusable, EventEmitter, FocusHandle, Focusable, InteractiveElement, IntoElement, KeyBinding,
InteractiveElement, IntoElement, KeyBinding, ParentElement, Pixels, Render, ScrollHandle, ParentElement, Pixels, Render, ScrollHandle, SharedString, StatefulInteractiveElement, Styled,
SharedString, StatefulInteractiveElement, Styled, WeakEntity, Window, WeakEntity, Window, anchored, canvas, div, prelude::FluentBuilder, px, rems,
}; };
use gpui::{ClickEvent, Half, MouseDownEvent, OwnedMenuItem, Subscription}; use gpui::{ClickEvent, Half, MouseDownEvent, OwnedMenuItem, Subscription};
use std::rc::Rc; use std::rc::Rc;
@ -944,7 +944,7 @@ impl PopupMenu {
action: Option<Box<dyn Action>>, action: Option<Box<dyn Action>>,
window: &mut Window, window: &mut Window,
_: &mut Context<Self>, _: &mut Context<Self>,
) -> Option<impl IntoElement> { ) -> Option<Kbd> {
let action = action?; let action = action?;
match self match self
@ -1013,7 +1013,7 @@ impl PopupMenu {
state: ItemState, state: ItemState,
window: &mut Window, window: &mut Window,
cx: &mut Context<Self>, cx: &mut Context<Self>,
) -> impl IntoElement { ) -> MenuItemElement {
let has_icon = self.has_icon; let has_icon = self.has_icon;
let selected = self.selected_index == Some(ix); let selected = self.selected_index == Some(ix);
const EDGE_PADDING: Pixels = px(4.); const EDGE_PADDING: Pixels = px(4.);

View file

@ -1,14 +1,15 @@
use crate::{ use crate::{
ActiveTheme, Placement,
dialog::Dialog, dialog::Dialog,
input::InputState, input::InputState,
notification::{Notification, NotificationList}, notification::{Notification, NotificationList},
sheet::Sheet, sheet::Sheet,
window_border, ActiveTheme, Placement, window_border,
}; };
use gpui::{ use gpui::{
actions, canvas, div, prelude::FluentBuilder as _, AnyView, App, AppContext, Context, AnyView, App, AppContext, Context, DefiniteLength, Entity, FocusHandle, InteractiveElement,
DefiniteLength, Entity, FocusHandle, InteractiveElement, IntoElement, KeyBinding, IntoElement, KeyBinding, ParentElement as _, Render, Styled, Window, actions, canvas, div,
ParentElement as _, Render, Styled, Window, prelude::FluentBuilder as _,
}; };
use std::{any::TypeId, rc::Rc}; use std::{any::TypeId, rc::Rc};
@ -278,7 +279,7 @@ impl Root {
pub fn render_notification_layer( pub fn render_notification_layer(
window: &mut Window, window: &mut Window,
cx: &mut App, cx: &mut App,
) -> Option<impl IntoElement> { ) -> Option<impl IntoElement + use<>> {
let root = window.root::<Root>()??; let root = window.root::<Root>()??;
let active_sheet_placement = root.read(cx).active_sheet.clone().map(|d| d.placement); let active_sheet_placement = root.read(cx).active_sheet.clone().map(|d| d.placement);
@ -301,7 +302,10 @@ impl Root {
} }
/// Render the Sheet layer. /// Render the Sheet layer.
pub fn render_sheet_layer(window: &mut Window, cx: &mut App) -> Option<impl IntoElement> { pub fn render_sheet_layer(
window: &mut Window,
cx: &mut App,
) -> Option<impl IntoElement + use<>> {
let root = window.root::<Root>()??; let root = window.root::<Root>()??;
if let Some(active_sheet) = root.read(cx).active_sheet.clone() { if let Some(active_sheet) = root.read(cx).active_sheet.clone() {
@ -328,7 +332,10 @@ impl Root {
} }
/// Render the Dialog layer. /// Render the Dialog layer.
pub fn render_dialog_layer(window: &mut Window, cx: &mut App) -> Option<impl IntoElement> { pub fn render_dialog_layer(
window: &mut Window,
cx: &mut App,
) -> Option<impl IntoElement + use<>> {
let root = window.root::<Root>()??; let root = window.root::<Root>()??;
let active_dialogs = root.read(cx).active_dialogs.clone(); let active_dialogs = root.read(cx).active_dialogs.clone();

View file

@ -1,17 +1,18 @@
use gpui::{ use gpui::{
div, prelude::FluentBuilder as _, AnyElement, App, Axis, InteractiveElement as _, IntoElement, AnyElement, App, Axis, Div, InteractiveElement as _, IntoElement, ParentElement, SharedString,
ParentElement, SharedString, Styled, Window, Stateful, Styled, Window, div, prelude::FluentBuilder as _,
}; };
use std::{any::TypeId, ops::Deref, rc::Rc}; use std::{any::TypeId, ops::Deref, rc::Rc};
use crate::{ use crate::{
ActiveTheme as _, AxisExt, StyledExt as _,
label::Label, label::Label,
setting::{ setting::{
fields::{BoolField, DropdownField, NumberField, SettingFieldRender, StringField},
AnySettingField, ElementField, RenderOptions, AnySettingField, ElementField, RenderOptions,
fields::{BoolField, DropdownField, NumberField, SettingFieldRender, StringField},
}, },
text::Text, text::Text,
v_flex, ActiveTheme as _, AxisExt, StyledExt as _, v_flex,
}; };
/// Setting item. /// Setting item.
@ -153,7 +154,7 @@ impl SettingItem {
options: &RenderOptions, options: &RenderOptions,
window: &mut Window, window: &mut Window,
cx: &mut App, cx: &mut App,
) -> impl IntoElement { ) -> Stateful<Div> {
div() div()
.id(SharedString::from(format!("item-{}", ix))) .id(SharedString::from(format!("item-{}", ix)))
.w_full() .w_full()

View file

@ -1,18 +1,19 @@
use std::{ops::Range, rc::Rc, time::Duration}; use std::{ops::Range, rc::Rc, time::Duration};
use crate::{ use crate::{
ActiveTheme, Icon, IconName, StyleSized as _, StyledExt, VirtualListScrollHandle,
actions::{Cancel, SelectDown, SelectUp}, actions::{Cancel, SelectDown, SelectUp},
h_flex, h_flex,
menu::{ContextMenuExt, PopupMenu}, menu::{ContextMenuExt, PopupMenu},
scroll::{ScrollableMask, Scrollbar, ScrollbarState}, scroll::{ScrollableMask, Scrollbar, ScrollbarState},
v_flex, ActiveTheme, Icon, IconName, StyleSized as _, StyledExt, VirtualListScrollHandle, v_flex,
}; };
use gpui::{ use gpui::{
canvas, div, prelude::FluentBuilder, px, uniform_list, AppContext, Axis, Bounds, ClickEvent, AppContext, Axis, Bounds, ClickEvent, Context, Div, DragMoveEvent, EventEmitter, FocusHandle,
Context, Div, DragMoveEvent, EventEmitter, FocusHandle, Focusable, InteractiveElement, Focusable, InteractiveElement, IntoElement, ListSizingBehavior, MouseButton, MouseDownEvent,
IntoElement, ListSizingBehavior, MouseButton, MouseDownEvent, ParentElement, Pixels, Point, ParentElement, Pixels, Point, Render, ScrollStrategy, SharedString, Stateful,
Render, ScrollStrategy, SharedString, StatefulInteractiveElement as _, Styled, Task, StatefulInteractiveElement as _, Styled, Task, UniformListScrollHandle, Window, canvas, div,
UniformListScrollHandle, Window, prelude::FluentBuilder, px, uniform_list,
}; };
use super::*; use super::*;
@ -791,12 +792,7 @@ where
/// The children must be one by one items. /// The children must be one by one items.
/// Because the horizontal scroll handle will use the child_item_bounds to /// Because the horizontal scroll handle will use the child_item_bounds to
/// calculate the item position for itself's `scroll_to_item` method. /// calculate the item position for itself's `scroll_to_item` method.
fn render_th( fn render_th(&self, col_ix: usize, window: &mut Window, cx: &mut Context<Self>) -> Div {
&self,
col_ix: usize,
window: &mut Window,
cx: &mut Context<Self>,
) -> impl IntoElement {
let entity_id = cx.entity_id(); let entity_id = cx.entity_id();
let col_group = self.col_groups.get(col_ix).expect("BUG: invalid col index"); let col_group = self.col_groups.get(col_ix).expect("BUG: invalid col index");
@ -970,7 +966,7 @@ where
is_filled: bool, is_filled: bool,
window: &mut Window, window: &mut Window,
cx: &mut Context<Self>, cx: &mut Context<Self>,
) -> impl IntoElement { ) -> Stateful<Div> {
let horizontal_scroll_handle = self.horizontal_scroll_handle.clone(); let horizontal_scroll_handle = self.horizontal_scroll_handle.clone();
let is_stripe_row = self.options.stripe && row_ix % 2 != 0; let is_stripe_row = self.options.stripe && row_ix % 2 != 0;
let is_selected = self.selected_row == Some(row_ix); let is_selected = self.selected_row == Some(row_ix);

View file

@ -5,9 +5,9 @@ use std::collections::HashMap;
use std::ops::Range; use std::ops::Range;
use std::rc::Rc; use std::rc::Rc;
use gpui::{px, relative, DefiniteLength, SharedString}; use gpui::{DefiniteLength, SharedString, px, relative};
use html5ever::tendril::TendrilSink; use html5ever::tendril::TendrilSink;
use html5ever::{local_name, parse_document, LocalName, ParseOpts}; use html5ever::{LocalName, ParseOpts, local_name, parse_document};
use markup5ever_rcdom::{Node, NodeData, RcDom}; use markup5ever_rcdom::{Node, NodeData, RcDom};
use crate::text::node::{ use crate::text::node::{
@ -252,7 +252,7 @@ fn parse_paragraph(
} }
match &node.data { match &node.data {
NodeData::Text { ref contents } => { NodeData::Text { contents } => {
let part = &contents.borrow(); let part = &contents.borrow();
text.push_str(&part); text.push_str(&part);
paragraph.push_str(&text); paragraph.push_str(&text);

View file

@ -6,9 +6,8 @@
use std::{cell::RefCell, io, rc::Rc, str}; use std::{cell::RefCell, io, rc::Rc, str};
use html5ever::{ use html5ever::{
parse_document, Attribute, ParseOpts, QualName, parse_document,
tendril::{fmt::UTF8, Tendril, TendrilSink}, tendril::{Tendril, TendrilSink, fmt::UTF8},
Attribute, ParseOpts, QualName,
}; };
use markup5ever_rcdom::{Node, NodeData, RcDom}; use markup5ever_rcdom::{Node, NodeData, RcDom};
@ -697,7 +696,7 @@ fn is_block_element_name(name: &str) -> bool {
fn is_block_element(node: &Node) -> bool { fn is_block_element(node: &Node) -> bool {
match &node.data { match &node.data {
NodeData::Element { ref name, .. } => is_block_element_name(name.local.as_ref()), NodeData::Element { name, .. } => is_block_element_name(name.local.as_ref()),
NodeData::Document => true, NodeData::Document => true,
_ => false, _ => false,
} }
@ -877,19 +876,24 @@ mod tests {
true, true,
), ),
// Retain end tag if touching inline element // Retain end tag if touching inline element
("<p>Some text</p><button></button>", "<p>Some text</p><button></button>", false, false), (
"<p>Some text</p><button></button>",
"<p>Some text</p><button></button>",
false,
false,
),
] { ] {
let mut w = vec![]; let mut w = vec![];
let mut minifier = Minifier::new(&mut w); let mut minifier = Minifier::new(&mut w);
minifier minifier
.omit_doctype(true) .omit_doctype(true)
.collapse_whitespace(collapse_whitespace) .collapse_whitespace(collapse_whitespace)
.preserve_comments(preserve_comments); .preserve_comments(preserve_comments);
minifier.minify(&mut input.as_bytes()).unwrap(); minifier.minify(&mut input.as_bytes()).unwrap();
let s = str::from_utf8(&w).unwrap(); let s = str::from_utf8(&w).unwrap();
assert_eq!(expected, s); assert_eq!(expected, s);
} }
} }
} }

View file

@ -5,23 +5,23 @@ use std::{
}; };
use gpui::{ use gpui::{
div, img, prelude::FluentBuilder as _, px, relative, rems, AnyElement, App, DefiniteLength, AnyElement, App, DefiniteLength, Div, Element, ElementId, FontStyle, FontWeight, Half,
Div, Element, ElementId, FontStyle, FontWeight, Half, HighlightStyle, InteractiveElement as _, HighlightStyle, InteractiveElement as _, IntoElement, Length, ListState, ObjectFit,
IntoElement, Length, ListState, ObjectFit, ParentElement, SharedString, SharedUri, ParentElement, SharedString, SharedUri, StatefulInteractiveElement, Styled, StyledImage as _,
StatefulInteractiveElement, Styled, StyledImage as _, Window, Window, div, img, prelude::FluentBuilder as _, px, relative, rems,
}; };
use markdown::mdast; use markdown::mdast;
use ropey::Rope; use ropey::Rope;
use crate::{ use crate::{
h_flex, ActiveTheme as _, Icon, IconName, StyledExt, h_flex,
highlighter::{HighlightTheme, SyntaxHighlighter}, highlighter::{HighlightTheme, SyntaxHighlighter},
text::inline::{Inline, InlineState}, text::inline::{Inline, InlineState},
tooltip::Tooltip, tooltip::Tooltip,
v_flex, ActiveTheme as _, Icon, IconName, StyledExt, v_flex,
}; };
use super::{utils::list_item_prefix, TextViewStyle}; use super::{TextViewStyle, utils::list_item_prefix};
#[allow(unused)] #[allow(unused)]
#[derive(Debug, Default, Clone, PartialEq)] #[derive(Debug, Default, Clone, PartialEq)]
@ -767,11 +767,7 @@ impl Node {
children, checked, .. children, checked, ..
} => { } => {
let checkbox = if let Some(checked) = checked { let checkbox = if let Some(checked) = checked {
if *checked { if *checked { "[x] " } else { "[ ] " }
"[x] "
} else {
"[ ] "
}
} else { } else {
"" ""
}; };
@ -866,7 +862,7 @@ impl Node {
node_cx: &NodeContext, node_cx: &NodeContext,
window: &mut Window, window: &mut Window,
cx: &mut App, cx: &mut App,
) -> impl IntoElement { ) -> AnyElement {
match item { match item {
Node::ListItem { Node::ListItem {
children, children,
@ -899,10 +895,9 @@ impl Node {
// merge content into last item. // merge content into last item.
if last_not_list { if last_not_list {
if let Some(item_item) = items.last_mut() { if let Some(item_item) = items.last_mut() {
item_item.extend(vec![div() item_item.extend(vec![
.overflow_hidden() div().overflow_hidden().child(text).into_any_element(),
.child(text) ]);
.into_any_element()]);
continue; continue;
} }
} }
@ -1116,7 +1111,7 @@ impl Node {
node_cx: &NodeContext, node_cx: &NodeContext,
window: &mut Window, window: &mut Window,
cx: &mut App, cx: &mut App,
) -> impl IntoElement { ) -> AnyElement {
let mb = if options.in_list || options.is_last { let mb = if options.in_list || options.is_last {
rems(0.) rems(0.)
} else { } else {

View file

@ -2,16 +2,17 @@ use std::{borrow::Cow, rc::Rc};
use chrono::{Datelike, Local, NaiveDate}; use chrono::{Datelike, Local, NaiveDate};
use gpui::{ use gpui::{
prelude::FluentBuilder as _, px, relative, App, ClickEvent, Context, ElementId, Empty, Entity, App, ClickEvent, Context, Div, ElementId, Empty, Entity, EventEmitter, FocusHandle,
EventEmitter, FocusHandle, InteractiveElement, IntoElement, ParentElement, Render, RenderOnce, InteractiveElement, IntoElement, ParentElement, Render, RenderOnce, SharedString, Stateful,
SharedString, StatefulInteractiveElement, StyleRefinement, Styled, Window, StatefulInteractiveElement, StyleRefinement, Styled, Window, prelude::FluentBuilder as _, px,
relative,
}; };
use rust_i18n::t; use rust_i18n::t;
use crate::{ use crate::{
ActiveTheme, Disableable as _, IconName, Selectable, Sizable, Size, StyledExt as _,
button::{Button, ButtonVariants as _}, button::{Button, ButtonVariants as _},
h_flex, v_flex, ActiveTheme, Disableable as _, IconName, Selectable, Sizable, Size, h_flex, v_flex,
StyledExt as _,
}; };
use super::utils::days_in_month; use super::utils::days_in_month;
@ -543,7 +544,7 @@ impl Calendar {
offset_month: usize, offset_month: usize,
window: &mut Window, window: &mut Window,
cx: &mut App, cx: &mut App,
) -> impl IntoElement { ) -> Stateful<Div> {
let state = self.state.read(cx); let state = self.state.read(cx);
let (_, month) = state.offset_year_month(offset_month); let (_, month) = state.offset_year_month(offset_month);
let day = d.day(); let day = d.day();
@ -561,7 +562,7 @@ impl Calendar {
let date_id: SharedString = format!("{}_{}", date.format("%Y-%m-%d"), offset_month).into(); let date_id: SharedString = format!("{}_{}", date.format("%Y-%m-%d"), offset_month).into();
self.item_button( self.item_button(
date_id, date_id.clone(),
day.to_string(), day.to_string(),
is_active, is_active,
is_in_range, is_in_range,
@ -734,7 +735,7 @@ impl Calendar {
disabled: bool, disabled: bool,
_: &mut Window, _: &mut Window,
cx: &mut App, cx: &mut App,
) -> impl IntoElement + Styled + StatefulInteractiveElement { ) -> Stateful<Div> {
h_flex() h_flex()
.id(id.into()) .id(id.into())
.map(|this| match self.size { .map(|this| match self.size {
@ -815,12 +816,7 @@ impl Calendar {
) )
} }
fn render_week( fn render_week(&self, week: impl Into<SharedString>, _: &mut Window, cx: &mut App) -> Div {
&self,
week: impl Into<SharedString>,
_: &mut Window,
cx: &mut App,
) -> impl IntoElement {
h_flex() h_flex()
.map(|this| match self.size { .map(|this| match self.size {
Size::Small => this.size_7().rounded(cx.theme().radius / 2.0), Size::Small => this.size_7().rounded(cx.theme().radius / 2.0),

View file

@ -1,9 +1,9 @@
[package] [package]
edition = "2021"
name = "app_assets" name = "app_assets"
description = "Example to load icons or images from assets folder." description = "Example to load icons or images from assets folder."
publish = false
version = "0.4.1" version = "0.4.1"
publish = false
edition.workspace = true
[dependencies] [dependencies]
anyhow.workspace = true anyhow.workspace = true

View file

@ -1,9 +1,9 @@
[package] [package]
edition = "2021"
name = "dialog_overlay" name = "dialog_overlay"
description = "An example of using gpui-component to create a Dialog with overlay." description = "An example of using gpui-component to create a Dialog with overlay."
publish = false
version = "0.4.1" version = "0.4.1"
publish = false
edition.workspace = true
[dependencies] [dependencies]
anyhow.workspace = true anyhow.workspace = true

View file

@ -1,9 +1,9 @@
[package] [package]
edition = "2021"
name = "hello_world" name = "hello_world"
description = "A minimal example of application development with GPUI Component." description = "A minimal example of application development with GPUI Component."
publish = false
version = "0.4.1" version = "0.4.1"
publish = false
edition.workspace = true
[dependencies] [dependencies]
anyhow.workspace = true anyhow.workspace = true

View file

@ -2,7 +2,7 @@
name = "input" name = "input"
version = "0.4.1" version = "0.4.1"
publish = false publish = false
edition = "2024" edition.workspace = true
[dependencies] [dependencies]
anyhow.workspace = true anyhow.workspace = true

View file

@ -1,9 +1,9 @@
[package] [package]
edition = "2021"
name = "window_title" name = "window_title"
description = "An example of using gpui-component to create a window with a custom title bar." description = "An example of using gpui-component to create a window with a custom title bar."
publish = false
version = "0.4.1" version = "0.4.1"
publish = false
edition.workspace = true
[dependencies] [dependencies]
anyhow.workspace = true anyhow.workspace = true