pub struct RadialGradientBrush {
pub stops: Vec<GradientStop>,
pub origin: Point2D<f64, RelativeSpace>,
pub center: Point2D<f64, RelativeSpace>,
pub radius: Size2D<f64, RelativeSpace>,
}Available on crate feature
winio only.Expand description
Radial gradient brush.
Fields§
§stops: Vec<GradientStop>The gradient stops.
origin: Point2D<f64, RelativeSpace>The relative origin position.
center: Point2D<f64, RelativeSpace>The relative center position.
radius: Size2D<f64, RelativeSpace>The relative radius.
Implementations§
Source§impl RadialGradientBrush
impl RadialGradientBrush
Sourcepub fn new(
stops: impl IntoIterator<Item = GradientStop>,
origin: Point2D<f64, RelativeSpace>,
center: Point2D<f64, RelativeSpace>,
radius: Size2D<f64, RelativeSpace>,
) -> RadialGradientBrush
pub fn new( stops: impl IntoIterator<Item = GradientStop>, origin: Point2D<f64, RelativeSpace>, center: Point2D<f64, RelativeSpace>, radius: Size2D<f64, RelativeSpace>, ) -> RadialGradientBrush
Create RadialGradientBrush.
Examples found in repository?
examples/test/widgets.rs (lines 345-356)
257 fn render(&mut self, _sender: &ComponentSender<Self>) {
258 let csize = self.window.client_size();
259 {
260 let mut cred_panel = layout! {
261 Grid::from_str("auto,1*,auto", "1*,auto,auto,1*").unwrap(),
262 self.ulabel => { column: 0, row: 1, valign: VAlign::Center },
263 self.uentry => { column: 1, row: 1, margin: Margin::new_all_same(4.0) },
264 self.plabel => { column: 0, row: 2, valign: VAlign::Center },
265 self.pentry => { column: 1, row: 2, margin: Margin::new_all_same(4.0) },
266 self.pcheck => { column: 2, row: 2 },
267 };
268
269 let mut rgroup_panel = layout! {
270 Grid::from_str("auto", "1*,auto,auto,auto,1*").unwrap(),
271 self.r1 => { row: 1 },
272 self.r2 => { row: 2 },
273 self.r3 => { row: 3 },
274 };
275
276 let mut buttons_panel = layout! {
277 StackPanel::new(Orient::Vertical),
278 self.push_button => { margin: Margin::new_all_same(4.0) },
279 self.pop_button => { margin: Margin::new_all_same(4.0) },
280 self.show_button => { margin: Margin::new_all_same(4.0) },
281 };
282
283 let mut root_panel = layout! {
284 Grid::from_str("1*,1*,1*", "1*,auto,1*").unwrap(),
285 cred_panel => { column: 1, row: 0 },
286 rgroup_panel => { column: 2, row: 0, halign: HAlign::Center },
287 self.canvas => { column: 0, row: 1, row_span: 2 },
288 self.combo => { column: 1, row: 1, halign: HAlign::Center },
289 self.progress => { column: 2, row: 1 },
290 self.mltext => { column: 1, row: 2, margin: Margin::new_all_same(8.0) },
291 buttons_panel => { column: 2, row: 2 },
292 };
293
294 root_panel.set_size(csize);
295 }
296
297 let size = self.canvas.size();
298 let is_dark = ColorTheme::current() == ColorTheme::Dark;
299 let back_color = if is_dark {
300 Color::new(255, 255, 255, 255)
301 } else {
302 Color::new(0, 0, 0, 255)
303 };
304 let brush = SolidColorBrush::new(back_color);
305 let pen = BrushPen::new(&brush, 1.0);
306 let mut ctx = self.canvas.context();
307 let cx = size.width / 2.0;
308 let cy = size.height / 2.0;
309 let r = cx.min(cy) - 2.0;
310 ctx.draw_pie(
311 &pen,
312 Rect::new(Point::new(cx - r, cy - r), Size::new(r * 2.0, r * 2.0)),
313 std::f64::consts::PI,
314 std::f64::consts::PI * 2.0,
315 );
316
317 let brush2 = LinearGradientBrush::new(
318 [
319 GradientStop::new(Color::new(0x87, 0xCE, 0xEB, 0xFF), 0.0),
320 GradientStop::new(back_color, 1.0),
321 ],
322 RelativePoint::zero(),
323 RelativePoint::new(0.0, 1.0),
324 );
325 let pen2 = BrushPen::new(&brush2, 1.0);
326 ctx.draw_round_rect(
327 &pen2,
328 Rect::new(
329 Point::new(cx - r - 1.0, cy - r - 1.0),
330 Size::new(r * 2.0 + 2.0, r * 1.618 + 2.0),
331 ),
332 Size::new(r / 10.0, r / 10.0),
333 );
334 let mut path = ctx.create_path_builder(Point::new(cx + r + 1.0 - r / 10.0, cy));
335 path.add_arc(
336 Point::new(cx, cy + r * 0.618 + 1.0),
337 Size::new(r + 1.0 - r / 10.0, r * 0.382 / 2.0),
338 0.0,
339 std::f64::consts::PI,
340 true,
341 );
342 path.add_line(Point::new(cx - r - 1.0 + r / 10.0, cy));
343 let path = path.build(false);
344 ctx.draw_path(&pen, &path);
345 let brush3 = RadialGradientBrush::new(
346 [
347 GradientStop::new(Color::new(0xF5, 0xF5, 0xF5, 0xFF), 0.0),
348 GradientStop::new(
349 Color::accent().unwrap_or(Color::new(0xFF, 0xC0, 0xCB, 0xFF)),
350 1.0,
351 ),
352 ],
353 RelativePoint::new(0.5, 0.5),
354 RelativePoint::new(0.2, 0.5),
355 RelativeSize::new(0.5, 0.5),
356 );
357 let font = DrawingFontBuilder::new()
358 .family("Arial")
359 .size(r / 5.0)
360 .halign(HAlign::Center)
361 .valign(VAlign::Bottom)
362 .build();
363 ctx.draw_str(&brush3, font, Point::new(cx, cy), "Hello world!");
364 }Trait Implementations§
Source§impl Clone for RadialGradientBrush
impl Clone for RadialGradientBrush
Source§fn clone(&self) -> RadialGradientBrush
fn clone(&self) -> RadialGradientBrush
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RadialGradientBrush
impl Debug for RadialGradientBrush
impl Brush for RadialGradientBrush
Auto Trait Implementations§
impl Freeze for RadialGradientBrush
impl RefUnwindSafe for RadialGradientBrush
impl Send for RadialGradientBrush
impl Sync for RadialGradientBrush
impl Unpin for RadialGradientBrush
impl UnwindSafe for RadialGradientBrush
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more