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.width() / 2, -widget.height() / 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?
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
pub fn launch(&mut self) {
while self.app.wait() {
use Message::*;
if let Some(msg) = self.r.recv() {
match msg {
Changed => {
if !self.modified {
self.modified = true;
self.menu.menu.find_item("&File/Save\t").unwrap().activate();
self.menu.menu.find_item("&File/Quit\t").unwrap().set_label_color(Color::Red);
let name = match &self.filename {
Some(f) => f.to_string_lossy().to_string(),
None => "(Untitled)".to_string(),
};
self.main_win.set_label(&format!("* {name} - RustyEd"));
}
}
New => {
if self.buf.text() != "" {
let clear = if let Some(x) = dialog::choice2(center().0 - 200, center().1 - 100, "File unsaved, Do you wish to continue?", "Yes", "No!", "") {
x == 0
} else {
false
};
if clear {
self.buf.set_text("");
}
}
},
Open => {
let mut dlg = dialog::FileDialog::new(dialog::FileDialogType::BrowseFile);
dlg.set_option(dialog::FileDialogOptions::NoOptions);
dlg.set_filter("*.{txt,rs,toml}");
dlg.show();
let filename = dlg.filename();
if !filename.to_string_lossy().to_string().is_empty() {
if filename.exists() {
match self.buf.load_file(&filename) {
Ok(_) => self.filename = Some(filename),
Err(e) => dialog::alert(center().0 - 200, center().1 - 100, &format!("An issue occured while loading the file: {e}")),
}
} else {
dialog::alert(center().0 - 200, center().1 - 100, "File does not exist!")
}
}
},
Save => { self.save_file().unwrap(); },
SaveAs => { self.save_file_as().unwrap(); },
Print => {
let mut printer = printer::Printer::default();
if printer.begin_job(0).is_ok() {
let (w, h) = printer.printable_rect();
self.printable.set_size(w - 40, h - 40);
// Needs cleanup
let line_count = self.printable.count_lines(0, self.printable.buffer().unwrap().length(), true) / 45;
for i in 0..=line_count {
self.printable.scroll(45 * i, 0);
printer.begin_page().ok();
printer.print_widget(&self.printable, 20, 20);
printer.end_page().ok();
}
printer.end_job();
}
},
Quit => {
if self.modified {
match dialog::choice2(center().0 - 200, center().1 - 100,
"Would you like to save your work?", "Yes", "No", "") {
Some(0) => {
if self.save_file().unwrap() {
self.app.quit();
}
},
Some(1) => { self.app.quit() },
Some(_) | None => (),
}
} else {
self.app.quit();
}
},
Cut => self.editor.cut(),
Copy => self.editor.copy(),
Paste => self.editor.paste(),
About => dialog::message(center().0 - 300, center().1 - 100, "This is an example application written in Rust and using the FLTK Gui library."),
}
}
}
}
sourcepub fn end_page(&mut self) -> Result<(), FltkError>
pub fn end_page(&mut self) -> Result<(), FltkError>
Examples found in repository?
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
pub fn launch(&mut self) {
while self.app.wait() {
use Message::*;
if let Some(msg) = self.r.recv() {
match msg {
Changed => {
if !self.modified {
self.modified = true;
self.menu.menu.find_item("&File/Save\t").unwrap().activate();
self.menu.menu.find_item("&File/Quit\t").unwrap().set_label_color(Color::Red);
let name = match &self.filename {
Some(f) => f.to_string_lossy().to_string(),
None => "(Untitled)".to_string(),
};
self.main_win.set_label(&format!("* {name} - RustyEd"));
}
}
New => {
if self.buf.text() != "" {
let clear = if let Some(x) = dialog::choice2(center().0 - 200, center().1 - 100, "File unsaved, Do you wish to continue?", "Yes", "No!", "") {
x == 0
} else {
false
};
if clear {
self.buf.set_text("");
}
}
},
Open => {
let mut dlg = dialog::FileDialog::new(dialog::FileDialogType::BrowseFile);
dlg.set_option(dialog::FileDialogOptions::NoOptions);
dlg.set_filter("*.{txt,rs,toml}");
dlg.show();
let filename = dlg.filename();
if !filename.to_string_lossy().to_string().is_empty() {
if filename.exists() {
match self.buf.load_file(&filename) {
Ok(_) => self.filename = Some(filename),
Err(e) => dialog::alert(center().0 - 200, center().1 - 100, &format!("An issue occured while loading the file: {e}")),
}
} else {
dialog::alert(center().0 - 200, center().1 - 100, "File does not exist!")
}
}
},
Save => { self.save_file().unwrap(); },
SaveAs => { self.save_file_as().unwrap(); },
Print => {
let mut printer = printer::Printer::default();
if printer.begin_job(0).is_ok() {
let (w, h) = printer.printable_rect();
self.printable.set_size(w - 40, h - 40);
// Needs cleanup
let line_count = self.printable.count_lines(0, self.printable.buffer().unwrap().length(), true) / 45;
for i in 0..=line_count {
self.printable.scroll(45 * i, 0);
printer.begin_page().ok();
printer.print_widget(&self.printable, 20, 20);
printer.end_page().ok();
}
printer.end_job();
}
},
Quit => {
if self.modified {
match dialog::choice2(center().0 - 200, center().1 - 100,
"Would you like to save your work?", "Yes", "No", "") {
Some(0) => {
if self.save_file().unwrap() {
self.app.quit();
}
},
Some(1) => { self.app.quit() },
Some(_) | None => (),
}
} else {
self.app.quit();
}
},
Cut => self.editor.cut(),
Copy => self.editor.copy(),
Paste => self.editor.paste(),
About => dialog::message(center().0 - 300, center().1 - 100, "This is an example application written in Rust and using the FLTK Gui library."),
}
}
}
}
sourcepub fn end_job(&mut self)
pub fn end_job(&mut self)
Ends the print job
Examples found in repository?
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
pub fn launch(&mut self) {
while self.app.wait() {
use Message::*;
if let Some(msg) = self.r.recv() {
match msg {
Changed => {
if !self.modified {
self.modified = true;
self.menu.menu.find_item("&File/Save\t").unwrap().activate();
self.menu.menu.find_item("&File/Quit\t").unwrap().set_label_color(Color::Red);
let name = match &self.filename {
Some(f) => f.to_string_lossy().to_string(),
None => "(Untitled)".to_string(),
};
self.main_win.set_label(&format!("* {name} - RustyEd"));
}
}
New => {
if self.buf.text() != "" {
let clear = if let Some(x) = dialog::choice2(center().0 - 200, center().1 - 100, "File unsaved, Do you wish to continue?", "Yes", "No!", "") {
x == 0
} else {
false
};
if clear {
self.buf.set_text("");
}
}
},
Open => {
let mut dlg = dialog::FileDialog::new(dialog::FileDialogType::BrowseFile);
dlg.set_option(dialog::FileDialogOptions::NoOptions);
dlg.set_filter("*.{txt,rs,toml}");
dlg.show();
let filename = dlg.filename();
if !filename.to_string_lossy().to_string().is_empty() {
if filename.exists() {
match self.buf.load_file(&filename) {
Ok(_) => self.filename = Some(filename),
Err(e) => dialog::alert(center().0 - 200, center().1 - 100, &format!("An issue occured while loading the file: {e}")),
}
} else {
dialog::alert(center().0 - 200, center().1 - 100, "File does not exist!")
}
}
},
Save => { self.save_file().unwrap(); },
SaveAs => { self.save_file_as().unwrap(); },
Print => {
let mut printer = printer::Printer::default();
if printer.begin_job(0).is_ok() {
let (w, h) = printer.printable_rect();
self.printable.set_size(w - 40, h - 40);
// Needs cleanup
let line_count = self.printable.count_lines(0, self.printable.buffer().unwrap().length(), true) / 45;
for i in 0..=line_count {
self.printable.scroll(45 * i, 0);
printer.begin_page().ok();
printer.print_widget(&self.printable, 20, 20);
printer.end_page().ok();
}
printer.end_job();
}
},
Quit => {
if self.modified {
match dialog::choice2(center().0 - 200, center().1 - 100,
"Would you like to save your work?", "Yes", "No", "") {
Some(0) => {
if self.save_file().unwrap() {
self.app.quit();
}
},
Some(1) => { self.app.quit() },
Some(_) | None => (),
}
} else {
self.app.quit();
}
},
Cut => self.editor.cut(),
Copy => self.editor.copy(),
Paste => self.editor.paste(),
About => dialog::message(center().0 - 300, center().1 - 100, "This is an example application written in Rust and using the FLTK Gui library."),
}
}
}
}
sourcepub fn begin_page(&mut self) -> Result<(), FltkError>
pub fn begin_page(&mut self) -> Result<(), FltkError>
Examples found in repository?
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
pub fn launch(&mut self) {
while self.app.wait() {
use Message::*;
if let Some(msg) = self.r.recv() {
match msg {
Changed => {
if !self.modified {
self.modified = true;
self.menu.menu.find_item("&File/Save\t").unwrap().activate();
self.menu.menu.find_item("&File/Quit\t").unwrap().set_label_color(Color::Red);
let name = match &self.filename {
Some(f) => f.to_string_lossy().to_string(),
None => "(Untitled)".to_string(),
};
self.main_win.set_label(&format!("* {name} - RustyEd"));
}
}
New => {
if self.buf.text() != "" {
let clear = if let Some(x) = dialog::choice2(center().0 - 200, center().1 - 100, "File unsaved, Do you wish to continue?", "Yes", "No!", "") {
x == 0
} else {
false
};
if clear {
self.buf.set_text("");
}
}
},
Open => {
let mut dlg = dialog::FileDialog::new(dialog::FileDialogType::BrowseFile);
dlg.set_option(dialog::FileDialogOptions::NoOptions);
dlg.set_filter("*.{txt,rs,toml}");
dlg.show();
let filename = dlg.filename();
if !filename.to_string_lossy().to_string().is_empty() {
if filename.exists() {
match self.buf.load_file(&filename) {
Ok(_) => self.filename = Some(filename),
Err(e) => dialog::alert(center().0 - 200, center().1 - 100, &format!("An issue occured while loading the file: {e}")),
}
} else {
dialog::alert(center().0 - 200, center().1 - 100, "File does not exist!")
}
}
},
Save => { self.save_file().unwrap(); },
SaveAs => { self.save_file_as().unwrap(); },
Print => {
let mut printer = printer::Printer::default();
if printer.begin_job(0).is_ok() {
let (w, h) = printer.printable_rect();
self.printable.set_size(w - 40, h - 40);
// Needs cleanup
let line_count = self.printable.count_lines(0, self.printable.buffer().unwrap().length(), true) / 45;
for i in 0..=line_count {
self.printable.scroll(45 * i, 0);
printer.begin_page().ok();
printer.print_widget(&self.printable, 20, 20);
printer.end_page().ok();
}
printer.end_job();
}
},
Quit => {
if self.modified {
match dialog::choice2(center().0 - 200, center().1 - 100,
"Would you like to save your work?", "Yes", "No", "") {
Some(0) => {
if self.save_file().unwrap() {
self.app.quit();
}
},
Some(1) => { self.app.quit() },
Some(_) | None => (),
}
} else {
self.app.quit();
}
},
Cut => self.editor.cut(),
Copy => self.editor.copy(),
Paste => self.editor.paste(),
About => dialog::message(center().0 - 300, center().1 - 100, "This is an example application written in Rust and using the FLTK Gui library."),
}
}
}
}
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?
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
pub fn launch(&mut self) {
while self.app.wait() {
use Message::*;
if let Some(msg) = self.r.recv() {
match msg {
Changed => {
if !self.modified {
self.modified = true;
self.menu.menu.find_item("&File/Save\t").unwrap().activate();
self.menu.menu.find_item("&File/Quit\t").unwrap().set_label_color(Color::Red);
let name = match &self.filename {
Some(f) => f.to_string_lossy().to_string(),
None => "(Untitled)".to_string(),
};
self.main_win.set_label(&format!("* {name} - RustyEd"));
}
}
New => {
if self.buf.text() != "" {
let clear = if let Some(x) = dialog::choice2(center().0 - 200, center().1 - 100, "File unsaved, Do you wish to continue?", "Yes", "No!", "") {
x == 0
} else {
false
};
if clear {
self.buf.set_text("");
}
}
},
Open => {
let mut dlg = dialog::FileDialog::new(dialog::FileDialogType::BrowseFile);
dlg.set_option(dialog::FileDialogOptions::NoOptions);
dlg.set_filter("*.{txt,rs,toml}");
dlg.show();
let filename = dlg.filename();
if !filename.to_string_lossy().to_string().is_empty() {
if filename.exists() {
match self.buf.load_file(&filename) {
Ok(_) => self.filename = Some(filename),
Err(e) => dialog::alert(center().0 - 200, center().1 - 100, &format!("An issue occured while loading the file: {e}")),
}
} else {
dialog::alert(center().0 - 200, center().1 - 100, "File does not exist!")
}
}
},
Save => { self.save_file().unwrap(); },
SaveAs => { self.save_file_as().unwrap(); },
Print => {
let mut printer = printer::Printer::default();
if printer.begin_job(0).is_ok() {
let (w, h) = printer.printable_rect();
self.printable.set_size(w - 40, h - 40);
// Needs cleanup
let line_count = self.printable.count_lines(0, self.printable.buffer().unwrap().length(), true) / 45;
for i in 0..=line_count {
self.printable.scroll(45 * i, 0);
printer.begin_page().ok();
printer.print_widget(&self.printable, 20, 20);
printer.end_page().ok();
}
printer.end_job();
}
},
Quit => {
if self.modified {
match dialog::choice2(center().0 - 200, center().1 - 100,
"Would you like to save your work?", "Yes", "No", "") {
Some(0) => {
if self.save_file().unwrap() {
self.app.quit();
}
},
Some(1) => { self.app.quit() },
Some(_) | None => (),
}
} else {
self.app.quit();
}
},
Cut => self.editor.cut(),
Copy => self.editor.copy(),
Paste => self.editor.paste(),
About => dialog::message(center().0 - 300, center().1 - 100, "This is an example application written in Rust and using the FLTK Gui library."),
}
}
}
}
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?
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
pub fn launch(&mut self) {
while self.app.wait() {
use Message::*;
if let Some(msg) = self.r.recv() {
match msg {
Changed => {
if !self.modified {
self.modified = true;
self.menu.menu.find_item("&File/Save\t").unwrap().activate();
self.menu.menu.find_item("&File/Quit\t").unwrap().set_label_color(Color::Red);
let name = match &self.filename {
Some(f) => f.to_string_lossy().to_string(),
None => "(Untitled)".to_string(),
};
self.main_win.set_label(&format!("* {name} - RustyEd"));
}
}
New => {
if self.buf.text() != "" {
let clear = if let Some(x) = dialog::choice2(center().0 - 200, center().1 - 100, "File unsaved, Do you wish to continue?", "Yes", "No!", "") {
x == 0
} else {
false
};
if clear {
self.buf.set_text("");
}
}
},
Open => {
let mut dlg = dialog::FileDialog::new(dialog::FileDialogType::BrowseFile);
dlg.set_option(dialog::FileDialogOptions::NoOptions);
dlg.set_filter("*.{txt,rs,toml}");
dlg.show();
let filename = dlg.filename();
if !filename.to_string_lossy().to_string().is_empty() {
if filename.exists() {
match self.buf.load_file(&filename) {
Ok(_) => self.filename = Some(filename),
Err(e) => dialog::alert(center().0 - 200, center().1 - 100, &format!("An issue occured while loading the file: {e}")),
}
} else {
dialog::alert(center().0 - 200, center().1 - 100, "File does not exist!")
}
}
},
Save => { self.save_file().unwrap(); },
SaveAs => { self.save_file_as().unwrap(); },
Print => {
let mut printer = printer::Printer::default();
if printer.begin_job(0).is_ok() {
let (w, h) = printer.printable_rect();
self.printable.set_size(w - 40, h - 40);
// Needs cleanup
let line_count = self.printable.count_lines(0, self.printable.buffer().unwrap().length(), true) / 45;
for i in 0..=line_count {
self.printable.scroll(45 * i, 0);
printer.begin_page().ok();
printer.print_widget(&self.printable, 20, 20);
printer.end_page().ok();
}
printer.end_job();
}
},
Quit => {
if self.modified {
match dialog::choice2(center().0 - 200, center().1 - 100,
"Would you like to save your work?", "Yes", "No", "") {
Some(0) => {
if self.save_file().unwrap() {
self.app.quit();
}
},
Some(1) => { self.app.quit() },
Some(_) | None => (),
}
} else {
self.app.quit();
}
},
Cut => self.editor.cut(),
Copy => self.editor.copy(),
Paste => self.editor.paste(),
About => dialog::message(center().0 - 300, center().1 - 100, "This is an example application written in Rust and using the FLTK Gui library."),
}
}
}
}
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”