Skip to content

Commit

Permalink
Fix SwiftUI sector radius
Browse files Browse the repository at this point in the history
  • Loading branch information
fwcd committed Sep 4, 2024
1 parent 0fd073e commit 31087ec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions examples/pie_chart.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![feature(type_alias_impl_trait, impl_trait_in_assoc_type)]

use nuit::{Alignment, Angle, Bind, Color, Sector, ShapeExt, Text, View, ViewExt, ZStack};
use nuit::{Alignment, Angle, Bind, Color, Insets, Sector, ShapeExt, Text, View, ViewExt, ZStack};

#[derive(Bind)]
struct PieChartView;
Expand All @@ -12,14 +12,14 @@ impl View for PieChartView {
ZStack::new((
Sector::new(Angle::with_degrees(30.0), Angle::FULL, 0)
.fill(Color::BLUE)
.frame(100)
.overlay_at(Alignment::Leading, Text::new("Majority")),
.frame(160)
.overlay_at(Alignment::Leading, Text::new("Majority").padding(Insets::default())),
Sector::new(Angle::ZERO, Angle::with_degrees(30.0), 0)
.fill(Color::CYAN)
.frame(150),
.frame(240),
Sector::new(Angle::with_degrees(10.0), Angle::with_degrees(20.0), 0.9)
.fill(Color::MAGENTA)
.frame(180),
.frame(280),
))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct Sector: Shape {
func path(in rect: CGRect) -> Path {
Path { path in
let center = CGPoint(x: rect.midX, y: rect.midY)
let outerRadius = min(rect.width, rect.height)
let outerRadius = min(rect.width, rect.height) / 2
let innerRadius = innerRadiusFraction * outerRadius

path.addArc(center: center, radius: outerRadius, startAngle: startAngle, endAngle: endAngle, clockwise: false)
Expand Down

0 comments on commit 31087ec

Please sign in to comment.