pub struct Printer { /* private fields */ }
Expand description
Defines a printer object. Example usage:
use fltk::{prelude::*, *};
let mut but = button::Button::default();
but.set_callback(|widget| {
let mut printer = printer::Printer::default();
if printer.begin_job(1).is_ok() {
printer.begin_page().ok();
let (width, height) = printer.printable_rect();
draw::set_draw_color(enums::Color::Black);
draw::set_line_style(draw::LineStyle::Solid, 2);
draw::draw_rect(0, 0, width, height);
draw::set_font(enums::Font::Courier, 12);
printer.set_origin(width / 2, height / 2);
printer.print_widget(widget, -widget.w() / 2, -widget.h() / 2);
printer.end_page().ok();
printer.end_job();
}
});
Implementations§
Source§impl Printer
impl Printer
Sourcepub fn begin_job(
&mut self,
pagecount: i32,
) -> Result<(Option<i32>, Option<i32>), FltkError>
pub fn begin_job( &mut self, pagecount: i32, ) -> Result<(Option<i32>, Option<i32>), FltkError>
Begins a print job.
pagecount
The total number of pages to be created. Use 0 if this number is unknown
Returns a tuple (frompage, topage) indicating the chosen pages by the user
§Errors
Errors on failure to print
Examples found in repository?
362 pub fn launch(&mut self) {
363 while self.app.wait() {
364 use Message::*;
365 if let Some(msg) = self.r.recv() {
366 match msg {
367 Changed => {
368 if !self.modified {
369 self.modified = true;
370 self.menu
371 .menu
372 .find_item("&File/&Save\t")
373 .unwrap()
374 .activate();
375 self.menu
376 .menu
377 .find_item("&File/&Quit\t")
378 .unwrap()
379 .set_label_color(Color::Red);
380 let name = match &self.filename {
381 Some(f) => f.to_string_lossy().to_string(),
382 None => "(Untitled)".to_string(),
383 };
384 self.main_win.set_label(&format!("* {name} - RustyEd"));
385 }
386 }
387 New => {
388 if self.buf.text() != "" {
389 let clear = if let Some(x) = dialog::choice(
390 "File unsaved, Do you wish to continue?",
391 "&Yes",
392 "&No!",
393 "",
394 ) {
395 x == 0
396 } else {
397 false
398 };
399 if clear {
400 self.buf.set_text("");
401 }
402 }
403 }
404 Open => {
405 if let Some(c) = nfc_get_file(dialog::NativeFileChooserType::BrowseFile) {
406 if c.exists() {
407 match self.buf.load_file(&c) {
408 Ok(_) => self.filename = Some(c),
409 Err(e) => dialog::alert(&format!(
410 "An issue occured while loading the file: {e}"
411 )),
412 }
413 } else {
414 dialog::alert("File does not exist!")
415 }
416 }
417 }
418 Save => {
419 self.save_file().unwrap();
420 }
421 SaveAs => {
422 self.save_file_as().unwrap();
423 }
424 Print => {
425 let mut printer = printer::Printer::default();
426 if printer.begin_job(0).is_ok() {
427 let (w, h) = printer.printable_rect();
428 self.printable.resize(
429 self.printable.x(),
430 self.printable.y(),
431 w - 40,
432 h - 40,
433 );
434 // Needs cleanup
435 let line_count = self.printable.count_lines(
436 0,
437 self.printable.buffer().unwrap().length(),
438 true,
439 ) / 45;
440 for i in 0..=line_count {
441 self.printable.scroll(45 * i, 0);
442 printer.begin_page().ok();
443 printer.print_widget(&self.printable, 20, 20);
444 printer.end_page().ok();
445 }
446 printer.end_job();
447 }
448 }
449 Quit => {
450 if self.modified {
451 match dialog::choice(
452 "Would you like to save your work?",
453 "&Yes",
454 "&No",
455 "",
456 ) {
457 Some(0) => {
458 if self.save_file().unwrap() {
459 self.app.quit();
460 }
461 }
462 Some(1) => self.app.quit(),
463 Some(_) | None => (),
464 }
465 } else {
466 self.app.quit();
467 }
468 }
469 Cut => self.editor.cut(),
470 Copy => self.editor.copy(),
471 Paste => self.editor.paste(),
472 About => dialog::message(
473 "This is an example application written in Rust and using the FLTK Gui library.",
474 ),
475 }
476 }
477 }
478 }
Sourcepub fn end_page(&mut self) -> Result<(), FltkError>
pub fn end_page(&mut self) -> Result<(), FltkError>
Examples found in repository?
362 pub fn launch(&mut self) {
363 while self.app.wait() {
364 use Message::*;
365 if let Some(msg) = self.r.recv() {
366 match msg {
367 Changed => {
368 if !self.modified {
369 self.modified = true;
370 self.menu
371 .menu
372 .find_item("&File/&Save\t")
373 .unwrap()
374 .activate();
375 self.menu
376 .menu
377 .find_item("&File/&Quit\t")
378 .unwrap()
379 .set_label_color(Color::Red);
380 let name = match &self.filename {
381 Some(f) => f.to_string_lossy().to_string(),
382 None => "(Untitled)".to_string(),
383 };
384 self.main_win.set_label(&format!("* {name} - RustyEd"));
385 }
386 }
387 New => {
388 if self.buf.text() != "" {
389 let clear = if let Some(x) = dialog::choice(
390 "File unsaved, Do you wish to continue?",
391 "&Yes",
392 "&No!",
393 "",
394 ) {
395 x == 0
396 } else {
397 false
398 };
399 if clear {
400 self.buf.set_text("");
401 }
402 }
403 }
404 Open => {
405 if let Some(c) = nfc_get_file(dialog::NativeFileChooserType::BrowseFile) {
406 if c.exists() {
407 match self.buf.load_file(&c) {
408 Ok(_) => self.filename = Some(c),
409 Err(e) => dialog::alert(&format!(
410 "An issue occured while loading the file: {e}"
411 )),
412 }
413 } else {
414 dialog::alert("File does not exist!")
415 }
416 }
417 }
418 Save => {
419 self.save_file().unwrap();
420 }
421 SaveAs => {
422 self.save_file_as().unwrap();
423 }
424 Print => {
425 let mut printer = printer::Printer::default();
426 if printer.begin_job(0).is_ok() {
427 let (w, h) = printer.printable_rect();
428 self.printable.resize(
429 self.printable.x(),
430 self.printable.y(),
431 w - 40,
432 h - 40,
433 );
434 // Needs cleanup
435 let line_count = self.printable.count_lines(
436 0,
437 self.printable.buffer().unwrap().length(),
438 true,
439 ) / 45;
440 for i in 0..=line_count {
441 self.printable.scroll(45 * i, 0);
442 printer.begin_page().ok();
443 printer.print_widget(&self.printable, 20, 20);
444 printer.end_page().ok();
445 }
446 printer.end_job();
447 }
448 }
449 Quit => {
450 if self.modified {
451 match dialog::choice(
452 "Would you like to save your work?",
453 "&Yes",
454 "&No",
455 "",
456 ) {
457 Some(0) => {
458 if self.save_file().unwrap() {
459 self.app.quit();
460 }
461 }
462 Some(1) => self.app.quit(),
463 Some(_) | None => (),
464 }
465 } else {
466 self.app.quit();
467 }
468 }
469 Cut => self.editor.cut(),
470 Copy => self.editor.copy(),
471 Paste => self.editor.paste(),
472 About => dialog::message(
473 "This is an example application written in Rust and using the FLTK Gui library.",
474 ),
475 }
476 }
477 }
478 }
Sourcepub fn end_job(&mut self)
pub fn end_job(&mut self)
Ends the print job
Examples found in repository?
362 pub fn launch(&mut self) {
363 while self.app.wait() {
364 use Message::*;
365 if let Some(msg) = self.r.recv() {
366 match msg {
367 Changed => {
368 if !self.modified {
369 self.modified = true;
370 self.menu
371 .menu
372 .find_item("&File/&Save\t")
373 .unwrap()
374 .activate();
375 self.menu
376 .menu
377 .find_item("&File/&Quit\t")
378 .unwrap()
379 .set_label_color(Color::Red);
380 let name = match &self.filename {
381 Some(f) => f.to_string_lossy().to_string(),
382 None => "(Untitled)".to_string(),
383 };
384 self.main_win.set_label(&format!("* {name} - RustyEd"));
385 }
386 }
387 New => {
388 if self.buf.text() != "" {
389 let clear = if let Some(x) = dialog::choice(
390 "File unsaved, Do you wish to continue?",
391 "&Yes",
392 "&No!",
393 "",
394 ) {
395 x == 0
396 } else {
397 false
398 };
399 if clear {
400 self.buf.set_text("");
401 }
402 }
403 }
404 Open => {
405 if let Some(c) = nfc_get_file(dialog::NativeFileChooserType::BrowseFile) {
406 if c.exists() {
407 match self.buf.load_file(&c) {
408 Ok(_) => self.filename = Some(c),
409 Err(e) => dialog::alert(&format!(
410 "An issue occured while loading the file: {e}"
411 )),
412 }
413 } else {
414 dialog::alert("File does not exist!")
415 }
416 }
417 }
418 Save => {
419 self.save_file().unwrap();
420 }
421 SaveAs => {
422 self.save_file_as().unwrap();
423 }
424 Print => {
425 let mut printer = printer::Printer::default();
426 if printer.begin_job(0).is_ok() {
427 let (w, h) = printer.printable_rect();
428 self.printable.resize(
429 self.printable.x(),
430 self.printable.y(),
431 w - 40,
432 h - 40,
433 );
434 // Needs cleanup
435 let line_count = self.printable.count_lines(
436 0,
437 self.printable.buffer().unwrap().length(),
438 true,
439 ) / 45;
440 for i in 0..=line_count {
441 self.printable.scroll(45 * i, 0);
442 printer.begin_page().ok();
443 printer.print_widget(&self.printable, 20, 20);
444 printer.end_page().ok();
445 }
446 printer.end_job();
447 }
448 }
449 Quit => {
450 if self.modified {
451 match dialog::choice(
452 "Would you like to save your work?",
453 "&Yes",
454 "&No",
455 "",
456 ) {
457 Some(0) => {
458 if self.save_file().unwrap() {
459 self.app.quit();
460 }
461 }
462 Some(1) => self.app.quit(),
463 Some(_) | None => (),
464 }
465 } else {
466 self.app.quit();
467 }
468 }
469 Cut => self.editor.cut(),
470 Copy => self.editor.copy(),
471 Paste => self.editor.paste(),
472 About => dialog::message(
473 "This is an example application written in Rust and using the FLTK Gui library.",
474 ),
475 }
476 }
477 }
478 }
Sourcepub fn begin_page(&mut self) -> Result<(), FltkError>
pub fn begin_page(&mut self) -> Result<(), FltkError>
Examples found in repository?
362 pub fn launch(&mut self) {
363 while self.app.wait() {
364 use Message::*;
365 if let Some(msg) = self.r.recv() {
366 match msg {
367 Changed => {
368 if !self.modified {
369 self.modified = true;
370 self.menu
371 .menu
372 .find_item("&File/&Save\t")
373 .unwrap()
374 .activate();
375 self.menu
376 .menu
377 .find_item("&File/&Quit\t")
378 .unwrap()
379 .set_label_color(Color::Red);
380 let name = match &self.filename {
381 Some(f) => f.to_string_lossy().to_string(),
382 None => "(Untitled)".to_string(),
383 };
384 self.main_win.set_label(&format!("* {name} - RustyEd"));
385 }
386 }
387 New => {
388 if self.buf.text() != "" {
389 let clear = if let Some(x) = dialog::choice(
390 "File unsaved, Do you wish to continue?",
391 "&Yes",
392 "&No!",
393 "",
394 ) {
395 x == 0
396 } else {
397 false
398 };
399 if clear {
400 self.buf.set_text("");
401 }
402 }
403 }
404 Open => {
405 if let Some(c) = nfc_get_file(dialog::NativeFileChooserType::BrowseFile) {
406 if c.exists() {
407 match self.buf.load_file(&c) {
408 Ok(_) => self.filename = Some(c),
409 Err(e) => dialog::alert(&format!(
410 "An issue occured while loading the file: {e}"
411 )),
412 }
413 } else {
414 dialog::alert("File does not exist!")
415 }
416 }
417 }
418 Save => {
419 self.save_file().unwrap();
420 }
421 SaveAs => {
422 self.save_file_as().unwrap();
423 }
424 Print => {
425 let mut printer = printer::Printer::default();
426 if printer.begin_job(0).is_ok() {
427 let (w, h) = printer.printable_rect();
428 self.printable.resize(
429 self.printable.x(),
430 self.printable.y(),
431 w - 40,
432 h - 40,
433 );
434 // Needs cleanup
435 let line_count = self.printable.count_lines(
436 0,
437 self.printable.buffer().unwrap().length(),
438 true,
439 ) / 45;
440 for i in 0..=line_count {
441 self.printable.scroll(45 * i, 0);
442 printer.begin_page().ok();
443 printer.print_widget(&self.printable, 20, 20);
444 printer.end_page().ok();
445 }
446 printer.end_job();
447 }
448 }
449 Quit => {
450 if self.modified {
451 match dialog::choice(
452 "Would you like to save your work?",
453 "&Yes",
454 "&No",
455 "",
456 ) {
457 Some(0) => {
458 if self.save_file().unwrap() {
459 self.app.quit();
460 }
461 }
462 Some(1) => self.app.quit(),
463 Some(_) | None => (),
464 }
465 } else {
466 self.app.quit();
467 }
468 }
469 Cut => self.editor.cut(),
470 Copy => self.editor.copy(),
471 Paste => self.editor.paste(),
472 About => dialog::message(
473 "This is an example application written in Rust and using the FLTK Gui library.",
474 ),
475 }
476 }
477 }
478 }
Sourcepub fn printable_rect(&self) -> (i32, i32)
pub fn printable_rect(&self) -> (i32, i32)
Returns the width and height of the printable rect
Examples found in repository?
362 pub fn launch(&mut self) {
363 while self.app.wait() {
364 use Message::*;
365 if let Some(msg) = self.r.recv() {
366 match msg {
367 Changed => {
368 if !self.modified {
369 self.modified = true;
370 self.menu
371 .menu
372 .find_item("&File/&Save\t")
373 .unwrap()
374 .activate();
375 self.menu
376 .menu
377 .find_item("&File/&Quit\t")
378 .unwrap()
379 .set_label_color(Color::Red);
380 let name = match &self.filename {
381 Some(f) => f.to_string_lossy().to_string(),
382 None => "(Untitled)".to_string(),
383 };
384 self.main_win.set_label(&format!("* {name} - RustyEd"));
385 }
386 }
387 New => {
388 if self.buf.text() != "" {
389 let clear = if let Some(x) = dialog::choice(
390 "File unsaved, Do you wish to continue?",
391 "&Yes",
392 "&No!",
393 "",
394 ) {
395 x == 0
396 } else {
397 false
398 };
399 if clear {
400 self.buf.set_text("");
401 }
402 }
403 }
404 Open => {
405 if let Some(c) = nfc_get_file(dialog::NativeFileChooserType::BrowseFile) {
406 if c.exists() {
407 match self.buf.load_file(&c) {
408 Ok(_) => self.filename = Some(c),
409 Err(e) => dialog::alert(&format!(
410 "An issue occured while loading the file: {e}"
411 )),
412 }
413 } else {
414 dialog::alert("File does not exist!")
415 }
416 }
417 }
418 Save => {
419 self.save_file().unwrap();
420 }
421 SaveAs => {
422 self.save_file_as().unwrap();
423 }
424 Print => {
425 let mut printer = printer::Printer::default();
426 if printer.begin_job(0).is_ok() {
427 let (w, h) = printer.printable_rect();
428 self.printable.resize(
429 self.printable.x(),
430 self.printable.y(),
431 w - 40,
432 h - 40,
433 );
434 // Needs cleanup
435 let line_count = self.printable.count_lines(
436 0,
437 self.printable.buffer().unwrap().length(),
438 true,
439 ) / 45;
440 for i in 0..=line_count {
441 self.printable.scroll(45 * i, 0);
442 printer.begin_page().ok();
443 printer.print_widget(&self.printable, 20, 20);
444 printer.end_page().ok();
445 }
446 printer.end_job();
447 }
448 }
449 Quit => {
450 if self.modified {
451 match dialog::choice(
452 "Would you like to save your work?",
453 "&Yes",
454 "&No",
455 "",
456 ) {
457 Some(0) => {
458 if self.save_file().unwrap() {
459 self.app.quit();
460 }
461 }
462 Some(1) => self.app.quit(),
463 Some(_) | None => (),
464 }
465 } else {
466 self.app.quit();
467 }
468 }
469 Cut => self.editor.cut(),
470 Copy => self.editor.copy(),
471 Paste => self.editor.paste(),
472 About => dialog::message(
473 "This is an example application written in Rust and using the FLTK Gui library.",
474 ),
475 }
476 }
477 }
478 }
Sourcepub fn margins(&self) -> (i32, i32, i32, i32)
pub fn margins(&self) -> (i32, i32, i32, i32)
Returns the coordinates of the printable margins. (left, top, right, bottom)
Sourcepub fn set_origin(&mut self, x: i32, y: i32)
pub fn set_origin(&mut self, x: i32, y: i32)
Set the origin coordinates of the printable rect
Sourcepub fn untranslate(&mut self)
pub fn untranslate(&mut self)
Untranslate the printable rect
Sourcepub fn is_current(&self) -> bool
pub fn is_current(&self) -> bool
Check whether the printer is the current printer
Sourcepub fn set_current(&mut self)
pub fn set_current(&mut self)
Set the printer to be the current printer
Sourcepub fn print_widget<W: WidgetExt>(&self, widget: &W, delta_x: i32, delta_y: i32)
pub fn print_widget<W: WidgetExt>(&self, widget: &W, delta_x: i32, delta_y: i32)
Print a widget
Examples found in repository?
362 pub fn launch(&mut self) {
363 while self.app.wait() {
364 use Message::*;
365 if let Some(msg) = self.r.recv() {
366 match msg {
367 Changed => {
368 if !self.modified {
369 self.modified = true;
370 self.menu
371 .menu
372 .find_item("&File/&Save\t")
373 .unwrap()
374 .activate();
375 self.menu
376 .menu
377 .find_item("&File/&Quit\t")
378 .unwrap()
379 .set_label_color(Color::Red);
380 let name = match &self.filename {
381 Some(f) => f.to_string_lossy().to_string(),
382 None => "(Untitled)".to_string(),
383 };
384 self.main_win.set_label(&format!("* {name} - RustyEd"));
385 }
386 }
387 New => {
388 if self.buf.text() != "" {
389 let clear = if let Some(x) = dialog::choice(
390 "File unsaved, Do you wish to continue?",
391 "&Yes",
392 "&No!",
393 "",
394 ) {
395 x == 0
396 } else {
397 false
398 };
399 if clear {
400 self.buf.set_text("");
401 }
402 }
403 }
404 Open => {
405 if let Some(c) = nfc_get_file(dialog::NativeFileChooserType::BrowseFile) {
406 if c.exists() {
407 match self.buf.load_file(&c) {
408 Ok(_) => self.filename = Some(c),
409 Err(e) => dialog::alert(&format!(
410 "An issue occured while loading the file: {e}"
411 )),
412 }
413 } else {
414 dialog::alert("File does not exist!")
415 }
416 }
417 }
418 Save => {
419 self.save_file().unwrap();
420 }
421 SaveAs => {
422 self.save_file_as().unwrap();
423 }
424 Print => {
425 let mut printer = printer::Printer::default();
426 if printer.begin_job(0).is_ok() {
427 let (w, h) = printer.printable_rect();
428 self.printable.resize(
429 self.printable.x(),
430 self.printable.y(),
431 w - 40,
432 h - 40,
433 );
434 // Needs cleanup
435 let line_count = self.printable.count_lines(
436 0,
437 self.printable.buffer().unwrap().length(),
438 true,
439 ) / 45;
440 for i in 0..=line_count {
441 self.printable.scroll(45 * i, 0);
442 printer.begin_page().ok();
443 printer.print_widget(&self.printable, 20, 20);
444 printer.end_page().ok();
445 }
446 printer.end_job();
447 }
448 }
449 Quit => {
450 if self.modified {
451 match dialog::choice(
452 "Would you like to save your work?",
453 "&Yes",
454 "&No",
455 "",
456 ) {
457 Some(0) => {
458 if self.save_file().unwrap() {
459 self.app.quit();
460 }
461 }
462 Some(1) => self.app.quit(),
463 Some(_) | None => (),
464 }
465 } else {
466 self.app.quit();
467 }
468 }
469 Cut => self.editor.cut(),
470 Copy => self.editor.copy(),
471 Paste => self.editor.paste(),
472 About => dialog::message(
473 "This is an example application written in Rust and using the FLTK Gui library.",
474 ),
475 }
476 }
477 }
478 }
Sourcepub fn set_dialog_title(msg: &'static str)
pub fn set_dialog_title(msg: &'static str)
Set the dialog “Title”
Sourcepub fn set_dialog_printer(msg: &'static str)
pub fn set_dialog_printer(msg: &'static str)
Set the dialog “Printer”
Sourcepub fn set_dialog_range(msg: &'static str)
pub fn set_dialog_range(msg: &'static str)
Set dialog “Range”
Sourcepub fn set_dialog_copies(msg: &'static str)
pub fn set_dialog_copies(msg: &'static str)
Set dialog “Copies”
Sourcepub fn set_dialog_all(msg: &'static str)
pub fn set_dialog_all(msg: &'static str)
Set dialog “All”
Sourcepub fn set_dialog_pages(msg: &'static str)
pub fn set_dialog_pages(msg: &'static str)
Set dialog “Pages”
Sourcepub fn set_dialog_from(msg: &'static str)
pub fn set_dialog_from(msg: &'static str)
Set dialog “From”
Sourcepub fn set_dialog_to(msg: &'static str)
pub fn set_dialog_to(msg: &'static str)
Set dialog “To”
Sourcepub fn set_dialog_properties(msg: &'static str)
pub fn set_dialog_properties(msg: &'static str)
Set dialog “Properties”
Sourcepub fn set_dialog_copy_number(msg: &'static str)
pub fn set_dialog_copy_number(msg: &'static str)
Set dialog “Number of copies”
Set dialog “Print” button
Set dialog “Cancel” button
Sourcepub fn set_dialog_print_to_file(msg: &'static str)
pub fn set_dialog_print_to_file(msg: &'static str)
Set dialog “Print to file” button
Sourcepub fn set_property_title(msg: &'static str)
pub fn set_property_title(msg: &'static str)
Set property “Title”
Sourcepub fn set_property_pagesize(msg: &'static str)
pub fn set_property_pagesize(msg: &'static str)
Set property “Page Size”
Sourcepub fn set_property_mode(msg: &'static str)
pub fn set_property_mode(msg: &'static str)
Set property “Mode”
Sourcepub fn set_property_use(msg: &'static str)
pub fn set_property_use(msg: &'static str)
Set property “Use”
Sourcepub fn set_property_save(msg: &'static str)
pub fn set_property_save(msg: &'static str)
Set property “Save”
Sourcepub fn set_property_cancel(msg: &'static str)
pub fn set_property_cancel(msg: &'static str)
Set property “Cancel”