Skip to content
Snippets Groups Projects
Unverified Commit e4af3fe5 authored by StaffEngineer's avatar StaffEngineer Committed by GitHub
Browse files

Merge pull request #15 from StaffEngineer/blinking_cursor

Enable cursor blinking
parents c545a6e3 d76e9bb8
No related branches found
No related tags found
No related merge requests found
......@@ -388,7 +388,7 @@ dependencies = [
[[package]]
name = "bevy_cosmic_edit"
version = "0.10.0"
version = "0.10.1"
dependencies = [
"arboard",
"bevy",
......
[package]
name = "bevy_cosmic_edit"
version = "0.10.0"
version = "0.10.1"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "Bevy cosmic-text multiline text input"
......
......@@ -249,12 +249,13 @@ fn setup(
let mut attrs_2 = cosmic_text::Attrs::new();
attrs_2 = attrs_2.family(cosmic_text::Family::Name("Times New Roman"));
attrs_2.color_opt = Some(cosmic_text::Color::rgb(0x94, 0x00, 0xD3));
let cosmic_edit_2 = CosmicEditUiBundle {
cosmic_attrs: CosmicAttrs(AttrsOwned::new(attrs_2)),
cosmic_metrics: CosmicMetrics {
font_size: 14.,
line_height: 18.,
font_size: 28.,
line_height: 36.,
scale_factor: primary_window.scale_factor() as f32,
},
text_position: CosmicTextPosition::Center,
......
......@@ -389,6 +389,8 @@ impl Plugin for CosmicEditPlugin {
.before(cosmic_edit_set_redraw)
.before(on_scale_factor_change),
cosmic_edit_redraw_buffer.before(on_scale_factor_change),
blink_cursor,
hide_inactive_cursor,
),
)
.init_resource::<ActiveEditor>()
......@@ -1177,6 +1179,61 @@ fn cosmic_edit_redraw_buffer_ui(
}
}
fn blink_cursor(
mut visible: Local<bool>,
mut timer: Local<Option<Timer>>,
time: Res<Time>,
active_editor: ResMut<ActiveEditor>,
mut cosmic_editor_q: Query<(&mut CosmicEditor, &BackgroundColor), Without<ReadOnly>>,
) {
if let Some(e) = active_editor.entity {
if let Ok((mut editor, bg_color)) = cosmic_editor_q.get_mut(e) {
let timer =
timer.get_or_insert_with(|| Timer::from_seconds(0.53, TimerMode::Repeating));
timer.tick(time.delta());
if !timer.just_finished() && !active_editor.is_changed() {
return;
}
*visible = !*visible;
// always start cursor visible on focus
if active_editor.is_changed() {
*visible = true;
timer.set_elapsed(Duration::from_secs(0));
}
let mut cursor = editor.0.cursor();
let new_color = if *visible {
None
} else {
Some(bevy_color_to_cosmic(bg_color.0))
};
cursor.color = new_color;
editor.0.set_cursor(cursor);
editor.0.buffer_mut().set_redraw(true);
}
}
}
fn hide_inactive_cursor(
mut cosmic_editor_q: Query<(Entity, &mut CosmicEditor, &BackgroundColor)>,
active_editor: Res<ActiveEditor>,
) {
if !active_editor.is_changed() || active_editor.entity.is_none() {
return;
}
for (e, mut editor, bg_color) in &mut cosmic_editor_q.iter_mut() {
if e != active_editor.entity.unwrap() {
let mut cursor = editor.0.cursor();
cursor.color = Some(bevy_color_to_cosmic(bg_color.0));
editor.0.set_cursor(cursor);
editor.0.buffer_mut().set_redraw(true);
}
}
}
fn cosmic_edit_redraw_buffer(
windows: Query<&Window, With<PrimaryWindow>>,
mut images: ResMut<Assets<Image>>,
......
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