pie_chart/
pie_chart.rs

1#![feature(type_alias_impl_trait, impl_trait_in_assoc_type)]
2
3use nuit::{Alignment, Angle, Bind, Color, Insets, Sector, ShapeExt, Text, View, ViewExt, ZStack};
4
5#[derive(Bind)]
6struct PieChartView;
7
8impl View for PieChartView {
9    type Body = impl View;
10
11    fn body(&self) -> Self::Body {
12        ZStack::new((
13            Sector::new(Angle::with_degrees(30.0), Angle::FULL, 0)
14                .fill(Color::BLUE)
15                .frame(160)
16                .overlay_at(Alignment::Leading, Text::new("Majority").padding(Insets::default())),
17            Sector::new(Angle::ZERO, Angle::with_degrees(30.0), 0)
18                .fill(Color::CYAN)
19                .frame(240),
20            Sector::new(Angle::with_degrees(10.0), Angle::with_degrees(20.0), 0.9)
21                .fill(Color::MAGENTA)
22                .frame(280),
23        ))
24    }
25}
26
27fn main() {
28    nuit::run_app(PieChartView);
29}