-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
Showing
18 changed files
with
228 additions
and
59 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
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
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
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Creating SVGs with mogwai | ||
*S*calable *V*ector *G*raphics are images that are specified with XML. An SVG's | ||
markup looks a lot like HTML markup and allows developers and artists to quickly | ||
create images that can be resized without degrading the quality of the image. | ||
|
||
### Contents | ||
- [Explanation](#explanation) | ||
- [Notes](#notes) | ||
- [Code](#code) | ||
- [Example](#example) | ||
|
||
## Explanation | ||
|
||
In `mogwai` we create SVG images using the same RSX we use to create any other | ||
[`View`][structviewbuilder]. There's just one extra attribute we need to specify | ||
that lets the browser know that we're drawing an SVG image instead of HTML - | ||
the `xmlns` attribute. | ||
|
||
## Notes | ||
|
||
Unfortunately we must supply this namespace for each SVG node. It ends up not | ||
being too much of a burden. | ||
|
||
## Code | ||
|
||
```rust, ignore | ||
{{#include ../../examples/svg/src/lib.rs}} | ||
``` | ||
|
||
Notice that the `main` of this example takes an optional string. This allows us | ||
to pass the id of an element that we'd like to append our list/parent component | ||
to. This allows us to load the example on the page right here. | ||
|
||
## Example | ||
|
||
<div id="app_example"></div> | ||
<script type="module"> | ||
import init, { main } from '{{cookbookroot}}/examples/svg/pkg/svg.js'; | ||
window.addEventListener('load', async () => { | ||
await init(); | ||
await main("app_example"); | ||
}); | ||
</script> | ||
|
||
|
||
{{#include reflinks.md}} |
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,6 +1,6 @@ | ||
[package] | ||
name = "mogwai-html-macro" | ||
version = "0.2.1" | ||
version = "0.2.2" | ||
authors = ["Schell Scivally <[email protected]>"] | ||
edition = "2018" | ||
readme = "README.md" | ||
|
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/target | ||
**/*.rs.bk | ||
/pkg |
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
[package] | ||
name = "svg" | ||
version = "0.0.0" | ||
authors = ["Schell Scivally <[email protected]>"] | ||
edition = "2018" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[features] | ||
default = ["console_error_panic_hook"] | ||
|
||
[dependencies] | ||
console_log = "^0.1" | ||
log = "^0.4" | ||
serde = { version = "^1.0", features = ["derive"] } | ||
serde_json = "^1.0" | ||
wasm-bindgen = "^0.2" | ||
|
||
# The `console_error_panic_hook` crate provides better debugging of panics by | ||
# logging them with `console.error`. This is great for development, but requires | ||
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for | ||
# code size when deploying. | ||
console_error_panic_hook = { version = "0.1.6", optional = true } | ||
|
||
# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size | ||
# compared to the default allocator's ~10K. It is slower than the default | ||
# allocator, however. | ||
# | ||
# Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now. | ||
wee_alloc = { version = "0.4.2", optional = true } | ||
|
||
[dependencies.mogwai] | ||
version = "^0.3" | ||
path = "../../mogwai" | ||
|
||
[dependencies.web-sys] | ||
version = "^0.3" | ||
# Add more web-sys API's as you need them | ||
features = [ | ||
"HtmlInputElement", | ||
] | ||
|
||
[dev-dependencies] | ||
wasm-bindgen-test = "0.2" | ||
|
||
[profile.release] | ||
# Tell `rustc` to optimize for small code size. | ||
opt-level = "s" |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>svg</title> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module"> | ||
import init, { main } from './pkg/svg.js'; | ||
window.addEventListener('load', async () => { | ||
await init(); | ||
await main("app"); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#![allow(unused_braces)] | ||
use log::Level; | ||
use mogwai::prelude::*; | ||
use std::panic; | ||
use wasm_bindgen::prelude::*; | ||
|
||
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global | ||
// allocator. | ||
#[cfg(feature = "wee_alloc")] | ||
#[global_allocator] | ||
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; | ||
|
||
/// Create an SVG circle using the xmlns attribute and the SVG namespace. | ||
fn my_circle() -> ViewBuilder<HtmlElement> { | ||
let ns = "http://www.w3.org/2000/svg"; | ||
builder! { | ||
<svg xmlns=ns width="100" height="100"> | ||
<circle xmlns=ns | ||
cx="50" | ||
cy="50" | ||
r="40" | ||
stroke="green" | ||
stroke-width="4" | ||
fill="yellow" /> | ||
</svg> | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn main(parent_id: Option<String>) -> Result<(), JsValue> { | ||
panic::set_hook(Box::new(console_error_panic_hook::hook)); | ||
console_log::init_with_level(Level::Trace).unwrap(); | ||
|
||
let view = View::from(my_circle()); | ||
|
||
if let Some(id) = parent_id { | ||
let parent = utils::document() | ||
.get_element_by_id(&id) | ||
.unwrap(); | ||
view.run_in_container(&parent) | ||
} else { | ||
view.run() | ||
} | ||
} |
Empty file.
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,6 +1,6 @@ | ||
[package] | ||
name = "mogwai" | ||
version = "0.3.5" | ||
version = "0.3.6" | ||
authors = ["Schell Scivally <[email protected]>"] | ||
edition = "2018" | ||
license = "MIT" | ||
|
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
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
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