Skip to content

Commit

Permalink
Refactor ScrollView into scrollable fluent method. (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee authored Jul 24, 2024
1 parent 7305967 commit 030a706
Show file tree
Hide file tree
Showing 6 changed files with 363 additions and 356 deletions.
13 changes: 8 additions & 5 deletions crates/story/src/scrollable_story.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use gpui::{
};
use ui::button::Button;
use ui::divider::Divider;
use ui::scroll::{Scrollable, Scrollbar, ScrollbarAxis, ScrollbarState};
use ui::scroll::{Scrollbar, ScrollbarAxis, ScrollbarState};
use ui::theme::ActiveTheme;
use ui::{h_flex, v_flex, Clickable};
use ui::{h_flex, v_flex, Clickable, StyledExt as _};

pub struct ScrollableStory {
scroll_handle: ScrollHandle,
Expand Down Expand Up @@ -182,15 +182,18 @@ impl Render for ScrollableStory {
.h(px(200.))
.child(
v_flex()
.m_3()
.id("test-1")
.focusable()
.scrollable(cx.view().clone(), ScrollbarAxis::Vertical)
.p_3()
.w(test_width)
.gap_1()
.child("Hello world")
.children(
items
.iter()
.map(|s| div().bg(cx.theme().card).child(s.clone())),
)
.scrollable("scroll-view1", cx.view().clone()),
),
)
})
}
Expand Down
34 changes: 2 additions & 32 deletions crates/ui/src/scroll/mod.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,7 @@
mod scroll_view;
mod scrollable;
mod scrollable_mask;
mod scrollbar;

use gpui::{AnyElement, AnyView, Div, Element, ElementId, Focusable, InteractiveElement, Stateful};
pub use scroll_view::*;
pub use scrollable::*;
pub use scrollable_mask::*;
pub use scrollbar::*;

pub trait Scrollable: Element {
/// Wraps the element in a ScrollView.
///
/// Current this is only have a vertical scrollbar.
fn scrollable(self, id: impl Into<ElementId>, view: impl Into<AnyView>) -> ScrollView {
ScrollView::new(
ElementId::Name(format!("{}:{}", id.into(), "ScrollView").into()),
view,
ScrollbarAxis::Vertical,
)
.content(move |_| self)
}
}

impl Scrollable for AnyElement {}
impl Scrollable for Div {}
impl<E> Scrollable for Focusable<E>
where
E: Element,
Self: InteractiveElement,
{
}
impl<E> Scrollable for Stateful<E>
where
E: Element,
Self: InteractiveElement,
{
}
199 changes: 0 additions & 199 deletions crates/ui/src/scroll/scroll_view.rs

This file was deleted.

Loading

0 comments on commit 030a706

Please sign in to comment.