Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
23b0965
commit db1d359
Showing
3 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ features = [ | |
'Document', | ||
'Element', | ||
'HtmlElement', | ||
'SvgImageElement', | ||
'Node', | ||
'Window', | ||
'Attr', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,56 @@ | ||
|
||
use wasm_bindgen::prelude::*; | ||
use web_sys::{Document, Element}; | ||
|
||
#[wasm_bindgen(start)] | ||
pub fn go() -> Result<(), JsValue> { | ||
let window = web_sys::window().expect("no global window"); | ||
let document = window.document().expect("window has no document"); | ||
let body = document.body().expect("document has no body"); | ||
|
||
let val = document.create_element("p")?; | ||
val.set_inner_html("Hello from Rust!"); | ||
body.append_child(&val)?; | ||
let title = { | ||
let title = document.create_element("h1")?; | ||
title.set_inner_html("Calendar"); | ||
title | ||
}; | ||
body.append_child(&title)?; | ||
|
||
let container = { | ||
let container = document.create_element("div")?; | ||
container.set_attribute("width", "1000")?; | ||
container.set_attribute("height", "1000")?; | ||
|
||
let svg = svg(&document)?; | ||
container.append_child(&svg)?; | ||
|
||
container | ||
}; | ||
body.append_child(&container)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn svg(document: &Document) -> Result<Element, JsValue> | ||
{ | ||
const XMLNS: &'static str = "http://www.w3.org/2000/svg"; | ||
|
||
let svg = document.create_element_ns(Some(XMLNS), "svg")?; | ||
svg.set_attribute_ns(None, "viewBox", "0 0 1000 1000")?; | ||
svg.set_attribute_ns(None, "width", "1000")?; | ||
svg.set_attribute_ns(None, "height", "1000")?; | ||
//svg.style.display = "block"; | ||
svg.set_attribute_ns(None, "id", "calendar")?; | ||
svg.set_attribute_ns(None, "version", "1.1")?; | ||
|
||
let circle = document.create_element_ns(Some(XMLNS), "circle")?; | ||
circle.set_attribute_ns(None, "cx", "500")?; | ||
circle.set_attribute_ns(None, "cy", "500")?; | ||
circle.set_attribute_ns(None, "r", "499")?; | ||
circle.set_attribute_ns(None, "stroke", "black")?; | ||
circle.set_attribute_ns(None, "stroke-width", "1")?; | ||
circle.set_attribute_ns(None, "fill", "lightyellow")?; | ||
circle.set_attribute_ns(None, "id", "maincircle")?; | ||
svg.append_child(&circle)?; | ||
|
||
Ok(svg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,9 @@ a:hover, a:active { | |
.large { | ||
font-size:1.4rem; | ||
} | ||
|
||
#calendar { | ||
display: block; | ||
width: 1000px; | ||
height: 1000px; | ||
} |