Skip to content

Commit

Permalink
Improve roundness of headerbar (PolyMeilex#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
Friz64 authored Dec 16, 2023
1 parent a5df4bf commit cc33bd2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## [Unreleased]

- Improved roundness of headerbar (#51)

## 0.8.0
- **Braking:** `AdwaitaFrame::new` now takes `Arc<CompositorState>` as an argument
- Fix leftmost title pixel sometimes being cut off (#45)
Expand Down
39 changes: 16 additions & 23 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,8 @@ fn draw_headerbar_bg(
}

fn rounded_headerbar_shape(x: f32, y: f32, width: f32, height: f32, radius: f32) -> Option<Path> {
use std::f32::consts::FRAC_1_SQRT_2;
// https://stackoverflow.com/a/27863181
let cubic_bezier_circle = 0.552_284_8 * radius;

let mut pb = PathBuilder::new();
let mut cursor = Point::from_xy(x, y);
Expand All @@ -725,41 +726,33 @@ fn rounded_headerbar_shape(x: f32, y: f32, width: f32, height: f32, radius: f32)
pb.move_to(cursor.x, cursor.y);

// Drawing the outline
let next = Point::from_xy(cursor.x + radius, cursor.y - radius);
pb.cubic_to(
cursor.x,
cursor.y,
cursor.x,
cursor.y - FRAC_1_SQRT_2 * radius,
{
cursor.x += radius;
cursor.x
},
{
cursor.y -= radius;
cursor.y
},
cursor.y - cubic_bezier_circle,
next.x - cubic_bezier_circle,
next.y,
next.x,
next.y,
);
cursor = next;
pb.line_to(
{
cursor.x = x + width - radius;
cursor.x
},
cursor.y,
);
let next = Point::from_xy(cursor.x + radius, cursor.y + radius);
pb.cubic_to(
cursor.x,
cursor.y,
cursor.x + FRAC_1_SQRT_2 * radius,
cursor.x + cubic_bezier_circle,
cursor.y,
{
cursor.x += radius;
cursor.x
},
{
cursor.y += radius;
cursor.y
},
next.x,
next.y - cubic_bezier_circle,
next.x,
next.y,
);
cursor = next;
pb.line_to(cursor.x, {
cursor.y = y + height;
cursor.y
Expand Down

0 comments on commit cc33bd2

Please sign in to comment.