pub struct Painter {Show 19 fields
canvas: HtmlCanvasElement,
context: CanvasRenderingContext2d,
selected_idx: Option<BrdIdx>,
white_square: JsValue,
black_square: JsValue,
white_piece: JsValue,
black_piece: JsValue,
selected_piece: JsValue,
white_piece_line: JsValue,
black_piece_line: JsValue,
selected_piece_line: JsValue,
king_line: JsValue,
piece_lines: bool,
piece_line_proportion: f64,
square_outline: JsValue,
outline_width: f64,
draw_outline: bool,
width: u32,
height: u32,
}
Expand description
Used to paint boards onto HTML canvases
Fields
canvas: HtmlCanvasElement
context: CanvasRenderingContext2d
selected_idx: Option<BrdIdx>
white_square: JsValue
black_square: JsValue
white_piece: JsValue
black_piece: JsValue
selected_piece: JsValue
white_piece_line: JsValue
black_piece_line: JsValue
selected_piece_line: JsValue
king_line: JsValue
piece_lines: bool
piece_line_proportion: f64
square_outline: JsValue
outline_width: f64
draw_outline: bool
width: u32
height: u32
Implementations
sourceimpl Painter
impl Painter
sourcepub fn set_selected(&mut self, idx: &Option<BrdIdx>)
pub fn set_selected(&mut self, idx: &Option<BrdIdx>)
Set selected piece by board index
sourcefn get_canvas(canvas_id: &str) -> HtmlCanvasElement
fn get_canvas(canvas_id: &str) -> HtmlCanvasElement
Get a canvas by element ID
sourcefn get_canvas_context(canvas: &HtmlCanvasElement) -> CanvasRenderingContext2d
fn get_canvas_context(canvas: &HtmlCanvasElement) -> CanvasRenderingContext2d
Get a 2D canvas context for a given canvas
sourceimpl Painter
impl Painter
sourcepub fn new(width: u32, height: u32, canvas_id: &str) -> Painter
pub fn new(width: u32, height: u32, canvas_id: &str) -> Painter
Default constructor which queries for canvas by ID
sourcepub fn new_with_canvas(
width: u32,
height: u32,
canvas: HtmlCanvasElement
) -> Painter
pub fn new_with_canvas(
width: u32,
height: u32,
canvas: HtmlCanvasElement
) -> Painter
Constructor with given canvas element
sourcepub fn set_square_outline(&mut self, value: JsValue)
pub fn set_square_outline(&mut self, value: JsValue)
Set new square outline colour value
sourcepub fn set_outline_width(&mut self, value: f64)
pub fn set_outline_width(&mut self, value: f64)
Set new line width for outlining squares
sourcepub fn set_draw_outline(&mut self, value: bool)
pub fn set_draw_outline(&mut self, value: bool)
Set whether squares are outlined
sourcepub fn reset_dimensions(&self)
pub fn reset_dimensions(&self)
Reset the canvas dimensions to the given width and height
sourcepub fn validate_board_dim(&self, board: &Board) -> bool
pub fn validate_board_dim(&self, board: &Board) -> bool
Check whether given canvas dimensions divide evenly by given board dimenions
Trait Implementations
sourceimpl FromWasmAbi for Painter
impl FromWasmAbi for Painter
sourceimpl IntoWasmAbi for Painter
impl IntoWasmAbi for Painter
sourceimpl OptionFromWasmAbi for Painter
impl OptionFromWasmAbi for Painter
sourceimpl OptionIntoWasmAbi for Painter
impl OptionIntoWasmAbi for Painter
sourceimpl RefFromWasmAbi for Painter
impl RefFromWasmAbi for Painter
type Anchor = Ref<'static, Painter>
type Anchor = Ref<'static, Painter>
The type that holds the reference to Self
for the duration of the
invocation of the function that has an &Self
parameter. This is
required to ensure that the lifetimes don’t persist beyond one function
call, and so that they remain anonymous. Read more
sourceunsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor
unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor
Recover a Self::Anchor
from Self::Abi
. Read more
sourceimpl RefMutFromWasmAbi for Painter
impl RefMutFromWasmAbi for Painter
sourceimpl WasmDescribe for Painter
impl WasmDescribe for Painter
Auto Trait Implementations
impl RefUnwindSafe for Painter
impl !Send for Painter
impl !Sync for Painter
impl Unpin for Painter
impl UnwindSafe for Painter
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ReturnWasmAbi for T where
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for T where
T: IntoWasmAbi,
type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
Same as IntoWasmAbi::Abi
sourcefn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
Same as IntoWasmAbi::into_abi
, except that it may throw and never
return in the case of Err
. Read more