Advertisement
loloof64

rust_board_snippet

Nov 25th, 2018
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.91 KB | None | 0 0
  1.  fn get_chessboard(cells_size: u32, initial_position: &str) -> Option<RefCell<ChessBoard>>
  2.     {
  3.         let drawing_area = DrawingArea::new();
  4.  
  5.         let logic = ChessGame::new_from_fen(initial_position);
  6.  
  7.         match logic {
  8.             Some(game_logic) => {
  9.                 let chess_board = ChessBoard {
  10.                     drawing_area,
  11.                     reversed: false,
  12.                     logic: game_logic,
  13.                     cells_size,
  14.                 };
  15.  
  16.                 let chess_board_ref = RefCell::new(chess_board);
  17.                 let chess_board_ref_2 = chess_board_ref.clone();
  18.  
  19.                 chess_board_ref.borrow().drawing_area.connect_draw(move |_drawing_area, cr|{
  20.                     chess_board_ref_2.borrow().paint(cr);
  21.                     Inhibit(false)
  22.                 });
  23.  
  24.                 Some(chess_board_ref)
  25.             },
  26.             _ => None
  27.         }
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement