Skip to content
Snippets Groups Projects
Unverified Commit 2fd94719 authored by databasedav's avatar databasedav Committed by GitHub
Browse files

add scroll disableability (#141)

* add scroll disableability

* fmt
parent 88ea7326
No related branches found
No related tags found
No related merge requests found
......@@ -70,6 +70,10 @@ pub struct MaxLines(pub usize);
#[derive(Component, Default)]
pub struct MaxChars(pub usize);
/// Buffer does not respond to scroll events
#[derive(Component, Default)]
pub struct ScrollDisabled;
/// A pointer to an entity with a [`CosmicEditBundle`], used to apply cosmic rendering to a UI
/// element.
///
......
......@@ -69,6 +69,7 @@ pub(crate) fn input_mouse(
Entity,
&XOffset,
&mut Sprite,
Option<&ScrollDisabled>,
)>,
node_q: Query<(&Node, &GlobalTransform, &CosmicSource)>,
mut font_system: ResMut<CosmicFontSystem>,
......@@ -107,8 +108,15 @@ pub(crate) fn input_mouse(
return;
};
if let Ok((mut editor, sprite_transform, text_position, entity, x_offset, sprite)) =
editor_q.get_mut(active_editor_entity)
if let Ok((
mut editor,
sprite_transform,
text_position,
entity,
x_offset,
sprite,
scroll_disabled,
)) = editor_q.get_mut(active_editor_entity)
{
let buffer = editor.with_buffer(|b| b.clone());
......@@ -218,24 +226,26 @@ pub(crate) fn input_mouse(
return;
}
for ev in scroll_evr.read() {
match ev.unit {
MouseScrollUnit::Line => {
editor.action(
&mut font_system.0,
Action::Scroll {
lines: -ev.y as i32,
},
);
}
MouseScrollUnit::Pixel => {
let line_height = buffer.metrics().line_height;
editor.action(
&mut font_system.0,
Action::Scroll {
lines: -(ev.y / line_height) as i32,
},
);
if scroll_disabled.is_none() {
for ev in scroll_evr.read() {
match ev.unit {
MouseScrollUnit::Line => {
editor.action(
&mut font_system.0,
Action::Scroll {
lines: -ev.y as i32,
},
);
}
MouseScrollUnit::Pixel => {
let line_height = buffer.metrics().line_height;
editor.action(
&mut font_system.0,
Action::Scroll {
lines: -(ev.y / line_height) as i32,
},
);
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment