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

add text change event (#50)

parent 6873e7b5
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,9 @@ pub enum CosmicTextPosition {
TopLeft,
}
#[derive(Event, Debug)]
pub struct CosmicTextChanged(pub (Entity, String));
// TODO docs
#[derive(Clone, Component)]
pub struct CosmicMetrics {
......@@ -67,7 +70,7 @@ pub struct ReadOnly; // tag component
pub struct CosmicEditor(pub Editor);
impl CosmicEditor {
fn set_text(
pub fn set_text(
&mut self,
text: CosmicText,
attrs: AttrsOwned,
......@@ -410,7 +413,8 @@ impl Plugin for CosmicEditPlugin {
.insert_resource(SwashCacheState {
swash_cache: SwashCache::new(),
})
.insert_resource(CosmicFontSystem(font_system));
.insert_resource(CosmicFontSystem(font_system))
.add_event::<CosmicTextChanged>();
}
}
......@@ -698,6 +702,7 @@ fn cosmic_edit_bevy_events(
),
With<CosmicEditor>,
>,
mut evw_changed: EventWriter<CosmicTextChanged>,
readonly_query: Query<&ReadOnly>,
node_query: Query<&mut Node>,
sprite_query: Query<&mut Sprite>,
......@@ -916,6 +921,7 @@ fn cosmic_edit_bevy_events(
edit_history.current_edit += 1;
}
*undoredo_duration = Some(Duration::from_millis(now_ms as u64));
evw_changed.send(CosmicTextChanged((entity, editor.get_text())));
return;
}
// undo
......@@ -952,6 +958,7 @@ fn cosmic_edit_bevy_events(
edit_history.current_edit -= 1;
}
*undoredo_duration = Some(Duration::from_millis(now_ms as u64));
evw_changed.send(CosmicTextChanged((entity, editor.get_text())));
return;
}
......@@ -1106,6 +1113,8 @@ fn cosmic_edit_bevy_events(
return;
}
evw_changed.send(CosmicTextChanged((entity, editor.get_text())));
if let Some(last_edit_duration) = *edits_duration {
if Duration::from_millis(now_ms as u64) - last_edit_duration
> Duration::from_millis(150)
......
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