mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
Update Retype font previews while typing
This commit is contained in:
1 parent
f040538a39
commit
0859e9a6c6
2 files changed
+20
-1
No files matched your search
@@ -89,9 +89,10 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
}
|
||||
let typed = TextField::new(tl!("Type your text to preview"), Bind::given(Mixed::Same(app.ui.retype.text.clone())))
|
||||
.placeholder(tl!("Type your text to preview"))
|
||||
.keeps_on_escape()
|
||||
.limit(MAX_TEXT)
|
||||
.show(ui);
|
||||
if let Some(text) = typed.events.committed() {
|
||||
if let Some(text) = typed.events.value().filter(|text| **text != app.ui.retype.text) {
|
||||
run = Some(("retype.preview", json!({ "text": text })));
|
||||
}
|
||||
Divider::horizontal().show(ui);
|
||||
|
||||
@@ -5,6 +5,7 @@ use vectorcraft_engine::Session;
|
||||
|
||||
use super::{ID, Size, show};
|
||||
use crate::VectorcraftApp;
|
||||
use crate::tests::panel_harness::Panel;
|
||||
|
||||
const SCREEN: egui::Rect = egui::Rect::from_min_max(egui::Pos2::ZERO, egui::pos2(600.0, 900.0));
|
||||
|
||||
@@ -138,6 +139,23 @@ fn a_failed_search_leaves_the_list_as_it_was() {
|
||||
assert_eq!(app.run("retype.list", json!({})).unwrap(), listed);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn typing_updates_the_preview_without_enter_and_escape_keeps_it() {
|
||||
let mut panel = Panel::new(app(), show);
|
||||
let label = "Type your text to preview";
|
||||
panel.click(label);
|
||||
assert!(panel.focused(label));
|
||||
panel.type_text("Preview");
|
||||
assert_eq!(panel.app().run("retype.list", json!({})).unwrap()["text"], "Preview");
|
||||
panel.type_text(" sample");
|
||||
assert_eq!(panel.app().run("retype.list", json!({})).unwrap()["text"], "Preview sample");
|
||||
|
||||
panel.key(egui::Key::Escape, egui::Modifiers::NONE);
|
||||
assert!(!panel.focused(label));
|
||||
assert_eq!(panel.value(label).as_deref(), Some("Preview sample"));
|
||||
assert_eq!(panel.app().run("retype.list", json!({})).unwrap()["text"], "Preview sample");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preview_sets_the_size_and_text_and_reset_keeps_them() {
|
||||
let mut app = app();
|
||||
|
||||
Reference in new issue
Block a user