-
sam edelsten authored
* barely got text entry working again * remove local optimizations i should really put them somewhere else on my machine * delete most stuff to get the basics nearly working * editable text lots of cloning but seems to be the only way if buffers are in the ECS editor widgets don't relayout when edited, but when unfocused the buffer does * fix backspace on native and make basic_ui wasm editable * fix mid-edit layout * reimplement text cursor blinking uhoh it's looking like im using the not a starting point pr as a starting point lol * update `basic_sprite` example adds a util crate for common example systems also removes history tracking structs * `image_background`+`bevy_api_testing` examples MV `bevy_api_testing.rs` > `sprite_and_ui_clickable.rs` * remove `CosmicText` in favor of buffer functions simplifys API and mirrors Bevy's Text functions more closely * strip autoheight + example, update other examples * fix wasm compilation * clippy * fix text * fix clippy * fix wasm * fix import * add changelog * fix mouse cursor hover on sprite widget * fix editor cursor location when edited * fix blank widget when focused on startup * configurable cursor/selection colors * run layout functions when needed * fix ui widget mouse cursor * fix scale change --------- Co-authored-by:
Dima <Dmytro.Rets@Gamesys.co.uk> Co-authored-by:
StaffEngineer <velo.app1@gmail.com>
Unverified696fe6f7
focus.rs 1.39 KiB
use bevy::prelude::*;
use cosmic_text::{Edit, Editor};
use crate::{CosmicBuffer, CosmicEditor};
/// Resource struct that keeps track of the currently active editor entity.
#[derive(Resource, Default, Deref, DerefMut)]
pub struct FocusedWidget(pub Option<Entity>);
pub(crate) fn add_editor_to_focused(
mut commands: Commands,
active_editor: Res<FocusedWidget>,
q: Query<&CosmicBuffer, Without<CosmicEditor>>,
) {
if let Some(e) = active_editor.0 {
let Ok(b) = q.get(e) else {
return;
};
let mut editor = Editor::new(b.0.clone());
editor.set_redraw(true);
commands.entity(e).insert(CosmicEditor::new(editor));
}
}
pub(crate) fn drop_editor_unfocused(
mut commands: Commands,
active_editor: Res<FocusedWidget>,
mut q: Query<(Entity, &mut CosmicBuffer, &CosmicEditor)>,
) {
if active_editor.0.is_none() {
for (e, mut b, ed) in q.iter_mut() {
b.lines = ed.with_buffer(|buf| buf.lines.clone());
b.set_redraw(true);
commands.entity(e).remove::<CosmicEditor>();
}
} else if let Some(focused) = active_editor.0 {
for (e, mut b, ed) in q.iter_mut() {
if e != focused {
b.lines = ed.with_buffer(|buf| buf.lines.clone());
b.set_redraw(true);
commands.entity(e).remove::<CosmicEditor>();
}
}
}
}