Skip to content

Commit

Permalink
Allow fill_rounding on progress block.
Browse files Browse the repository at this point in the history
  • Loading branch information
Toqozz committed Aug 22, 2021
1 parent 7a3c713 commit b9e29f1
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 10 deletions.
Binary file added readme_stuff/rounding_artifact.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added readme_stuff/rounding_correct.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ mod bus;
mod config;
mod maths_utility;

use std::env;
use std::time::{Instant, Duration};
use std::os::unix::net::{ UnixStream, UnixListener };
use std::io::{BufRead, BufReader};

use winit::{
event::{StartCause, Event, WindowEvent},
Expand All @@ -23,9 +26,27 @@ use config::Config;
use management::NotifyWindowManager;
use wired_derive;

/*
fn run_daemon() {
}
*/

fn main() {
let maybe_watcher = Config::init();

// Socket, for listening to CLI calls to ourselves.
/*
std::fs::remove_file("/tmp/wired.sock").unwrap();
let socket_listener = match UnixListener::bind("/tmp/wired.sock") {
Ok(sock) => sock,
Err(e) => {
eprintln!("Couldn't bind socket /tmp/wired.sock, is another wired instance running?\n{:?}", e);
return;
}
};
*/

// Allows us to receive messages from dbus.
let receiver = bus::dbus::init_connection();
let dbus_connection = bus::dbus::get_connection();
Expand All @@ -46,6 +67,25 @@ fn main() {
prev_instant = now;
manager.update(time_passed);

// Read wired socket signals.
/*
for stream in socket_listener.incoming() {
match stream {
Ok(stream) => {
let stream = BufReader::new(stream);
for line in stream.lines() {
println!("{}", line.unwrap());
}
},
Err(e) => {
dbg!("Error reading stream.");
break;
}
}
}
*/

// Check dbus signals.
// If we don't do get incoming signals, notify sender will block when sending.
let signal = dbus_connection.incoming(0).next();
Expand Down
10 changes: 5 additions & 5 deletions src/maths_utility/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,28 +255,28 @@ pub fn cairo_rounded_bordered_rectangle(ctx: &cairo::Context, x: f64, y: f64, wi
// Creates a rounded rectangle with a border that acts as a user would expect.
// Obeys background opacity and such -- border color is not present on the background like it would
// be with the naive approach.
pub fn cairo_rounded_bordered_filled_rectangle(ctx: &cairo::Context, x: f64, y: f64, width: f64, height: f64, fill_percent: f64, corner_radius: f64, thickness: f64, fg_color: &Color, bg_color: &Color, fill_color: &Color) {
pub fn cairo_rounded_bordered_filled_rectangle(ctx: &cairo::Context, x: f64, y: f64, width: f64, height: f64, fill_percent: f64, border_corner_radius: f64, fill_corner_radius: f64, thickness: f64, fg_color: &Color, bg_color: &Color, fill_color: &Color) {
ctx.save();

// To my understanding, push group basically lets us write to another texture, which we can
// then paint on top of stuff later.
ctx.push_group();
ctx.set_operator(cairo::Operator::Source);
cairo_path_rounded_rectangle(ctx, x, y, width, height, corner_radius);
cairo_path_rounded_rectangle(ctx, x, y, width, height, border_corner_radius);
ctx.set_source_rgba(fg_color.r, fg_color.g, fg_color.b, fg_color.a);
ctx.fill();

// Background clipping path (to prevent leaks at small fill %s).
cairo_path_rounded_rectangle(ctx, x + thickness, y + thickness, width - thickness * 2.0, height - thickness * 2.0, corner_radius);
cairo_path_rounded_rectangle(ctx, x + thickness, y + thickness, width - thickness * 2.0, height - thickness * 2.0, fill_corner_radius);
ctx.clip_preserve();

// Draw background, which subtracts from the clipping area path.
cairo_path_rounded_rectangle_inverse(ctx, x + thickness, y + thickness, (width - thickness * 2.0)*fill_percent, height - thickness * 2.0, corner_radius);
cairo_path_rounded_rectangle_inverse(ctx, x + thickness, y + thickness, (width - thickness * 2.0)*fill_percent, height - thickness * 2.0, fill_corner_radius);
ctx.set_source_rgba(bg_color.r, bg_color.g, bg_color.b, bg_color.a);
ctx.fill();

// Draw fill area, on top of the background.
cairo_path_rounded_rectangle(ctx, x + thickness, y + thickness, (width - thickness * 2.0)*fill_percent, height - thickness * 2.0, corner_radius);
cairo_path_rounded_rectangle(ctx, x + thickness, y + thickness, (width - thickness * 2.0)*fill_percent, height - thickness * 2.0, fill_corner_radius);
ctx.set_source_rgba(fill_color.r, fill_color.g, fill_color.b, fill_color.a);
ctx.fill();

Expand Down
13 changes: 8 additions & 5 deletions src/rendering/blocks/progress_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ pub struct ProgressBlockParameters {
pub padding: Padding,
pub border_width: f64,
pub border_rounding: f64,
pub fill_rounding: f64,
pub border_color: Color,
pub background_color: Color,
pub fill_color: Color,
pub size: Vec2,
pub width: f64,
pub height: f64,

// -- Optional fields
pub border_color_hovered: Option<Color>,
Expand Down Expand Up @@ -63,8 +65,8 @@ impl DrawableLayoutElement for ProgressBlockParameters {
let background_col = self.background_color();
let fill_col = self.fill_color();

let width = if self.size.x < 0.0 { parent_rect.width() } else { self.size.x + self.padding.width() };
let height = if self.size.y < 0.0 { parent_rect.height() } else { self.size.y + self.padding.height() };
let width = if self.width < 0.0 { parent_rect.width() } else { self.width + self.padding.width() };
let height = if self.height < 0.0 { parent_rect.height() } else { self.height + self.padding.height() };
let mut rect = Rect::new(
0.0, 0.0,
width, height,
Expand All @@ -78,6 +80,7 @@ impl DrawableLayoutElement for ProgressBlockParameters {
width - self.padding.width(), height - self.padding.height(),
self.percentage,
self.border_rounding,
self.fill_rounding,
self.border_width,
border_col,
background_col,
Expand All @@ -101,8 +104,8 @@ impl DrawableLayoutElement for ProgressBlockParameters {
eprintln!("Warning: padding width/height exceeds parent rect width/height.");
}

let width = if self.size.x < 0.0 { parent_rect.width() } else { self.size.x + self.padding.width() };
let height = if self.size.y < 0.0 { parent_rect.height() } else { self.size.y + self.padding.height() };
let width = if self.width < 0.0 { parent_rect.width() } else { self.width + self.padding.width() };
let height = if self.height < 0.0 { parent_rect.height() } else { self.height + self.padding.height() };
let mut rect = Rect::new(
0.0, 0.0,
width, height,
Expand Down

0 comments on commit b9e29f1

Please sign in to comment.