Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dock: Add cache to panel view. #600

Merged
merged 4 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions crates/story/src/table_story.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ impl_internal_actions!(table_story, [ChangeSize, OpenDetail]);
#[derive(Clone, Debug, Default)]
struct Stock {
id: usize,
symbol: String,
name: String,
symbol: SharedString,
name: SharedString,
price: f64,
change: f64,
change_percent: f64,
Expand Down Expand Up @@ -104,8 +104,8 @@ fn random_stocks(size: usize) -> Vec<Stock> {
(0..size)
.map(|id| Stock {
id,
symbol: Faker.fake::<String>(),
name: Faker.fake::<String>(),
symbol: Faker.fake::<String>().into(),
name: Faker.fake::<String>().into(),
change: (-100.0..100.0).fake(),
change_percent: (-1.0..1.0).fake(),
volume: (0.0..1000.0).fake(),
Expand Down
15 changes: 10 additions & 5 deletions crates/ui/src/dock/dock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
use std::sync::Arc;

use gpui::{
div, prelude::FluentBuilder as _, px, App, AppContext, Axis, Context, Element, Empty, Entity,
InteractiveElement as _, IntoElement, MouseMoveEvent, MouseUpEvent, ParentElement as _, Pixels,
Point, Render, StatefulInteractiveElement, Style, Styled as _, WeakEntity, Window,
div, prelude::FluentBuilder as _, px, AnyView, App, AppContext, Axis, Context, Element, Empty,
Entity, InteractiveElement as _, IntoElement, MouseMoveEvent, MouseUpEvent, ParentElement as _,
Pixels, Point, Render, StatefulInteractiveElement, Style, StyleRefinement, Styled as _,
WeakEntity, Window,
};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -394,6 +395,8 @@ impl Render for Dock {
return div();
}

let cache_style = StyleRefinement::default().v_flex().size_full();

div()
.relative()
.overflow_hidden()
Expand All @@ -408,8 +411,10 @@ impl Render for Dock {
})
.map(|this| match &self.panel {
DockItem::Split { view, .. } => this.child(view.clone()),
DockItem::Tabs { view, .. } => this.child(view.clone()),
DockItem::Panel { view, .. } => this.child(view.clone().view()),
DockItem::Tabs { view, .. } => {
this.child(AnyView::from(view.clone()).cached(cache_style))
}
DockItem::Panel { view, .. } => this.child(view.clone().view().cached(cache_style)),
// Not support to render Tiles and Tile into Dock
DockItem::Tiles { .. } => this,
})
Expand Down
10 changes: 7 additions & 3 deletions crates/ui/src/dock/tab_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use gpui::{
div, prelude::FluentBuilder, px, rems, App, AppContext, Context, Corner, DefiniteLength,
DismissEvent, DragMoveEvent, Empty, Entity, EventEmitter, FocusHandle, Focusable,
InteractiveElement as _, IntoElement, ParentElement, Pixels, Render, ScrollHandle,
SharedString, StatefulInteractiveElement, Styled, WeakEntity, Window,
SharedString, StatefulInteractiveElement, StyleRefinement, Styled, WeakEntity, Window,
};
use rust_i18n::t;

Expand All @@ -14,7 +14,7 @@ use crate::{
h_flex,
popup_menu::{PopupMenu, PopupMenuExt},
tab::{Tab, TabBar},
v_flex, ActiveTheme, AxisExt, IconName, Placement, Selectable, Sizable,
v_flex, ActiveTheme, AxisExt, IconName, Placement, Selectable, Sizable, StyledExt as _,
};

use super::{
Expand Down Expand Up @@ -767,7 +767,11 @@ impl TabPanel {
.overflow_y_scroll()
.overflow_x_hidden()
.flex_1()
.child(active_panel.view())
.child(
active_panel
.view()
.cached(StyleRefinement::default().v_flex().size_full()),
)
.when(state.droppable, |this| {
this.on_drag_move(cx.listener(Self::on_panel_drag_move))
.child(
Expand Down
Loading
Loading