Release 0.2.0: polish preview fonts and modal print dialog.
Disable editor autocomplete/focus while printing so parameter fields stay usable; bump package version. Co-authored-by: Cursor <cursoragent@cursor.com>
@@ -2769,7 +2769,7 @@ checksum = "2f3a9f18d041e6d0e102a0a46750538147e5e8992d3b4873aaafee2520b00ce3"
2769
2769
2770
2770
[[package]]
2771
2771
name = "posprint"
2772
version = "0.1.2"
2772
version = "0.2.0"
2773
2773
dependencies = [
2774
2774
"barcoders",
2775
2775
"chrono",
@@ -2769,7 +2769,7 @@ checksum = "2f3a9f18d041e6d0e102a0a46750538147e5e8992d3b4873aaafee2520b00ce3"2769
2769
2770
[[package]]2770
[[package]]2771
name = "posprint"2771
name = "posprint"2772
version = "0.1.2"2772
version = "0.2.0"2773
dependencies = [2773
dependencies = [2774
"barcoders",2774
"barcoders",2775
"chrono",2775
"chrono",@@ -1,6 +1,6 @@
1
1
[package]
2
2
name = "posprint"
3
version = "0.1.2"
3
version = "0.2.0"
4
4
edition = "2021"
5
5
rust-version = "1.88"
6
6
description = "Designer for POS-print documents"
@@ -1,6 +1,6 @@1
[package]
1
[package]
2
name = "posprint"
2
name = "posprint"
3
version = "0.1.2"
3
version = "0.2.0"
4
edition = "2021"
4
edition = "2021"
5
rust-version = "1.88"
5
rust-version = "1.88"
6
description = "Designer for POS-print documents"
6
description = "Designer for POS-print documents"
@@ -6,7 +6,7 @@ Cross-platform designer for POS (point-of-sale) receipt documents. Edit template
6
6
7
7
## Status
8
8
9
**v0.1.1** — Rust + egui app with editor, preview, help, `.pos` files, parameters, and USB-serial printing.
9
**v0.2.0** — Rust + egui app with editor, preview, help, `.pos` files, parameters, and USB-serial printing.
10
10
11
11
## Build and run
12
12
@@ -6,7 +6,7 @@ Cross-platform designer for POS (point-of-sale) receipt documents. Edit template6
6
7
## Status7
## Status8
8
9
**v0.1.1** — Rust + egui app with editor, preview, help, `.pos` files, parameters, and USB-serial printing.9
**v0.2.0** — Rust + egui app with editor, preview, help, `.pos` files, parameters, and USB-serial printing.10
10
11
## Build and run11
## Build and run12
12
@@ -1,6 +1,6 @@
1
1
# Maintainer: posprint contributors
2
2
pkgname=posprint
3
pkgver=0.1.1
3
pkgver=0.2.0
4
4
pkgrel=1
5
5
pkgdesc="Designer for POS-print documents with live preview and USB ESC/POS printing"
6
6
arch=('x86_64')
@@ -1,6 +1,6 @@1
# Maintainer: posprint contributors1
# Maintainer: posprint contributors2
pkgname=posprint2
pkgname=posprint3
pkgver=0.1.13
pkgver=0.2.04
pkgrel=14
pkgrel=15
pkgdesc="Designer for POS-print documents with live preview and USB ESC/POS printing"5
pkgdesc="Designer for POS-print documents with live preview and USB ESC/POS printing"6
arch=('x86_64')6
arch=('x86_64')@@ -241,90 +241,96 @@ impl PosPrintApp {
241
241
impl eframe::App for PosPrintApp {
242
242
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
243
243
self.validate_parse();
244
self.handle_shortcuts(ctx);
244
if !self.show_print_dialog {
245
self.handle_shortcuts(ctx);
246
}
245
247
self.print_dialog.poll_printer_discovery(ctx);
246
248
247
egui::TopBottomPanel::top("menu").show(ctx, |ui| {
248
ui.horizontal_wrapped(|ui| {
249
if ui.button("New").clicked() {
250
self.new_document();
251
}
252
if ui.button("Open").clicked() {
253
self.open_file_dialog();
254
}
255
if ui.button("Save").clicked() {
256
self.save();
257
}
258
if ui.button("Save As").clicked() {
259
self.save_as();
260
}
261
if ui.button("Print").clicked() {
262
self.open_print_dialog();
263
}
249
let main_enabled = !self.show_print_dialog;
264
250
265
ui.menu_button("Insert", |ui| {
266
for opt in image_insert_options() {
267
if ui.button(format!("Image — {}", opt.label)).clicked() {
268
self.insert_snippet(&opt.snippet);
269
ui.close_menu();
270
}
251
egui::TopBottomPanel::top("menu").show(ctx, |ui| {
252
ui.add_enabled_ui(main_enabled, |ui| {
253
ui.horizontal_wrapped(|ui| {
254
if ui.button("New").clicked() {
255
self.new_document();
256
}
257
if ui.button("Open").clicked() {
258
self.open_file_dialog();
259
}
260
if ui.button("Save").clicked() {
261
self.save();
262
}
263
if ui.button("Save As").clicked() {
264
self.save_as();
265
}
266
if ui.button("Print").clicked() {
267
self.open_print_dialog();
271
268
}
272
ui.separator();
273
ui.menu_button("Barcode", |ui| {
274
for opt in barcode_insert_options() {
275
if ui.button(&opt.label).clicked() {
269
270
ui.menu_button("Insert", |ui| {
271
for opt in image_insert_options() {
272
if ui.button(format!("Image — {}", opt.label)).clicked() {
276
273
self.insert_snippet(&opt.snippet);
277
274
ui.close_menu();
278
275
}
279
276
}
280
});
281
ui.menu_button("QR code", |ui| {
282
for opt in qr_insert_options() {
283
if ui.button(&opt.label).clicked() {
284
self.insert_snippet(&opt.snippet);
285
ui.close_menu();
277
ui.separator();
278
ui.menu_button("Barcode", |ui| {
279
for opt in barcode_insert_options() {
280
if ui.button(&opt.label).clicked() {
281
self.insert_snippet(&opt.snippet);
282
ui.close_menu();
283
}
286
284
}
287
}
288
});
289
ui.menu_button("Date / time", |ui| {
290
for opt in date_time_insert_options() {
291
if ui.button(&opt.label).clicked() {
292
self.insert_snippet(&opt.snippet);
293
ui.close_menu();
285
});
286
ui.menu_button("QR code", |ui| {
287
for opt in qr_insert_options() {
288
if ui.button(&opt.label).clicked() {
289
self.insert_snippet(&opt.snippet);
290
ui.close_menu();
291
}
294
292
}
295
}
296
});
297
ui.menu_button("Parameters", |ui| {
298
for opt in parameter_insert_options(&self.body) {
299
if ui.button(&opt.label).clicked() {
300
self.insert_snippet(&opt.snippet);
301
ui.close_menu();
293
});
294
ui.menu_button("Date / time", |ui| {
295
for opt in date_time_insert_options() {
296
if ui.button(&opt.label).clicked() {
297
self.insert_snippet(&opt.snippet);
298
ui.close_menu();
299
}
300
}
301
});
302
ui.menu_button("Parameters", |ui| {
303
for opt in parameter_insert_options(&self.body) {
304
if ui.button(&opt.label).clicked() {
305
self.insert_snippet(&opt.snippet);
306
ui.close_menu();
307
}
302
308
}
309
});
310
ui.separator();
311
if ui.button("@feed").clicked() {
312
self.insert_snippet("@feed 3\n");
313
ui.close_menu();
314
}
315
if ui.button("@cut").clicked() {
316
self.insert_snippet("@cut\n");
317
ui.close_menu();
303
318
}
304
319
});
305
ui.separator();
306
if ui.button("@feed").clicked() {
307
self.insert_snippet("@feed 3\n");
308
ui.close_menu();
309
}
310
if ui.button("@cut").clicked() {
311
self.insert_snippet("@cut\n");
312
ui.close_menu();
313
}
314
320
});
315
});
316
321
317
ui.separator();
318
ui.horizontal(|ui| {
319
ui.label("Page width (mm):");
320
let mut width = self.metadata.page_width_mm;
321
if ui
322
.add(egui::DragValue::new(&mut width).range(40.0..=120.0).speed(1.0))
323
.changed()
324
{
325
self.metadata.page_width_mm = width;
326
self.dirty = true;
327
}
322
ui.separator();
323
ui.horizontal(|ui| {
324
ui.label("Page width (mm):");
325
let mut width = self.metadata.page_width_mm;
326
if ui
327
.add(egui::DragValue::new(&mut width).range(40.0..=120.0).speed(1.0))
328
.changed()
329
{
330
self.metadata.page_width_mm = width;
331
self.dirty = true;
332
}
333
});
328
334
});
329
335
330
336
if let Some(err) = &self.parse_error {
@@ -336,56 +342,64 @@ impl eframe::App for PosPrintApp {
336
342
});
337
343
338
344
egui::TopBottomPanel::bottom("tabs").show(ctx, |ui| {
339
ui.horizontal(|ui| {
340
ui.selectable_value(&mut self.view_mode, ViewMode::Design, "Design");
341
ui.selectable_value(&mut self.view_mode, ViewMode::Help, "Help");
342
if let Ok(doc) = parse(&self.body) {
343
if !dsl::document_ends_with_cut(&doc) {
344
ui.colored_label(
345
egui::Color32::RED,
346
"Warning: No @cut directive at end of file.",
347
);
345
ui.add_enabled_ui(main_enabled, |ui| {
346
ui.horizontal(|ui| {
347
ui.selectable_value(&mut self.view_mode, ViewMode::Design, "Design");
348
ui.selectable_value(&mut self.view_mode, ViewMode::Help, "Help");
349
if let Ok(doc) = parse(&self.body) {
350
if !dsl::document_ends_with_cut(&doc) {
351
ui.colored_label(
352
egui::Color32::RED,
353
"Warning: No @cut directive at end of file.",
354
);
355
}
348
356
}
349
}
357
});
350
358
});
351
359
});
352
360
353
361
match self.view_mode {
354
362
ViewMode::Design => {
355
363
egui::SidePanel::right("preview_panel")
356
.resizable(true)
364
.resizable(main_enabled)
357
365
.min_width(260.0)
358
366
.default_width(380.0)
359
367
.show(ctx, |ui| {
360
ui.heading("Preview");
361
ui.horizontal(|ui| {
362
ui.label(format!(
363
"Page width: {:.0} mm",
364
self.metadata.page_width_mm
365
));
368
ui.add_enabled_ui(main_enabled, |ui| {
369
ui.heading("Preview");
370
ui.horizontal(|ui| {
371
ui.label(format!(
372
"Page width: {:.0} mm",
373
self.metadata.page_width_mm
374
));
375
ui.separator();
376
ui.label("Zoom:");
377
ui.add(
378
egui::Slider::new(&mut self.preview_zoom, 0.25..=4.0)
379
.logarithmic(true)
380
.show_value(true),
381
);
382
if ui.button("100%").clicked() {
383
self.preview_zoom = 1.0;
384
}
385
});
366
386
ui.separator();
367
ui.label("Zoom:");
368
ui.add(
369
egui::Slider::new(&mut self.preview_zoom, 0.25..=4.0)
370
.logarithmic(true)
371
.show_value(true),
372
);
373
if ui.button("100%").clicked() {
374
self.preview_zoom = 1.0;
375
}
387
self.show_preview(ui, ctx);
376
388
});
377
ui.separator();
378
self.show_preview(ui, ctx);
379
389
});
380
390
381
391
egui::CentralPanel::default().show(ctx, |ui| {
382
ui.heading("Editor");
383
self.show_editor(ui);
392
ui.add_enabled_ui(main_enabled, |ui| {
393
ui.heading("Editor");
394
self.show_editor(ui);
395
});
384
396
});
385
397
}
386
398
ViewMode::Help => {
387
399
egui::CentralPanel::default().show(ctx, |ui| {
388
help_view::show_help(ui, HELP_MARKDOWN);
400
ui.add_enabled_ui(main_enabled, |ui| {
401
help_view::show_help(ui, HELP_MARKDOWN);
402
});
389
403
});
390
404
}
391
405
}
@@ -428,7 +442,11 @@ impl PosPrintApp {
428
442
let before = self.body.clone();
429
443
let cursor_before = self.editor_cursor;
430
444
431
let directive_ctx = at_directive_prefix(&self.body, cursor_before);
445
// Autocomplete steals focus every frame; keep it off while the print dialog is open.
446
let autocomplete_enabled = !self.show_print_dialog;
447
let directive_ctx = autocomplete_enabled
448
.then(|| at_directive_prefix(&self.body, cursor_before))
449
.flatten();
432
450
let autocomplete_active = directive_ctx.as_ref().is_some_and(|(_, prefix)| {
433
451
complete_directive(prefix).is_some() || directive_ghost_suffix(prefix).is_some()
434
452
});
@@ -450,7 +468,7 @@ impl PosPrintApp {
450
468
.desired_width(f32::INFINITY)
451
469
.desired_rows(30)
452
470
.font(egui::TextStyle::Monospace)
453
.lock_focus(true)
471
.lock_focus(autocomplete_active)
454
472
.show(ui);
455
473
456
474
if autocomplete_active {
@@ -483,20 +501,22 @@ impl PosPrintApp {
483
501
self.dirty = true;
484
502
}
485
503
486
if let Some((_at_index, prefix)) = at_directive_prefix(&self.body, self.editor_cursor) {
487
if let Some(suffix) = directive_ghost_suffix(&prefix) {
488
if let Some(cursor_range) = &output.cursor_range {
489
let font_id = egui::TextStyle::Monospace.resolve(ui.style());
490
let pos = output.galley.pos_from_cursor(&cursor_range.primary);
491
let ghost_pos = output.galley_pos + pos.min.to_vec2();
492
let ghost_color = ui.visuals().weak_text_color();
493
ui.painter().text(
494
ghost_pos,
495
egui::Align2::LEFT_TOP,
496
suffix,
497
font_id,
498
ghost_color,
499
);
504
if autocomplete_enabled {
505
if let Some((_at_index, prefix)) = at_directive_prefix(&self.body, self.editor_cursor) {
506
if let Some(suffix) = directive_ghost_suffix(&prefix) {
507
if let Some(cursor_range) = &output.cursor_range {
508
let font_id = egui::TextStyle::Monospace.resolve(ui.style());
509
let pos = output.galley.pos_from_cursor(&cursor_range.primary);
510
let ghost_pos = output.galley_pos + pos.min.to_vec2();
511
let ghost_color = ui.visuals().weak_text_color();
512
ui.painter().text(
513
ghost_pos,
514
egui::Align2::LEFT_TOP,
515
suffix,
516
font_id,
517
ghost_color,
518
);
519
}
500
520
}
501
521
}
502
522
}
@@ -241,90 +241,96 @@ impl PosPrintApp {241
impl eframe::App for PosPrintApp {
241
impl eframe::App for PosPrintApp {
242
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
242
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
243
self.validate_parse();
243
self.validate_parse();
244
self.handle_shortcuts(ctx);
244
if !self.show_print_dialog {
245
self.handle_shortcuts(ctx);
246
}
245
self.print_dialog.poll_printer_discovery(ctx);
247
self.print_dialog.poll_printer_discovery(ctx);
246
248
247
egui::TopBottomPanel::top("menu").show(ctx, |ui| {
249
let main_enabled = !self.show_print_dialog;
248
ui.horizontal_wrapped(|ui| {
249
if ui.button("New").clicked() {
250
self.new_document();
251
}
252
if ui.button("Open").clicked() {
253
self.open_file_dialog();
254
}
255
if ui.button("Save").clicked() {
256
self.save();
257
}
258
if ui.button("Save As").clicked() {
259
self.save_as();
260
}
261
if ui.button("Print").clicked() {
262
self.open_print_dialog();
263
}
264
250
265
ui.menu_button("Insert", |ui| {
251
egui::TopBottomPanel::top("menu").show(ctx, |ui| {
266
for opt in image_insert_options() {
252
ui.add_enabled_ui(main_enabled, |ui| {
267
if ui.button(format!("Image — {}", opt.label)).clicked() {
253
ui.horizontal_wrapped(|ui| {
268
self.insert_snippet(&opt.snippet);
254
if ui.button("New").clicked() {
269
ui.close_menu();
255
self.new_document();
270
}
256
}
257
if ui.button("Open").clicked() {
258
self.open_file_dialog();
259
}
260
if ui.button("Save").clicked() {
261
self.save();
262
}
263
if ui.button("Save As").clicked() {
264
self.save_as();
265
}
266
if ui.button("Print").clicked() {
267
self.open_print_dialog();
271
}
268
}
272
ui.separator();
269
273
ui.menu_button("Barcode", |ui| {
270
ui.menu_button("Insert", |ui| {
274
for opt in barcode_insert_options() {
271
for opt in image_insert_options() {
275
if ui.button(&opt.label).clicked() {
272
if ui.button(format!("Image — {}", opt.label)).clicked() {
276
self.insert_snippet(&opt.snippet);
273
self.insert_snippet(&opt.snippet);
277
ui.close_menu();
274
ui.close_menu();
278
}
275
}
279
}
276
}
280
});
277
ui.separator();
281
ui.menu_button("QR code", |ui| {
278
ui.menu_button("Barcode", |ui| {
282
for opt in qr_insert_options() {
279
for opt in barcode_insert_options() {
283
if ui.button(&opt.label).clicked() {
280
if ui.button(&opt.label).clicked() {
284
self.insert_snippet(&opt.snippet);
281
self.insert_snippet(&opt.snippet);
285
ui.close_menu();
282
ui.close_menu();
283
}
286
}
284
}
287
}
285
});
288
});
286
ui.menu_button("QR code", |ui| {
289
ui.menu_button("Date / time", |ui| {
287
for opt in qr_insert_options() {
290
for opt in date_time_insert_options() {
288
if ui.button(&opt.label).clicked() {
291
if ui.button(&opt.label).clicked() {
289
self.insert_snippet(&opt.snippet);
292
self.insert_snippet(&opt.snippet);
290
ui.close_menu();
293
ui.close_menu();
291
}
294
}
292
}
295
}
293
});
296
});
294
ui.menu_button("Date / time", |ui| {
297
ui.menu_button("Parameters", |ui| {
295
for opt in date_time_insert_options() {
298
for opt in parameter_insert_options(&self.body) {
296
if ui.button(&opt.label).clicked() {
299
if ui.button(&opt.label).clicked() {
297
self.insert_snippet(&opt.snippet);
300
self.insert_snippet(&opt.snippet);
298
ui.close_menu();
301
ui.close_menu();
299
}
300
}
301
});
302
ui.menu_button("Parameters", |ui| {
303
for opt in parameter_insert_options(&self.body) {
304
if ui.button(&opt.label).clicked() {
305
self.insert_snippet(&opt.snippet);
306
ui.close_menu();
307
}
302
}
308
}
309
});
310
ui.separator();
311
if ui.button("@feed").clicked() {
312
self.insert_snippet("@feed 3\n");
313
ui.close_menu();
314
}
315
if ui.button("@cut").clicked() {
316
self.insert_snippet("@cut\n");
317
ui.close_menu();
303
}
318
}
304
});
319
});
305
ui.separator();
306
if ui.button("@feed").clicked() {
307
self.insert_snippet("@feed 3\n");
308
ui.close_menu();
309
}
310
if ui.button("@cut").clicked() {
311
self.insert_snippet("@cut\n");
312
ui.close_menu();
313
}
314
});
320
});
315
});
316
321
317
ui.separator();
322
ui.separator();
318
ui.horizontal(|ui| {
323
ui.horizontal(|ui| {
319
ui.label("Page width (mm):");
324
ui.label("Page width (mm):");
320
let mut width = self.metadata.page_width_mm;
325
let mut width = self.metadata.page_width_mm;
321
if ui
326
if ui
322
.add(egui::DragValue::new(&mut width).range(40.0..=120.0).speed(1.0))
327
.add(egui::DragValue::new(&mut width).range(40.0..=120.0).speed(1.0))
323
.changed()
328
.changed()
324
{
329
{
325
self.metadata.page_width_mm = width;
330
self.metadata.page_width_mm = width;
326
self.dirty = true;
331
self.dirty = true;
327
}
332
}
333
});
328
});
334
});
329
335
330
if let Some(err) = &self.parse_error {
336
if let Some(err) = &self.parse_error {
@@ -336,56 +342,64 @@ impl eframe::App for PosPrintApp {336
});
342
});
337
343
338
egui::TopBottomPanel::bottom("tabs").show(ctx, |ui| {
344
egui::TopBottomPanel::bottom("tabs").show(ctx, |ui| {
339
ui.horizontal(|ui| {
345
ui.add_enabled_ui(main_enabled, |ui| {
340
ui.selectable_value(&mut self.view_mode, ViewMode::Design, "Design");
346
ui.horizontal(|ui| {
341
ui.selectable_value(&mut self.view_mode, ViewMode::Help, "Help");
347
ui.selectable_value(&mut self.view_mode, ViewMode::Design, "Design");
342
if let Ok(doc) = parse(&self.body) {
348
ui.selectable_value(&mut self.view_mode, ViewMode::Help, "Help");
343
if !dsl::document_ends_with_cut(&doc) {
349
if let Ok(doc) = parse(&self.body) {
344
ui.colored_label(
350
if !dsl::document_ends_with_cut(&doc) {
345
egui::Color32::RED,
351
ui.colored_label(
346
"Warning: No @cut directive at end of file.",
352
egui::Color32::RED,
347
);
353
"Warning: No @cut directive at end of file.",
354
);
355
}
348
}
356
}
349
}
357
});
350
});
358
});
351
});
359
});
352
360
353
match self.view_mode {
361
match self.view_mode {
354
ViewMode::Design => {
362
ViewMode::Design => {
355
egui::SidePanel::right("preview_panel")
363
egui::SidePanel::right("preview_panel")
356
.resizable(true)
364
.resizable(main_enabled)
357
.min_width(260.0)
365
.min_width(260.0)
358
.default_width(380.0)
366
.default_width(380.0)
359
.show(ctx, |ui| {
367
.show(ctx, |ui| {
360
ui.heading("Preview");
368
ui.add_enabled_ui(main_enabled, |ui| {
361
ui.horizontal(|ui| {
369
ui.heading("Preview");
362
ui.label(format!(
370
ui.horizontal(|ui| {
363
"Page width: {:.0} mm",
371
ui.label(format!(
364
self.metadata.page_width_mm
372
"Page width: {:.0} mm",
365
));
373
self.metadata.page_width_mm
374
));
375
ui.separator();
376
ui.label("Zoom:");
377
ui.add(
378
egui::Slider::new(&mut self.preview_zoom, 0.25..=4.0)
379
.logarithmic(true)
380
.show_value(true),
381
);
382
if ui.button("100%").clicked() {
383
self.preview_zoom = 1.0;
384
}
385
});
366
ui.separator();
386
ui.separator();
367
ui.label("Zoom:");
387
self.show_preview(ui, ctx);
368
ui.add(
369
egui::Slider::new(&mut self.preview_zoom, 0.25..=4.0)
370
.logarithmic(true)
371
.show_value(true),
372
);
373
if ui.button("100%").clicked() {
374
self.preview_zoom = 1.0;
375
}
376
});
388
});
377
ui.separator();
378
self.show_preview(ui, ctx);
379
});
389
});
380
390
381
egui::CentralPanel::default().show(ctx, |ui| {
391
egui::CentralPanel::default().show(ctx, |ui| {
382
ui.heading("Editor");
392
ui.add_enabled_ui(main_enabled, |ui| {
383
self.show_editor(ui);
393
ui.heading("Editor");
394
self.show_editor(ui);
395
});
384
});
396
});
385
}
397
}
386
ViewMode::Help => {
398
ViewMode::Help => {
387
egui::CentralPanel::default().show(ctx, |ui| {
399
egui::CentralPanel::default().show(ctx, |ui| {
388
help_view::show_help(ui, HELP_MARKDOWN);
400
ui.add_enabled_ui(main_enabled, |ui| {
401
help_view::show_help(ui, HELP_MARKDOWN);
402
});
389
});
403
});
390
}
404
}
391
}
405
}
@@ -428,7 +442,11 @@ impl PosPrintApp {428
let before = self.body.clone();
442
let before = self.body.clone();
429
let cursor_before = self.editor_cursor;
443
let cursor_before = self.editor_cursor;
430
444
431
let directive_ctx = at_directive_prefix(&self.body, cursor_before);
445
// Autocomplete steals focus every frame; keep it off while the print dialog is open.
446
let autocomplete_enabled = !self.show_print_dialog;
447
let directive_ctx = autocomplete_enabled
448
.then(|| at_directive_prefix(&self.body, cursor_before))
449
.flatten();
432
let autocomplete_active = directive_ctx.as_ref().is_some_and(|(_, prefix)| {
450
let autocomplete_active = directive_ctx.as_ref().is_some_and(|(_, prefix)| {
433
complete_directive(prefix).is_some() || directive_ghost_suffix(prefix).is_some()
451
complete_directive(prefix).is_some() || directive_ghost_suffix(prefix).is_some()
434
});
452
});
@@ -450,7 +468,7 @@ impl PosPrintApp {450
.desired_width(f32::INFINITY)
468
.desired_width(f32::INFINITY)
451
.desired_rows(30)
469
.desired_rows(30)
452
.font(egui::TextStyle::Monospace)
470
.font(egui::TextStyle::Monospace)
453
.lock_focus(true)
471
.lock_focus(autocomplete_active)
454
.show(ui);
472
.show(ui);
455
473
456
if autocomplete_active {
474
if autocomplete_active {
@@ -483,20 +501,22 @@ impl PosPrintApp {483
self.dirty = true;
501
self.dirty = true;
484
}
502
}
485
503
486
if let Some((_at_index, prefix)) = at_directive_prefix(&self.body, self.editor_cursor) {
504
if autocomplete_enabled {
487
if let Some(suffix) = directive_ghost_suffix(&prefix) {
505
if let Some((_at_index, prefix)) = at_directive_prefix(&self.body, self.editor_cursor) {
488
if let Some(cursor_range) = &output.cursor_range {
506
if let Some(suffix) = directive_ghost_suffix(&prefix) {
489
let font_id = egui::TextStyle::Monospace.resolve(ui.style());
507
if let Some(cursor_range) = &output.cursor_range {
490
let pos = output.galley.pos_from_cursor(&cursor_range.primary);
508
let font_id = egui::TextStyle::Monospace.resolve(ui.style());
491
let ghost_pos = output.galley_pos + pos.min.to_vec2();
509
let pos = output.galley.pos_from_cursor(&cursor_range.primary);
492
let ghost_color = ui.visuals().weak_text_color();
510
let ghost_pos = output.galley_pos + pos.min.to_vec2();
493
ui.painter().text(
511
let ghost_color = ui.visuals().weak_text_color();
494
ghost_pos,
512
ui.painter().text(
495
egui::Align2::LEFT_TOP,
513
ghost_pos,
496
suffix,
514
egui::Align2::LEFT_TOP,
497
font_id,
515
suffix,
498
ghost_color,
516
font_id,
499
);
517
ghost_color,
518
);
519
}
500
}
520
}
501
}
521
}
502
}
522
}
@@ -549,6 +549,14 @@ mod tests {
549
549
assert!((preview_font_size_px(char_w) - char_w / 0.6).abs() < 0.001);
550
550
}
551
551
552
#[test]
553
fn char_width_fits_columns_on_paper() {
554
let meta = PosMetadata::default();
555
let width = preview_content_width_px(&meta) * preview_visual_scale(1.0);
556
let char_w = preview_char_width_px(&meta, 1.0);
557
assert!((char_w * meta.chars_per_line() as f32 - width).abs() < 0.01);
558
}
559
552
560
#[test]
553
561
fn heading1_is_double_normal_text_height() {
554
562
let meta = PosMetadata::default();
@@ -549,6 +549,14 @@ mod tests {549
assert!((preview_font_size_px(char_w) - char_w / 0.6).abs() < 0.001);
549
assert!((preview_font_size_px(char_w) - char_w / 0.6).abs() < 0.001);
550
}
550
}
551
551
552
#[test]
553
fn char_width_fits_columns_on_paper() {
554
let meta = PosMetadata::default();
555
let width = preview_content_width_px(&meta) * preview_visual_scale(1.0);
556
let char_w = preview_char_width_px(&meta, 1.0);
557
assert!((char_w * meta.chars_per_line() as f32 - width).abs() < 0.01);
558
}
559
552
#[test]
560
#[test]
553
fn heading1_is_double_normal_text_height() {
561
fn heading1_is_double_normal_text_height() {
554
let meta = PosMetadata::default();
562
let meta = PosMetadata::default();