1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! Canvas composable for custom drawing via [`DrawScope`].
//!
//! Matches Jetpack Compose's `Canvas(modifier) { onDraw }`.
use NodeId;
use ;
use crate::;
/// A composable that draws custom content using a [`DrawScope`].
///
/// ```ignore
/// Canvas(
/// Modifier::empty().size_points(200.0, 100.0),
/// |scope| {
/// scope.draw_rect(Brush::solid(Color::RED));
/// },
/// );
/// ```
///
/// The scope draws text too, against the app's fonts and through the same
/// glyph atlas the `Text` composable uses — a canvas never needs its own font.
/// Alignment happens inside the box you pass, and
/// [`DrawScope::measure_text`] reports exactly the box a draw will fill, so a
/// caller can position text itself:
///
/// ```ignore
/// Canvas(Modifier::empty().fill_max_size(), |scope| {
/// let style = DrawTextStyle::new(24.0)
/// .with_weight(FontWeight::BOLD)
/// .with_align(TextAlign::Center);
/// // Centered in the whole canvas.
/// scope.draw_text(Brush::solid(Color::WHITE), "GAME OVER", &style);
/// // Or placed by hand from the measurement.
/// let measured = scope.measure_text("SCORE 1234", &style);
/// scope.draw_text_from(
/// Point::new(scope.size().width - measured.size.width - 8.0, 8.0),
/// Brush::solid(Color::WHITE),
/// "SCORE 1234",
/// &style,
/// );
/// });
/// ```