add getter/setter to interface with the current scroll offset of interactivity

This commit is contained in:
temportalflux
2026-07-11 09:31:07 -04:00
parent 1f2c11d44f
commit f4cb5e21b7
+29
View File
@@ -1866,6 +1866,35 @@ pub struct Interactivity {
pub(crate) debug_selector: Option<String>,
}
impl Interactivity {
/// Assigns the current scroll offset of an element. No-op if the element's
/// style does not have overflow enabled.
///
/// Should only be called during the `request_layout` phase.
pub fn set_scroll_offset(
&self,
global_id: Option<&GlobalElementId>,
window: &mut Window,
point: Point<Pixels>,
) {
window.with_optional_element_state::<gpui::InteractiveElementState, _>(
global_id,
|element_state, _window| {
let mut element_state =
element_state.map(|element_state| element_state.unwrap_or_default());
let overflow = &self.base_style.overflow;
if (overflow.x == Some(Overflow::Scroll) || overflow.y == Some(Overflow::Scroll))
&& let Some(element_state) = element_state.as_mut()
{
let scroll_offset = element_state.scroll_offset.get_or_insert_with(Rc::default);
*scroll_offset.borrow_mut() = point;
}
((), element_state)
},
);
}
}
impl Interactivity {
/// Layout this element according to this interactivity state's configured styles
pub fn request_layout(