From a19182507b064d8a20c1c321a1399240e2b6028f Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 25 Oct 2022 09:30:16 -0600 Subject: [PATCH] Set orbclient async mode when edge scrolling --- examples/editor-orbclient/Cargo.toml | 2 +- examples/editor-orbclient/src/main.rs | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/examples/editor-orbclient/Cargo.toml b/examples/editor-orbclient/Cargo.toml index 060a631..718a6cb 100644 --- a/examples/editor-orbclient/Cargo.toml +++ b/examples/editor-orbclient/Cargo.toml @@ -11,7 +11,7 @@ cosmic-text = { path = "../../" } env_logger = "0.9" fontdb = "0.9" log = "0.4" -orbclient = "0.3.35" +orbclient = "0.3.39" [features] mono = [] diff --git a/examples/editor-orbclient/src/main.rs b/examples/editor-orbclient/src/main.rs index b5daad5..f2b132a 100644 --- a/examples/editor-orbclient/src/main.rs +++ b/examples/editor-orbclient/src/main.rs @@ -167,6 +167,7 @@ fn main() { } let mut found_event = false; + let mut window_async = false; for event in window.events() { found_event = true; match event.to_option() { @@ -225,8 +226,10 @@ fn main() { if mouse_y <= 5 { buffer.action(TextAction::Scroll { lines: -3 }); + window_async = true; } else if mouse_y + 5 >= window.height() as i32 { buffer.action(TextAction::Scroll { lines: 3 }); + window_async = true; } else { buffer.shape_until_cursor() } @@ -269,12 +272,19 @@ fn main() { if mouse_y <= 5 { buffer.action(TextAction::Scroll { lines: -3 }); + window_async = true; } else if mouse_y + 5 >= window.height() as i32 { buffer.action(TextAction::Scroll { lines: 3 }); + window_async = true; } } - if ! found_event { + if window_async != window.is_async() { + window.set_async(window_async); + } + + if window_async && ! found_event { + // In async mode and no event found, sleep thread::sleep(Duration::from_millis(5)); } }