default_text_options

Function default_text_options 

Source
pub fn default_text_options() -> DrawTextOptions
Expand description

Determine a suitable default set of text options. Enables color fonts on systems that are capable of them (8.1 and above).

Examples found in repository?
examples/perftest.rs (line 80)
48    fn paint(&self, paint_ctx: &mut PaintCtx) -> bool {
49        let mut state = self.0.borrow_mut();
50        let rt = paint_ctx.render_target();
51        let size = rt.get_size();
52        let rect = RectF::from((0.0, 0.0, size.width, size.height));
53        let bg = SolidColorBrush::create(rt).with_color(0x272822).build().unwrap();
54        let fg = SolidColorBrush::create(rt).with_color(0xf0f0ea).build().unwrap();
55        rt.fill_rectangle(rect, &bg);
56
57        rt.draw_line((0.0, size.height), (size.width, 0.0), &fg, 1.0, None);
58
59        let th = ::std::f32::consts::PI * (get_time().nsec as f32) * 2e-9;
60        let dx = 100.0 * th.sin();
61        let dy = 100.0 * th.cos();
62        rt.draw_line((100.0, 100.0), (100.0 + dx, 100.0 - dy),
63            &fg, 1.0, None);
64
65        let text_format = TextFormat::create(&state.dwrite_factory)
66            .with_family("Consolas")
67            .with_size(15.0)
68            .build()
69            .unwrap();
70
71        let now = get_time();
72        let now = now.sec as f64 + 1e-9 * now.nsec as f64;
73        let msg = format!("{:3.1}ms", 1e3 * (now - state.last_time));
74        state.last_time = now;
75        rt.draw_text(
76            &msg,
77            &text_format,
78            (10.0, 210.0, 100.0, 300.0),
79            &fg,
80            default_text_options()
81        );
82
83        let msg = "Hello DWrite! This is a somewhat longer string of text intended to provoke slightly longer draw times.";
84        let dy = 15.0;
85        let x0 = 210.0;
86        let y0 = 10.0;
87        for i in 0..60 {
88            let y = y0 + (i as f32) * dy;
89            rt.draw_text(
90                msg,
91                &text_format,
92                (x0, y, x0 + 900.0, y + 80.0),
93                &fg,
94                default_text_options()
95            );
96        }
97
98    true
99    }