From 9e5448b103797dd8282773291e6eb0fc87988bf1 Mon Sep 17 00:00:00 2001 From: "Artem V. Ageev" Date: Mon, 1 Apr 2024 15:28:45 +0300 Subject: [PATCH] format and lint cairo_shadow_button --- cairo-demo/Cargo.toml | 2 +- cairo_shadow_button/Cargo.toml | 5 ++-- cairo_shadow_button/src/main.rs | 38 ++++++++++++++++++++++++++---- cairo_shadow_button/src/surface.rs | 33 -------------------------- 4 files changed, 38 insertions(+), 40 deletions(-) delete mode 100644 cairo_shadow_button/src/surface.rs diff --git a/cairo-demo/Cargo.toml b/cairo-demo/Cargo.toml index 3e0e958..2aa6e90 100644 --- a/cairo-demo/Cargo.toml +++ b/cairo-demo/Cargo.toml @@ -8,4 +8,4 @@ edition = "2021" [dependencies] fltk = { version = "^1.4", features = ["cairoext"] } -cairo-rs = "^0.19" +cairo-rs = "0.18" diff --git a/cairo_shadow_button/Cargo.toml b/cairo_shadow_button/Cargo.toml index 86d04ed..720d080 100644 --- a/cairo_shadow_button/Cargo.toml +++ b/cairo_shadow_button/Cargo.toml @@ -1,9 +1,10 @@ [package] name = "cairo_button" version = "0.1.0" +authors = ["Mohammed Alyousef "] edition = "2021" [dependencies] fltk = "^1.4" -cairo-rs = "0.18" -cairo-blur = "0.1.0" +cairo-rs = "^0.19" +cairo-blur = "^0.1" diff --git a/cairo_shadow_button/src/main.rs b/cairo_shadow_button/src/main.rs index cbf3e77..f01702d 100644 --- a/cairo_shadow_button/src/main.rs +++ b/cairo_shadow_button/src/main.rs @@ -1,8 +1,6 @@ -use cairo::{Format, ImageSurface}; +use cairo::{Context, Format, ImageSurface}; use fltk::{enums::*, prelude::*, *}; -mod surface; - #[derive(Clone)] struct CairoButton { btn: button::Button, @@ -16,7 +14,7 @@ impl CairoButton { draw::draw_rect_fill(w.x(), w.y(), w.w(), w.h(), Color::White); let mut surface = ImageSurface::create(Format::ARgb32, w.w(), w.h()) .expect("Couldn’t create surface"); - surface::draw_surface(&mut surface, w.w(), w.h()); + draw_surface(&mut surface, w.w(), w.h()); if !w.value() { cairo_blur::blur_image_surface(&mut surface, 20); } @@ -86,3 +84,35 @@ fn main() { .run() .unwrap(); } + +fn draw_surface(surface: &mut ImageSurface, w: i32, h: i32) { + let ctx = Context::new(surface).unwrap(); + ctx.save().unwrap(); + let corner_radius = h as f64 / 10.0; + let radius = corner_radius / 1.0; + let degrees = std::f64::consts::PI / 180.0; + + ctx.new_sub_path(); + ctx.arc(w as f64 - radius, radius, radius, -90. * degrees, 0.0); + ctx.arc( + w as f64 - radius, + h as f64 - radius, + radius, + 0.0, + 90. * degrees, + ); + ctx.arc( + radius, + h as f64 - radius, + radius, + 90. * degrees, + 180. * degrees, + ); + ctx.arc(radius, radius, radius, 180. * degrees, 270. * degrees); + ctx.close_path(); + + ctx.set_source_rgba(150.0 / 255.0, 150.0 / 255.0, 150.0 / 255.0, 40.0 / 255.0); + ctx.set_line_width(4.); + ctx.fill().unwrap(); + ctx.restore().unwrap(); +} diff --git a/cairo_shadow_button/src/surface.rs b/cairo_shadow_button/src/surface.rs deleted file mode 100644 index d92e64b..0000000 --- a/cairo_shadow_button/src/surface.rs +++ /dev/null @@ -1,33 +0,0 @@ -use cairo::{Context, ImageSurface}; - -pub fn draw_surface(surface: &mut ImageSurface, w: i32, h: i32) { - let ctx = Context::new(surface).unwrap(); - ctx.save().unwrap(); - let corner_radius = h as f64 / 10.0; - let radius = corner_radius / 1.0; - let degrees = std::f64::consts::PI / 180.0; - - ctx.new_sub_path(); - ctx.arc(w as f64 - radius, radius, radius, -90. * degrees, 0.0); - ctx.arc( - w as f64 - radius, - h as f64 - radius, - radius, - 0.0, - 90. * degrees, - ); - ctx.arc( - radius, - h as f64 - radius, - radius, - 90. * degrees, - 180. * degrees, - ); - ctx.arc(radius, radius, radius, 180. * degrees, 270. * degrees); - ctx.close_path(); - - ctx.set_source_rgba(150.0 / 255.0, 150.0 / 255.0, 150.0 / 255.0, 40.0 / 255.0); - ctx.set_line_width(4.); - ctx.fill().unwrap(); - ctx.restore().unwrap(); -}