chore: Improve Request Screening (#101)
* open chat while screening * close panel on ignore * bypass screening * . * improve settings * refine modal * . * . * . * . * .
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
use std::cell::Cell;
|
||||
use std::rc::Rc;
|
||||
|
||||
use gpui::{
|
||||
canvas, div, relative, AnyElement, App, Div, Element, ElementId, EntityId, GlobalElementId,
|
||||
InteractiveElement, IntoElement, ParentElement, Pixels, Position, ScrollHandle, SharedString,
|
||||
Size, Stateful, StatefulInteractiveElement, Style, StyleRefinement, Styled, Window,
|
||||
div, relative, AnyElement, App, Bounds, Div, Element, ElementId, GlobalElementId,
|
||||
InspectorElementId, InteractiveElement, Interactivity, IntoElement, LayoutId, ParentElement,
|
||||
Pixels, Position, ScrollHandle, SharedString, Size, Stateful, StatefulInteractiveElement,
|
||||
Style, StyleRefinement, Styled, Window,
|
||||
};
|
||||
|
||||
use super::{Scrollbar, ScrollbarAxis, ScrollbarState};
|
||||
@@ -13,7 +11,6 @@ use super::{Scrollbar, ScrollbarAxis, ScrollbarState};
|
||||
pub struct Scrollable<E> {
|
||||
id: ElementId,
|
||||
element: Option<E>,
|
||||
view_id: EntityId,
|
||||
axis: ScrollbarAxis,
|
||||
/// This is a fake element to handle Styled, InteractiveElement, not used.
|
||||
_element: Stateful<Div>,
|
||||
@@ -23,19 +20,16 @@ impl<E> Scrollable<E>
|
||||
where
|
||||
E: Element,
|
||||
{
|
||||
pub(crate) fn new(view_id: EntityId, element: E, axis: ScrollbarAxis) -> Self {
|
||||
let id = ElementId::Name(SharedString::from(format!(
|
||||
"ScrollView:{}-{:?}",
|
||||
view_id,
|
||||
element.id(),
|
||||
)));
|
||||
pub(crate) fn new(axis: impl Into<ScrollbarAxis>, element: E) -> Self {
|
||||
let id = ElementId::Name(SharedString::from(
|
||||
format!("scrollable-{:?}", element.id(),),
|
||||
));
|
||||
|
||||
Self {
|
||||
element: Some(element),
|
||||
_element: div().id("fake"),
|
||||
id,
|
||||
view_id,
|
||||
axis,
|
||||
axis: axis.into(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,8 +47,8 @@ where
|
||||
}
|
||||
|
||||
/// Set the axis of the scroll view.
|
||||
pub fn set_axis(&mut self, axis: ScrollbarAxis) {
|
||||
self.axis = axis;
|
||||
pub fn set_axis(&mut self, axis: impl Into<ScrollbarAxis>) {
|
||||
self.axis = axis.into();
|
||||
}
|
||||
|
||||
fn with_element_state<R>(
|
||||
@@ -76,8 +70,7 @@ where
|
||||
}
|
||||
|
||||
pub struct ScrollViewState {
|
||||
scroll_size: Rc<Cell<Size<Pixels>>>,
|
||||
state: Rc<Cell<ScrollbarState>>,
|
||||
state: ScrollbarState,
|
||||
handle: ScrollHandle,
|
||||
}
|
||||
|
||||
@@ -85,8 +78,7 @@ impl Default for ScrollViewState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
handle: ScrollHandle::new(),
|
||||
scroll_size: Rc::new(Cell::new(Size::default())),
|
||||
state: Rc::new(Cell::new(ScrollbarState::default())),
|
||||
state: ScrollbarState::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,7 +111,7 @@ impl<E> InteractiveElement for Scrollable<E>
|
||||
where
|
||||
E: Element + InteractiveElement,
|
||||
{
|
||||
fn interactivity(&mut self) -> &mut gpui::Interactivity {
|
||||
fn interactivity(&mut self) -> &mut Interactivity {
|
||||
if let Some(element) = &mut self.element {
|
||||
element.interactivity()
|
||||
} else {
|
||||
@@ -127,7 +119,6 @@ where
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<E> StatefulInteractiveElement for Scrollable<E> where E: Element + StatefulInteractiveElement {}
|
||||
|
||||
impl<E> IntoElement for Scrollable<E>
|
||||
@@ -148,7 +139,7 @@ where
|
||||
type PrepaintState = ScrollViewState;
|
||||
type RequestLayoutState = AnyElement;
|
||||
|
||||
fn id(&self) -> Option<gpui::ElementId> {
|
||||
fn id(&self) -> Option<ElementId> {
|
||||
Some(self.id.clone())
|
||||
}
|
||||
|
||||
@@ -158,11 +149,11 @@ where
|
||||
|
||||
fn request_layout(
|
||||
&mut self,
|
||||
id: Option<&gpui::GlobalElementId>,
|
||||
_: Option<&gpui::InspectorElementId>,
|
||||
id: Option<&GlobalElementId>,
|
||||
_: Option<&InspectorElementId>,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) -> (gpui::LayoutId, Self::RequestLayoutState) {
|
||||
) -> (LayoutId, Self::RequestLayoutState) {
|
||||
let style = Style {
|
||||
position: Position::Relative,
|
||||
flex_grow: 1.0,
|
||||
@@ -175,16 +166,10 @@ where
|
||||
};
|
||||
|
||||
let axis = self.axis;
|
||||
let view_id = self.view_id;
|
||||
|
||||
let scroll_id = self.id.clone();
|
||||
let content = self.element.take().map(|c| c.into_any_element());
|
||||
|
||||
self.with_element_state(id.unwrap(), window, cx, |_, element_state, window, cx| {
|
||||
let handle = element_state.handle.clone();
|
||||
let state = element_state.state.clone();
|
||||
let scroll_size = element_state.scroll_size.clone();
|
||||
|
||||
let mut element = div()
|
||||
.relative()
|
||||
.size_full()
|
||||
@@ -192,16 +177,11 @@ where
|
||||
.child(
|
||||
div()
|
||||
.id(scroll_id)
|
||||
.track_scroll(&handle)
|
||||
.track_scroll(&element_state.handle)
|
||||
.overflow_scroll()
|
||||
.relative()
|
||||
.size_full()
|
||||
.child(div().children(content).child({
|
||||
let scroll_size = element_state.scroll_size.clone();
|
||||
canvas(move |b, _, _| scroll_size.set(b.size), |_, _, _, _| {})
|
||||
.absolute()
|
||||
.size_full()
|
||||
})),
|
||||
.child(div().children(content)),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
@@ -211,8 +191,7 @@ where
|
||||
.right_0()
|
||||
.bottom_0()
|
||||
.child(
|
||||
Scrollbar::both(view_id, state, handle.clone(), scroll_size.get())
|
||||
.axis(axis),
|
||||
Scrollbar::both(&element_state.state, &element_state.handle).axis(axis),
|
||||
),
|
||||
)
|
||||
.into_any_element();
|
||||
@@ -226,9 +205,9 @@ where
|
||||
|
||||
fn prepaint(
|
||||
&mut self,
|
||||
_: Option<&gpui::GlobalElementId>,
|
||||
_: Option<&gpui::InspectorElementId>,
|
||||
_: gpui::Bounds<Pixels>,
|
||||
_: Option<&GlobalElementId>,
|
||||
_: Option<&InspectorElementId>,
|
||||
_: Bounds<Pixels>,
|
||||
element: &mut Self::RequestLayoutState,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
@@ -240,9 +219,9 @@ where
|
||||
|
||||
fn paint(
|
||||
&mut self,
|
||||
_: Option<&gpui::GlobalElementId>,
|
||||
_: Option<&gpui::InspectorElementId>,
|
||||
_: gpui::Bounds<Pixels>,
|
||||
_: Option<&GlobalElementId>,
|
||||
_: Option<&InspectorElementId>,
|
||||
_: Bounds<Pixels>,
|
||||
element: &mut Self::RequestLayoutState,
|
||||
_: &mut Self::PrepaintState,
|
||||
window: &mut Window,
|
||||
|
||||
Reference in New Issue
Block a user