Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings in rustc 1.46.0 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ pub fn init_app() -> Result<(), JsValue> {
let state: Rc<RefCell<state::State>> = Rc::new(RefCell::new(state::State::new(w, h)));

let root = document.create_element("div")?;
root.set_attribute("style", "min-height: 100%;");
root.set_attribute("style", "min-height: 100%;")?;

body.append_child(&root);
body.append_child(&root)?;

let canvas_el = document
.create_element("canvas")?
Expand All @@ -35,12 +35,12 @@ pub fn init_app() -> Result<(), JsValue> {
canvas_el.set_height(h);

root.append_child(&canvas_el)?;
canvas::init_canvas(&canvas_el, &state);
canvas::init_canvas(&canvas_el, &state)?;

let toolbar_el = document.create_element("div")?.dyn_into::<Element>()?;
toolbar_el.set_attribute("style", "width:100%; border-left: 1px solid #efefef;");
toolbar_el.set_attribute("style", "width:100%; border-left: 1px solid #efefef;")?;
body.append_child(&toolbar_el)?;
toolbar::init_toolbar(&toolbar_el, &canvas_el, &state);
toolbar::init_toolbar(&toolbar_el, &canvas_el, &state)?;

Ok(())
}
Expand Down
35 changes: 21 additions & 14 deletions src/toolbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ use web_sys::{

use crate::state::{State, COLORS, PEN_SIZES};

const generic_box_styles: &str = "height: 50px; border-bottom: 1px solid #efefef; display: flex; align-items: center; justify-content: center;";
const GENERIC_BOX_STYLES: &str =
"height: 50px; \
border-bottom: 1px solid #efefef; \
display: flex; \
align-items: center; \
justify-content: center;";

enum UndoRedo {
Undo,
Expand All @@ -35,12 +40,12 @@ pub fn init_toolbar(
}

let clear_el = get_clear_element(&document, state, canvas)?;
toolbar.append_child(&clear_el);
toolbar.append_child(&clear_el)?;

let undo_el = get_undo_redo_element(UndoRedo::Undo, &document, state, canvas)?;
toolbar.append_child(&undo_el);
toolbar.append_child(&undo_el)?;
let redo_el = get_undo_redo_element(UndoRedo::Redo, &document, state, canvas)?;
toolbar.append_child(&redo_el);
toolbar.append_child(&redo_el)?;

Ok(())
}
Expand All @@ -54,8 +59,8 @@ fn get_color_block_element(

el.set_attribute(
"style",
&format!("{} background-color: {};", generic_box_styles, hex),
);
&format!("{} background-color: {};", GENERIC_BOX_STYLES, hex),
)?;

let state_copy = state.clone();

Expand All @@ -77,7 +82,7 @@ fn get_pen_size_element(
) -> Result<Element, JsValue> {
let el = document.create_element("div")?;

el.set_attribute("style", generic_box_styles);
el.set_attribute("style", GENERIC_BOX_STYLES)?;

let inner_el = document.create_element("div")?;

Expand All @@ -86,8 +91,8 @@ fn get_pen_size_element(
size + 2.0,
size + 2.0
);
inner_el.set_attribute("style", &style);
el.append_child(&inner_el);
inner_el.set_attribute("style", &style)?;
el.append_child(&inner_el)?;

let state_copy = state.clone();

Expand All @@ -111,8 +116,8 @@ fn get_clear_element(

el.set_attribute(
"style",
&format!("{} font-size: 11px; cursor: default;", generic_box_styles),
);
&format!("{} font-size: 11px; cursor: default;", GENERIC_BOX_STYLES),
)?;
el.set_inner_html("clear");

let state_copy = state.clone();
Expand Down Expand Up @@ -156,8 +161,8 @@ fn get_undo_redo_element(

el.set_attribute(
"style",
&format!("{} font-size: 11px; cursor: default;", generic_box_styles),
);
&format!("{} font-size: 11px; cursor: default;", GENERIC_BOX_STYLES),
)?;
let text = match undo_or_redo {
UndoRedo::Undo => "undo",
UndoRedo::Redo => "redo",
Expand Down Expand Up @@ -209,7 +214,9 @@ fn get_undo_redo_element(
state_copy_2.borrow().get_width() as f64,
state_copy_2.borrow().get_height() as f64,
);
context_copy.draw_image_with_html_image_element(&image_el, 0.0, 0.0);
context_copy.draw_image_with_html_image_element(
&image_el, 0.0, 0.0
).expect("draw_image_with_html_image_element() failed");
}) as Box<dyn FnMut()>);

html_image_el.set_onload(Some(handle_onload.as_ref().unchecked_ref()));
Expand Down