system_fonts/
system_fonts.rs

1// FLTK offers 16 fonts by default. However, it's possible to load all system fonts to be able to choose from them:
2// The following are the default FLTK fonts:
3// - Helvetica,
4// - HelveticaBold,
5// - HelveticaItalic,
6// - HelveticaBoldItalic,
7// - Courier,
8// - CourierBold,
9// - CourierItalic,
10// - CourierBoldItalic,
11// - Times,
12// - TimesBold,
13// - TimesItalic,
14// - TimesBoldItalic,
15// - Symbol,
16// - Screen,
17// - ScreenBold,
18// - Zapfdingbats,
19//
20// The system fonts depend on the system, and are not loaded by default.
21// These can be loaded using the App::load_system_fonts() method.
22// The fonts can then be acquired using the app::fonts() function
23// or be queried using the app::font_count(), app::font_name() and app::font_index() functions.
24// And then can be used using the Font::by_index() or Font::by_name() methods.
25
26use fltk::{prelude::*, *};
27
28fn main() {
29    let app = app::App::default().load_system_fonts();
30    // To load a font by path, check the App::load_font() method
31    let fonts = app::fonts();
32    // println!("{:?}", fonts);
33    let mut wind = window::Window::default().with_size(400, 300);
34    let mut frame = frame::Frame::default().size_of(&wind);
35    frame.set_label_size(30);
36    wind.set_color(enums::Color::White);
37    wind.end();
38    wind.show();
39    println!("The system has {} fonts!\nStarting slideshow!", fonts.len());
40    let mut i = 0;
41    while app.wait() {
42        if i == fonts.len() {
43            i = 0;
44        }
45        frame.set_label(&format!("[{}]", fonts[i]));
46        frame.set_label_font(enums::Font::by_index(i));
47        app::sleep(0.5);
48        i += 1;
49    }
50}