[Code Cleanup] Format code with rustfmt
This commit is contained in:
		
							
								
								
									
										69
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										69
									
								
								src/main.rs
									
									
									
									
									
								
							| @@ -2,14 +2,14 @@ extern crate smithay_client_toolkit as sctk; | ||||
|  | ||||
| use std::time::SystemTime; | ||||
|  | ||||
| use chrono::Timelike; | ||||
| use chrono::prelude::Local; | ||||
| use chrono::Timelike; | ||||
| use sctk::reexports::client::protocol::{wl_shm, wl_surface}; | ||||
| use sctk::shm::AutoMemPool; | ||||
| use sctk::window::{Event as WEvent, FallbackFrame}; | ||||
| use svg::Document; | ||||
| use svg::node::Text as TextNode; | ||||
| use svg::node::element::{Group, Line, Rectangle, Style, Text}; | ||||
| use svg::node::Text as TextNode; | ||||
| use svg::Document; | ||||
|  | ||||
| sctk::default_environment!(SeasonalClock, desktop); | ||||
|  | ||||
| @@ -17,8 +17,7 @@ fn seconds_to_degrees(seconds: i32) -> f32 { | ||||
|     seconds as f32 * 360.0 / 86400.0 | ||||
| } | ||||
|  | ||||
| fn time_to_degrees( | ||||
|     timestamp: i32  // should be time/timestamp | ||||
| fn time_to_degrees(timestamp: i32, // should be time/timestamp | ||||
| ) -> f32 { | ||||
|     seconds_to_degrees(timestamp) | ||||
| } | ||||
| @@ -40,12 +39,13 @@ fn gen_svg() -> Document { | ||||
|         .set("width", 700i32) | ||||
|         .set("height", 700i32) | ||||
|         .set("id", "border"); | ||||
|     let stylesheet = Style::new("\ | ||||
|     let stylesheet = Style::new( | ||||
|         "\ | ||||
|         #border {stroke: none; fill: rgb(19, 17, 30); } | ||||
|         .local-hour {stroke: none; fill: rgb(238, 187, 85);} | ||||
|         .dial {stroke-width: 2px; stroke: rgb(238, 187, 85);}"); | ||||
|     let mut local_clock = Group::new() | ||||
|         .set("id", "local-clock"); | ||||
|         .dial {stroke-width: 2px; stroke: rgb(238, 187, 85);}", | ||||
|     ); | ||||
|     let mut local_clock = Group::new().set("id", "local-clock"); | ||||
|  | ||||
|     for hour in 0i32..24 { | ||||
|         let hour_str = match hour { | ||||
| @@ -59,7 +59,10 @@ fn gen_svg() -> Document { | ||||
|             .set("class", "local-hour") | ||||
|             .set("transform", format!("rotate({}, 350, 350)", 180 + rotation)) | ||||
|             .set("x", (image_width as f32) / 2.0) | ||||
|             .set("y", (image_width as f32) / 2.0 - outer_r - local_hour_font_size / 2.0) | ||||
|             .set( | ||||
|                 "y", | ||||
|                 (image_width as f32) / 2.0 - outer_r - local_hour_font_size / 2.0, | ||||
|             ) | ||||
|             .set("text-anchor", "middle") | ||||
|             .set("font-size", local_hour_font_size as f32) | ||||
|             .add(hour_name); | ||||
| @@ -69,11 +72,22 @@ fn gen_svg() -> Document { | ||||
|     let dial = Line::new() | ||||
|         .set("id", "dial") | ||||
|         .set("class", "dial") | ||||
|         .set("transform", format!("rotate({}, {}, {})", time_to_degrees(local_time), image_width / 2, image_width / 2)) | ||||
|         .set( | ||||
|             "transform", | ||||
|             format!( | ||||
|                 "rotate({}, {}, {})", | ||||
|                 time_to_degrees(local_time), | ||||
|                 image_width / 2, | ||||
|                 image_width / 2 | ||||
|             ), | ||||
|         ) | ||||
|         .set("x1", image_width / 2) | ||||
|         .set("y1", image_width as f32 / 2.0 + outer_r * 0.5) | ||||
|         .set("x2", image_width / 2) | ||||
|         .set("y2", image_width as f32 / 2.0 + outer_r - ring_width + hour_name_font_size); | ||||
|         .set( | ||||
|             "y2", | ||||
|             image_width as f32 / 2.0 + outer_r - ring_width + hour_name_font_size, | ||||
|         ); | ||||
|  | ||||
|     Document::new() | ||||
|         .set("viewBox", (0i32, 0i32, 700i32, 700i32)) | ||||
| @@ -122,13 +136,14 @@ fn main() { | ||||
|  | ||||
|     window.set_title("Seasonal Hours Clock".to_string()); | ||||
|  | ||||
|     let mut pool = env.create_auto_pool().expect("Failed to create the memory pool."); | ||||
|     let mut pool = env | ||||
|         .create_auto_pool() | ||||
|         .expect("Failed to create the memory pool."); | ||||
|     let mut need_redraw = false; | ||||
|     let mut dimensions = (700, 700); | ||||
|  | ||||
|     if !env.get_shell().unwrap().needs_configure() { | ||||
|         redraw(&mut pool, window.surface(), dimensions) | ||||
|             .expect("Failed to draw"); | ||||
|         redraw(&mut pool, window.surface(), dimensions).expect("Failed to draw"); | ||||
|         window.refresh() | ||||
|     } | ||||
|  | ||||
| @@ -157,7 +172,10 @@ fn main() { | ||||
|                 window.refresh(); | ||||
|                 window.surface().commit(); | ||||
|             } | ||||
|             Some(WEvent::Configure { new_size, states: _ }) => { | ||||
|             Some(WEvent::Configure { | ||||
|                 new_size, | ||||
|                 states: _, | ||||
|             }) => { | ||||
|                 if let Some((w, h)) = new_size { | ||||
|                     if dimensions != (w, h) { | ||||
|                         dimensions = (w, h); | ||||
| @@ -173,8 +191,7 @@ fn main() { | ||||
|         if need_redraw { | ||||
|             need_redraw = false; | ||||
|  | ||||
|             redraw(&mut pool, window.surface(), dimensions) | ||||
|                 .expect("Failed to draw") | ||||
|             redraw(&mut pool, window.surface(), dimensions).expect("Failed to draw") | ||||
|         } | ||||
|  | ||||
|         if let Err(e) = display.flush() { | ||||
| @@ -186,12 +203,16 @@ fn main() { | ||||
|         if let Some(guard) = queue.prepare_read() { | ||||
|             if let Err(e) = guard.read_events() { | ||||
|                 if e.kind() != ::std::io::ErrorKind::WouldBlock { | ||||
|                     eprintln!("Error while trying to read from the wayland socked: {:?}", e); | ||||
|                     eprintln!( | ||||
|                         "Error while trying to read from the wayland socked: {:?}", | ||||
|                         e | ||||
|                     ); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         queue.dispatch_pending(&mut next_action, |_, _, _| {}) | ||||
|         queue | ||||
|             .dispatch_pending(&mut next_action, |_, _, _| {}) | ||||
|             .expect("Failed to dispatch all messages."); | ||||
|     } | ||||
| } | ||||
| @@ -220,7 +241,13 @@ fn redraw( | ||||
|     let move_x = (buf_x - image_size) as f32 / 2.0; | ||||
|     let move_y = (buf_y - image_size) as f32 / 2.0; | ||||
|     let mut pixmap = tiny_skia::Pixmap::new(buf_x, buf_y).unwrap(); | ||||
|     resvg::render(&svg_tree, usvg::FitTo::Size(image_size, image_size), tiny_skia::Transform::from_translate(move_x, move_y), pixmap.as_mut()).unwrap(); | ||||
|     resvg::render( | ||||
|         &svg_tree, | ||||
|         usvg::FitTo::Size(image_size, image_size), | ||||
|         tiny_skia::Transform::from_translate(move_x, move_y), | ||||
|         pixmap.as_mut(), | ||||
|     ) | ||||
|     .unwrap(); | ||||
|     // We do not have anything to draw yet, so draw an empty surface | ||||
|     for (dst_pixel, src_pixel) in canvas.chunks_exact_mut(4).zip(pixmap.pixels()) { | ||||
|         let r = src_pixel.red() as u32; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user