Resolve warnings in cyberpunk-splash

This commit is contained in:
Savanni D'Gerinel 2023-10-04 16:20:28 -04:00
parent f1f4afc65a
commit f1204faa5e
2 changed files with 32 additions and 48 deletions

View File

@ -2,6 +2,7 @@
name = "cyberpunk-splash"
version = "0.1.0"
edition = "2021"
license = "GPL-3.0-only"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -2,8 +2,8 @@ use cairo::{
Context, FontSlant, FontWeight, Format, ImageSurface, LineCap, LinearGradient, Pattern,
TextExtents,
};
use glib::{GString, Object};
use gtk::{gdk::Key, prelude::*, subclass::prelude::*, EventControllerKey};
use glib::Object;
use gtk::{prelude::*, subclass::prelude::*, EventControllerKey};
use std::{
cell::RefCell,
rc::Rc,
@ -14,12 +14,6 @@ use std::{
const WIDTH: i32 = 1600;
const HEIGHT: i32 = 600;
#[derive(Clone, Copy, Debug)]
enum Event {
Frames(u8),
Time(Duration),
}
#[derive(Clone, Copy, Debug)]
pub enum State {
Running {
@ -50,7 +44,7 @@ impl State {
*self = Self::Running {
last_update: Instant::now(),
deadline: Instant::now() + *time_remaining,
timeout: timeout.clone(),
timeout: *timeout,
};
}
}
@ -62,7 +56,7 @@ impl State {
{
*self = Self::Paused {
time_remaining: *deadline - Instant::now(),
timeout: timeout.clone(),
timeout: *timeout,
}
}
}
@ -108,13 +102,13 @@ impl TimeoutAnimation {
fn tick(&mut self, frames_elapsed: u8) {
let step_size = 1. / (self.duration * 60.);
if self.ascending {
self.intensity = self.intensity + step_size * frames_elapsed as f64;
self.intensity += step_size * frames_elapsed as f64;
if self.intensity > 1. {
self.intensity = 1.0;
self.ascending = false;
}
} else {
self.intensity = self.intensity - step_size * frames_elapsed as f64;
self.intensity -= step_size * frames_elapsed as f64;
if self.intensity < 0. {
self.intensity = 0.0;
self.ascending = true;
@ -148,7 +142,6 @@ impl SplashPrivate {
*self.height.borrow(),
2.,
8.,
8.,
(0.7, 0., 1.),
);
@ -333,7 +326,7 @@ impl Splash {
let _ = context.set_source(&*background);
let _ = context.paint();
let state = s.imp().state.borrow().clone();
let state = *s.imp().state.borrow();
let time = match state {
State::Running { deadline, .. } => deadline - Instant::now(),
@ -359,7 +352,7 @@ impl Splash {
let mut saved_extents = s.imp().time_extents.borrow_mut();
if saved_extents.is_none() {
*saved_extents = Some(time_extents.clone());
*saved_extents = Some(time_extents);
}
let time_baseline_x = center_x - time_extents.width() / 2.;
@ -372,8 +365,8 @@ impl Splash {
time_baseline_y,
);
let (running, timeout_animation) = match state {
State::Running { timeout, .. } => (true, timeout.clone()),
State::Paused { timeout, .. } => (false, timeout.clone()),
State::Running { timeout, .. } => (true, timeout),
State::Paused { timeout, .. } => (false, timeout),
};
match timeout_animation {
Some(ref animation) => {
@ -395,8 +388,7 @@ impl Splash {
let _ = context.show_text(&time);
};
match *s.imp().time_extents.borrow() {
Some(extents) => {
if let Some(extents) = *s.imp().time_extents.borrow() {
context.set_source_rgb(0.7, 0.0, 1.0);
let time_meter = SlashMeter {
orientation: gtk::Orientation::Horizontal,
@ -407,9 +399,7 @@ impl Splash {
height: 60.,
length: 100.,
};
time_meter.draw(&context);
}
None => {}
time_meter.draw(context);
}
}
});
@ -544,7 +534,7 @@ impl SlashMeter {
gtk::Orientation::Horizontal => {
let angle: f64 = 0.8;
let run = self.height / angle.tan();
let width = self.length as f64 / (self.count as f64 * 2.);
let width = self.length / (self.count as f64 * 2.);
for c in 0..self.count {
context.set_line_width(1.);
@ -579,10 +569,6 @@ trait Pen {
struct GlowPen {
blur_context: Context,
draw_context: Context,
line_width: f64,
blur_line_width: f64,
blur_size: f64,
}
impl GlowPen {
@ -591,7 +577,6 @@ impl GlowPen {
height: i32,
line_width: f64,
blur_line_width: f64,
blur_size: f64,
color: (f64, f64, f64),
) -> Self {
let blur_context =
@ -611,9 +596,6 @@ impl GlowPen {
Self {
blur_context,
draw_context,
line_width,
blur_line_width,
blur_size,
}
}
}
@ -630,8 +612,10 @@ impl Pen for GlowPen {
}
fn stroke(&self) {
self.blur_context.stroke();
self.draw_context.stroke();
self.blur_context.stroke().expect("to draw the blur line");
self.draw_context
.stroke()
.expect("to draw the regular line");
}
fn finish(self) -> Pattern {
@ -681,7 +665,7 @@ fn main() {
let countdown = match options.lookup::<String>("countdown") {
Ok(Some(countdown_str)) => {
let parts = countdown_str.split(':').collect::<Vec<&str>>();
let duration = match parts.len() {
match parts.len() {
2 => {
let minutes = parts[0].parse::<u64>().unwrap();
let seconds = parts[1].parse::<u64>().unwrap();
@ -692,8 +676,7 @@ fn main() {
Duration::from_secs(seconds)
}
_ => Duration::from_secs(300),
};
duration
}
}
_ => Duration::from_secs(300),
};
@ -725,7 +708,7 @@ fn main() {
let window = gtk::ApplicationWindow::new(app);
window.present();
let splash = Splash::new(title.read().unwrap().clone(), state.read().unwrap().clone());
let splash = Splash::new(title.read().unwrap().clone(), *state.read().unwrap());
window.set_child(Some(&splash));
@ -763,7 +746,7 @@ fn main() {
loop {
std::thread::sleep(Duration::from_millis(1000 / 60));
state.write().unwrap().run(Instant::now());
let _ = gtk_tx.send(state.read().unwrap().clone());
let _ = gtk_tx.send(*state.read().unwrap());
}
}
});