[go: up one dir, main page]

Circle

Struct Circle 

Source
pub struct Circle {
    pub center: Point,
    pub radius: f64,
}
Expand description

A circle.

Fields§

§center: Point

The center.

§radius: f64

The radius.

Implementations§

Source§

impl Circle

Source

pub fn new(center: impl Into<Point>, radius: f64) -> Circle

A new circle from center and radius.

Examples found in repository?
examples/anim.rs (line 82)
74    fn paint(&mut self, ctx: &mut PaintCtx, _data: &(), _env: &Env) {
75        let t = self.t;
76        let center = Point::new(50.0, 50.0);
77        ctx.paint_with_z_index(1, move |ctx| {
78            let ambit = center + 45.0 * Vec2::from_angle((0.75 + t) * 2.0 * PI);
79            ctx.stroke(Line::new(center, ambit), &Color::WHITE, 1.0);
80        });
81
82        ctx.fill(Circle::new(center, 50.0), &Color::BLACK);
83    }
More examples
Hide additional examples
examples/scroll.rs (line 65)
61    fn paint(&mut self, ctx: &mut PaintCtx, _: &T, env: &Env) {
62        let rect = Rect::ZERO.with_size(ctx.size());
63        let color = env.get_debug_color(self.0);
64        let radius = (rect + INSETS).size().height / 2.0;
65        let circle = Circle::new(rect.center(), radius);
66        let grad = RadialGradient::new(1.0, (color, color.with_alpha(0.0)));
67        ctx.fill(circle, &grad);
68        ctx.stroke(rect, &color, 2.0);
69    }
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}
Source

pub fn segment( self, inner_radius: f64, start_angle: f64, sweep_angle: f64, ) -> CircleSegment

Create a CircleSegment by cutting out parts of this circle.

Source

pub fn is_finite(&self) -> bool

Is this circle finite?

Source

pub fn is_nan(&self) -> bool

Is this circle NaN?

Trait Implementations§

Source§

impl Add<Vec2> for Circle

Source§

type Output = Circle

The resulting type after applying the + operator.
Source§

fn add(self, v: Vec2) -> Circle

Performs the + operation. Read more
Source§

impl Clone for Circle

Source§

fn clone(&self) -> Circle

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Data for Circle

Source§

fn same(&self, other: &Self) -> bool

Determine whether two values are the same. Read more
Source§

impl Debug for Circle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Circle

Source§

fn default() -> Circle

Returns the “default value” for a type. Read more
Source§

impl From<Circle> for Ellipse

Source§

fn from(circle: Circle) -> Ellipse

Converts to this type from the input type.
Source§

impl Mul<Circle> for Affine

Source§

type Output = Ellipse

The resulting type after applying the * operator.
Source§

fn mul(self, other: Circle) -> <Affine as Mul<Circle>>::Output

Performs the * operation. Read more
Source§

impl Mul<Circle> for TranslateScale

Source§

type Output = Circle

The resulting type after applying the * operator.
Source§

fn mul(self, other: Circle) -> Circle

Performs the * operation. Read more
Source§

impl PartialEq for Circle

Source§

fn eq(&self, other: &Circle) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Shape for Circle

Source§

type PathElementsIter<'iter> = CirclePathIter

The iterator returned by the path_elements method.
Source§

fn path_elements(&self, tolerance: f64) -> CirclePathIter

Returns an iterator over this shape expressed as PathEls; that is, as Bézier path elements. Read more
Source§

fn area(&self) -> f64

Signed area. Read more
Source§

fn perimeter(&self, _accuracy: f64) -> f64

Total length of perimeter.
Source§

fn winding(&self, pt: Point) -> i32

The winding number of a point. Read more
Source§

fn bounding_box(&self) -> Rect

The smallest rectangle that encloses the shape.
Source§

fn as_circle(&self) -> Option<Circle>

If the shape is a circle, make it available.
Source§

fn to_path(&self, tolerance: f64) -> BezPath

Convert to a Bézier path. Read more
Source§

fn into_path(self, tolerance: f64) -> BezPath

Convert into a Bézier path. Read more
Source§

fn path_segments(&self, tolerance: f64) -> Segments<Self::PathElementsIter<'_>>

Returns an iterator over this shape expressed as Bézier path segments (PathSegs). Read more
Source§

fn contains(&self, pt: Point) -> bool

Returns true if the Point is inside this shape. Read more
Source§

fn as_line(&self) -> Option<Line>

If the shape is a line, make it available.
Source§

fn as_rect(&self) -> Option<Rect>

If the shape is a rectangle, make it available.
Source§

fn as_rounded_rect(&self) -> Option<RoundedRect>

If the shape is a rounded rectangle, make it available.
Source§

fn as_path_slice(&self) -> Option<&[PathEl]>

If the shape is stored as a slice of path elements, make that available. Read more
Source§

impl Sub<Vec2> for Circle

Source§

type Output = Circle

The resulting type after applying the - operator.
Source§

fn sub(self, v: Vec2) -> Circle

Performs the - operation. Read more
Source§

impl Copy for Circle

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AnyEq for T
where T: Any + PartialEq,

Source§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IsDefault for T
where T: Default + PartialEq + Copy,

Source§

fn is_default(&self) -> bool

Checks that type has a default value.
Source§

impl<T> RoundFrom<T> for T

Source§

fn round_from(x: T) -> T

Performs the conversion.
Source§

impl<T, U> RoundInto<U> for T
where U: RoundFrom<T>,

Source§

fn round_into(self) -> U

Performs the conversion.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more