resolved clippy issues

This commit is contained in:
2025-06-27 09:20:02 +08:00
parent 01799ea4a0
commit 00c9787c17
2 changed files with 21 additions and 66 deletions

View File

@@ -157,12 +157,7 @@ fn draw_piece(
}
}
fn draw_score_bar(
cr: &CairoContext,
board: &Rectangle,
draughts_game: &DraughtsGame,
xform: &Matrix,
) {
fn draw_score_bar(cr: &CairoContext, board: &Rectangle, draughts_game: &DraughtsGame) {
let score_bar = Rectangle::new(
board.tl().x() - board.width() / 10.0,
board.tl().y(),
@@ -171,17 +166,7 @@ fn draw_score_bar(
);
let score_percentage = draughts_game.relative_score(Player::White) as f64;
let tl = score_bar.tl();
let br = score_bar.br();
{
let (tlx, tly) = xform.transform_point(tl.x(), tl.y());
let (brx, bry) = xform.transform_point(br.x(), br.y());
println!(
"tl: ({}, {}), br: ({}, {}), score: {}",
tlx, tly, brx, bry, score_percentage
);
}
cr.save().unwrap();
//cr.set_matrix(*xform);
cr.set_source_rgb(1.0, 1.0, 1.0);
cr.rectangle(
score_bar.tl().x(),
@@ -195,7 +180,7 @@ fn draw_score_bar(
tl.x(),
tl.y() + score_bar.height() * score_percentage,
score_bar.width(),
score_bar.height(),
score_bar.height() * (1.0 - score_percentage),
);
cr.fill().unwrap();
cr.restore().unwrap();
@@ -226,6 +211,10 @@ fn on_activate(application: &gtk::Application) {
let board_width = SQUARE_SIZE * DraughtsBoard::rows() as f64;
let board_height = SQUARE_SIZE * DraughtsBoard::columns() as f64;
let board = Rectangle::from_points(Point::new(0.0, 0.0), Point::new(board_width, board_height));
let board_with_bar = Rectangle::from_points(
Point::new(-board_width / 10.0, 0.0),
Point::new(board_width, board_height),
);
let board_clone = board;
let crown_red_handle = {
let stream = gio::MemoryInputStream::from_bytes(&glib::Bytes::from_static(CROWN_RED));
@@ -267,11 +256,11 @@ fn on_activate(application: &gtk::Application) {
Point::new(width as f64, height as f64),
);
let f = f64::min(
screen.width() / board.width(),
screen.height() / board.height(),
screen.width() / board_with_bar.width(),
screen.height() / board_with_bar.height(),
);
let screen_center = screen.center();
let board_center = board.center();
let board_center = board_with_bar.center();
let mut xform = xform.borrow_mut();
*xform = Matrix::multiply(
&Matrix::multiply(
@@ -389,7 +378,7 @@ fn on_activate(application: &gtk::Application) {
cr.restore().unwrap();
}
}
draw_score_bar(&cr, &board, &draughts_game.borrow(), &xform);
draw_score_bar(cr, &board, &draughts_game.borrow());
});
}
let gesture = gtk::GestureClick::new();