SHARE
TWEET

rust_board_snippet

loloof64 Nov 25th, 2018 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top