Fix rustfmt and nixfmt
This commit is contained in:
+12
-10
@@ -1,7 +1,7 @@
|
||||
use crate::cell::{Cell, CellValue};
|
||||
use ndarray::{prelude::*, ViewRepr};
|
||||
use std::collections::HashSet;
|
||||
use std::fmt;
|
||||
use ndarray::{prelude::*, ViewRepr};
|
||||
|
||||
const REGION_SIZE: usize = 9;
|
||||
const SUB_REGION_SIZE: usize = 3;
|
||||
@@ -30,9 +30,7 @@ impl fmt::Display for Board {
|
||||
impl Board {
|
||||
pub fn new() -> Board {
|
||||
let cells = Array2::zeros((REGION_SIZE, REGION_SIZE));
|
||||
let board = Board {
|
||||
cells,
|
||||
};
|
||||
let board = Board { cells };
|
||||
board
|
||||
}
|
||||
|
||||
@@ -83,7 +81,10 @@ impl Board {
|
||||
0..REGION_SIZE
|
||||
}
|
||||
|
||||
pub fn square_iter(&self, point: &Point) -> ndarray::ArrayBase<ViewRepr<&Cell>, Dim<[usize; 2]>> {
|
||||
pub fn square_iter(
|
||||
&self,
|
||||
point: &Point,
|
||||
) -> ndarray::ArrayBase<ViewRepr<&Cell>, Dim<[usize; 2]>> {
|
||||
let row_bounds = point.row_bounds();
|
||||
let col_bounds = point.col_bounds();
|
||||
self.cells.slice(s![row_bounds, col_bounds])
|
||||
@@ -101,14 +102,12 @@ impl Board {
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub struct Point {
|
||||
row: usize,
|
||||
col: usize
|
||||
col: usize,
|
||||
}
|
||||
|
||||
impl Point {
|
||||
pub fn new(row: usize, col: usize) -> Point {
|
||||
Point {
|
||||
row, col
|
||||
}
|
||||
Point { row, col }
|
||||
}
|
||||
|
||||
fn coordinates(&self) -> [usize; 2] {
|
||||
@@ -118,7 +117,10 @@ impl Point {
|
||||
fn _bounds(val: usize) -> std::ops::Range<usize> {
|
||||
let mut start = val / (SUB_REGION_SIZE as usize);
|
||||
start *= SUB_REGION_SIZE;
|
||||
std::ops::Range {start, end: start + SUB_REGION_SIZE}
|
||||
std::ops::Range {
|
||||
start,
|
||||
end: start + SUB_REGION_SIZE,
|
||||
}
|
||||
}
|
||||
|
||||
fn row_bounds(&self) -> std::ops::Range<usize> {
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
use std::collections::HashSet;
|
||||
use num_traits::identities::Zero;
|
||||
use std::collections::HashSet;
|
||||
use std::ops::Add;
|
||||
use std::string::ToString;
|
||||
|
||||
@@ -27,7 +27,7 @@ impl ToString for CellValue {
|
||||
CellValue::Six => String::from("6"),
|
||||
CellValue::Seven => String::from("7"),
|
||||
CellValue::Eight => String::from("8"),
|
||||
CellValue::Nine => String::from("9")
|
||||
CellValue::Nine => String::from("9"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-5
@@ -1,6 +1,10 @@
|
||||
use iced::{border::Radius, widget::{button, text}, Background, Border, Color, Shadow, Theme};
|
||||
use super::super::cell::Cell;
|
||||
use super::Message;
|
||||
use iced::{
|
||||
border::Radius,
|
||||
widget::{button, text},
|
||||
Background, Border, Color, Shadow, Theme,
|
||||
};
|
||||
|
||||
const LIGHT_GRAY: Color = Color {
|
||||
r: 0.5,
|
||||
@@ -27,14 +31,12 @@ pub fn widget(cell: &Cell) -> iced::Element<Message> {
|
||||
|
||||
// Return a style based on the status
|
||||
match status {
|
||||
button::Status::Active => {
|
||||
button::Style{
|
||||
button::Status::Active => button::Style {
|
||||
background: Some(Background::from(palette.background)),
|
||||
text_color: palette.text,
|
||||
border,
|
||||
shadow: Shadow::default(),
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
let mut style = button::primary(theme, status);
|
||||
style.border.radius = Radius::new(0);
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
mod cell;
|
||||
mod board;
|
||||
mod cell;
|
||||
pub mod display;
|
||||
|
||||
pub use board::Board;
|
||||
|
||||
+5
-9
@@ -1,9 +1,8 @@
|
||||
use rustdoku::Board;
|
||||
use rustdoku::display;
|
||||
use rustdoku::Board;
|
||||
|
||||
use iced;
|
||||
|
||||
|
||||
struct State {
|
||||
board: Board,
|
||||
message: String,
|
||||
@@ -25,20 +24,17 @@ fn update(state: &mut State, _message: display::Message) {
|
||||
fn display(state: &State) -> iced::Element<display::Message> {
|
||||
let mut column: Vec<iced::Element<display::Message>> = Vec::with_capacity(9);
|
||||
for row_idx in state.board.row_range() {
|
||||
let row: Vec<iced::Element<display::Message>> = state.board
|
||||
let row: Vec<iced::Element<display::Message>> = state
|
||||
.board
|
||||
.row_iter(row_idx)
|
||||
.into_iter()
|
||||
.map(|c| display::cell::widget(c))
|
||||
.into_iter()
|
||||
.collect();
|
||||
column.push(
|
||||
iced::widget::Row::with_children(row)
|
||||
.into()
|
||||
);
|
||||
column.push(iced::widget::Row::with_children(row).into());
|
||||
}
|
||||
|
||||
iced::widget::Column::with_children(column)
|
||||
.into()
|
||||
iced::widget::Column::with_children(column).into()
|
||||
}
|
||||
|
||||
fn main() -> iced::Result {
|
||||
|
||||
Reference in New Issue
Block a user