pub struct Circle {
pub center: Point,
pub radius: f64,
}Expand description
A circle.
Fields§
§center: PointThe center.
radius: f64The radius.
Implementations§
Source§impl Circle
impl Circle
Sourcepub fn new(center: impl Into<Point>, radius: f64) -> Circle
pub fn new(center: impl Into<Point>, radius: f64) -> Circle
A new circle from center and radius.
Examples found in repository?
More examples
examples/invalidation.rs (line 82)
70 fn event(&mut self, ctx: &mut EventCtx, ev: &Event, data: &mut Vector<Circle>, _env: &Env) {
71 if let Event::MouseDown(ev) = ev {
72 if ev.mods.shift() {
73 data.push_back(Circle {
74 pos: ev.pos,
75 time: Instant::now(),
76 });
77 } else if ev.mods.ctrl() {
78 data.retain(|c| {
79 if (c.pos - ev.pos).hypot() > RADIUS {
80 true
81 } else {
82 ctx.request_paint_rect(kurbo::Circle::new(c.pos, RADIUS).bounding_box());
83 false
84 }
85 });
86 } else {
87 // Move the circle to a new location, invalidating the old locations. The new location
88 // will be invalidated during AnimFrame.
89 for c in data.iter() {
90 ctx.request_paint_rect(kurbo::Circle::new(c.pos, RADIUS).bounding_box());
91 }
92 data.clear();
93 data.push_back(Circle {
94 pos: ev.pos,
95 time: Instant::now(),
96 });
97 }
98 ctx.request_anim_frame();
99 } else if let Event::AnimFrame(_) = ev {
100 for c in &*data {
101 ctx.request_paint_rect(kurbo::Circle::new(c.pos, RADIUS).bounding_box());
102 }
103 if !data.is_empty() {
104 ctx.request_anim_frame();
105 }
106 }
107 }
108
109 fn lifecycle(
110 &mut self,
111 _ctx: &mut LifeCycleCtx,
112 _ev: &LifeCycle,
113 _data: &Vector<Circle>,
114 _env: &Env,
115 ) {
116 }
117
118 fn update(
119 &mut self,
120 _ctx: &mut UpdateCtx,
121 _old: &Vector<Circle>,
122 _new: &Vector<Circle>,
123 _env: &Env,
124 ) {
125 }
126
127 fn layout(
128 &mut self,
129 _ctx: &mut LayoutCtx,
130 bc: &BoxConstraints,
131 _data: &Vector<Circle>,
132 _env: &Env,
133 ) -> Size {
134 bc.max()
135 }
136
137 fn paint(&mut self, ctx: &mut PaintCtx, data: &Vector<Circle>, _env: &Env) {
138 ctx.with_save(|ctx| {
139 let rect = ctx.size().to_rect();
140 ctx.clip(rect);
141 ctx.fill(rect, &Color::WHITE);
142 let now = Instant::now();
143 for c in data {
144 let color =
145 Color::BLACK.with_alpha(now.duration_since(c.time).as_secs_f64().cos().abs());
146 ctx.fill(kurbo::Circle::new(c.pos, RADIUS), &color);
147 }
148 });
149 }examples/transparency.rs (line 67)
62fn build_root_widget() -> impl Widget<HelloState> {
63 // Draw red circle, and two semi-transparent rectangles
64 let circle_and_rects = Painter::new(|ctx, _data, _env| {
65 let boundaries = ctx.size().to_rect();
66 let center = (boundaries.width() / 2., boundaries.height() / 2.);
67 let circle = Circle::new(center, center.0.min(center.1));
68 ctx.fill(circle, &Color::RED);
69
70 let rect1 = Rect::new(0., 0., boundaries.width() / 2., boundaries.height() / 2.);
71 ctx.fill(rect1, &Color::rgba8(0x0, 0xff, 0, 125));
72
73 let rect2 = Rect::new(
74 boundaries.width() / 2.,
75 boundaries.height() / 2.,
76 boundaries.width(),
77 boundaries.height(),
78 );
79 ctx.fill(rect2, &Color::rgba8(0x0, 0x0, 0xff, 125));
80 });
81
82 // This textbox modifies the label, idea here is to test that the background
83 // invalidation works when you type to the textbox
84 let textbox = TextBox::new()
85 .with_placeholder("Type to test clearing")
86 .with_text_size(18.0)
87 .lens(HelloState::name)
88 .fix_width(250.);
89
90 let label = Label::new(|data: &HelloState, _env: &Env| {
91 if data.name.is_empty() {
92 "Text: ".to_string()
93 } else {
94 format!("Text: {}!", data.name)
95 }
96 })
97 .with_text_color(Color::RED)
98 .with_text_size(32.0);
99
100 Flex::column()
101 .with_flex_child(circle_and_rects.expand().controller(DragController), 10.0)
102 .with_spacer(4.0)
103 .with_child(textbox)
104 .with_spacer(4.0)
105 .with_child(label)
106}examples/panels.rs (line 48)
31fn build_app() -> impl Widget<()> {
32 let gradient = LinearGradient::new(
33 UnitPoint::TOP_LEFT,
34 UnitPoint::BOTTOM_RIGHT,
35 (DARKER_GREY, LIGHTER_GREY),
36 );
37
38 // a custom background
39 let polka_dots = Painter::new(|ctx, _, _| {
40 let bounds = ctx.size().to_rect();
41 let dot_diam = bounds.width().max(bounds.height()) / 20.;
42 let dot_spacing = dot_diam * 1.8;
43 for y in 0..((bounds.height() / dot_diam).ceil() as usize) {
44 for x in 0..((bounds.width() / dot_diam).ceil() as usize) {
45 let x_offset = (y % 2) as f64 * (dot_spacing / 2.0);
46 let x = x as f64 * dot_spacing + x_offset;
47 let y = y as f64 * dot_spacing;
48 let circ = Circle::new((x, y), dot_diam / 2.0);
49 let purp = Color::rgb(1.0, 0.22, 0.76);
50 ctx.fill(circ, &purp);
51 }
52 }
53 });
54
55 Flex::column()
56 .with_flex_child(
57 Flex::row()
58 .with_flex_child(
59 Label::new("top left")
60 .center()
61 .border(DARK_GREY, 4.0)
62 .padding(10.0),
63 1.0,
64 )
65 .with_flex_child(
66 Label::new("top right")
67 .center()
68 .background(DARK_GREY)
69 .padding(10.0),
70 1.0,
71 ),
72 1.0,
73 )
74 .with_flex_child(
75 Flex::row()
76 .with_flex_child(
77 Label::new("bottom left")
78 .center()
79 .background(gradient)
80 .rounded(10.0)
81 .padding(10.0),
82 1.0,
83 )
84 .with_flex_child(
85 Label::new("bottom right")
86 .center()
87 .border(LIGHTER_GREY, 4.0)
88 .background(polka_dots)
89 .rounded(10.0)
90 .padding(10.0),
91 1.0,
92 ),
93 1.0,
94 )
95}Sourcepub fn segment(
self,
inner_radius: f64,
start_angle: f64,
sweep_angle: f64,
) -> CircleSegment
pub fn segment( self, inner_radius: f64, start_angle: f64, sweep_angle: f64, ) -> CircleSegment
Create a CircleSegment by cutting out parts of this circle.
Trait Implementations§
Source§impl Mul<Circle> for TranslateScale
impl Mul<Circle> for TranslateScale
Source§impl Shape for Circle
impl Shape for Circle
Source§type PathElementsIter<'iter> = CirclePathIter
type PathElementsIter<'iter> = CirclePathIter
The iterator returned by the
path_elements method.Source§fn path_elements(&self, tolerance: f64) -> CirclePathIter
fn path_elements(&self, tolerance: f64) -> CirclePathIter
Source§fn bounding_box(&self) -> Rect
fn bounding_box(&self) -> Rect
The smallest rectangle that encloses the shape.
Source§fn path_segments(&self, tolerance: f64) -> Segments<Self::PathElementsIter<'_>> ⓘ
fn path_segments(&self, tolerance: f64) -> Segments<Self::PathElementsIter<'_>> ⓘ
Source§fn as_rounded_rect(&self) -> Option<RoundedRect>
fn as_rounded_rect(&self) -> Option<RoundedRect>
If the shape is a rounded rectangle, make it available.
impl Copy for Circle
impl StructuralPartialEq for Circle
Auto Trait Implementations§
impl Freeze for Circle
impl RefUnwindSafe for Circle
impl Send for Circle
impl Sync for Circle
impl Unpin for Circle
impl UnwindSafe for Circle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IsDefault for T
impl<T> IsDefault for T
Source§fn is_default(&self) -> bool
fn is_default(&self) -> bool
Checks that type has a default value.
Source§impl<T, U> RoundInto<U> for Twhere
U: RoundFrom<T>,
impl<T, U> RoundInto<U> for Twhere
U: RoundFrom<T>,
Source§fn round_into(self) -> U
fn round_into(self) -> U
Performs the conversion.