Skip to content

Commit

Permalink
format and lint cairo_shadow_button
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem V. Ageev committed Apr 1, 2024
1 parent 5b8778a commit 9e5448b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 40 deletions.
2 changes: 1 addition & 1 deletion cairo-demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ edition = "2021"

[dependencies]
fltk = { version = "^1.4", features = ["cairoext"] }
cairo-rs = "^0.19"
cairo-rs = "0.18"
5 changes: 3 additions & 2 deletions cairo_shadow_button/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[package]
name = "cairo_button"
version = "0.1.0"
authors = ["Mohammed Alyousef <[email protected]>"]
edition = "2021"

[dependencies]
fltk = "^1.4"
cairo-rs = "0.18"
cairo-blur = "0.1.0"
cairo-rs = "^0.19"
cairo-blur = "^0.1"
38 changes: 34 additions & 4 deletions cairo_shadow_button/src/main.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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);
}
Expand Down Expand Up @@ -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();
}
33 changes: 0 additions & 33 deletions cairo_shadow_button/src/surface.rs

This file was deleted.

0 comments on commit 9e5448b

Please sign in to comment.