[−][src]Struct wasm_svg_graphics::renderer::Renderer
Container object used to interact with the SVG Object Keeps track of definitions and dom root id
Methods
impl Renderer
[src]
pub fn new(dom_root_id: &str) -> Result<Renderer, RendererError>
[src]
Create new renderer object
Arguments
dom_root_id
- The HTMl Attribute ID of the parent element of to be created SVG
pub fn render(&mut self, figure: &Figure, location: &Point)
[src]
Render figure at a location (this will automatically add a definition when needed)
Arguments
figure
- Figure object, used when adding to the domlocation
- the location where to add thefigure
Examples
use wasm_svg_graphics::figures; use geom_2d::point::Point; use wasm_svg_graphics::renderer::Renderer; // Declare renderer (must be mutable) let mut renderer = Renderer::new("svg_parent_id") .expect("Failed to create renderer!"); // Generate circle let circle = figures::preset::circle(10); // Render circle (since it's the first time of rendering this shape, // the renderer will add the shape's definition) renderer.render(&circle, &Point::new(20, 20));
pub fn render_named(&mut self, name: &str, figure: &Figure, location: &Point)
[src]
Render a named figure at a location (this will automatically add a definition when needed) One can use named-figures for later adjustments, e.g. updating the location of the figure, hiding/showing the figure
Arguments
name
- Name to use for later referencefigure
- Figure object, used when adding to the domlocation
- the location where to add thefigure
Panics
Cannot create duplicate names or declare a name more than once. When an attempt is made to declare a name more than once, a panic will occur. One is able to check if a name already exists with the does_name_exist method.
Examples
use wasm_svg_graphics::figures; use geom_2d::point::Point; use wasm_svg_graphics::renderer::Renderer; // Declare renderer (must be mutable) let mut renderer = Renderer::new("svg_parent_id") .expect("Failed to create renderer!"); // Generate circle let circle = figures::preset::circle(10); // Render circle (since it's the first time of rendering this shape, // the renderer will add the shape's definition) renderer.render_named("named_circle", &circle, &Point::new(10, 10)); // --snip // Updates the named figure's location to (20,20) renderer.update_named("named_circle", &circle, &Point::new(20, 20));
pub fn clear(&mut self)
[src]
Clears all elements within the SVG element and clears all internal definitions. Basically reinits the renderer.
Examples
use wasm_svg_graphics::figures; use geom_2d::point::Point; use wasm_svg_graphics::renderer::Renderer; // Declare renderer (must be mutable) let mut renderer = Renderer::new("svg_parent_id") .expect("Failed to create renderer!"); // Generate circle let circle = figures::preset::circle(10); // Render circle (since it's the first time of rendering this shape, // the renderer will add the shape's definition) renderer.render_named("named_circle", &circle, &Point::new(10, 10)); // --snip // Reinit the Renderer object renderer.clear(); // Renders the circle with "named_circle" name again. // This would normally panic, since a name is redeclared, // but since the renderer is cleared, it will not. :) renderer.render_named("named_circle", &circle, &Point::new(20, 20));
pub fn clear_named_container(&self, container_name: &str)
[src]
Clears all figures/containers within a named container, but does not clear up definitions.
Arguments
container_name
- The name of the container to clear
Panics
Will panic when a name passed in is in use by a pure figure. For pure figures use delete_named or hide_named instead.
Note
Most of the time the update_named method is a better alternative.
Examples
use wasm_svg_graphics::figures; use geom_2d::point::Point; use wasm_svg_graphics::renderer::Renderer; // Declare renderer (must be mutable) let mut renderer = Renderer::new("svg_parent_id") .expect("Failed to create renderer!"); // Generate circle let circle = figures::preset::circle(10); // Adds the named container 'named_container' to the svg root renderer.create_named_container("named_container", "root"); // Render circle (since it's the first time of rendering this shape, // the renderer will add the shape's definition) renderer.append_to_container("named_container", &circle, &Point::new(10, 10)); // Now the container contains the circle figure // --snip // Clear the named container renderer.clear_named_container("named_container"); // Now the container is empty again // Render circle in the named_container. // Since definitions were not cleared, it will use a previous definition. // This saves some processing time in this case. renderer.append_to_container("named_container", &circle, &Point::new(20, 20)); // Now the container contains the circle at a different position
pub fn update_named(&mut self, name: &str, figure: &Figure, location: &Point)
[src]
Updates a named container or figure to either contain the passed figure or become the passed figure, respectively.
Arguments
name
- The name of either a named container or a named figurefigure
- Figure object, used when adding to the domlocation
- the location where to add thefigure
Examples
use wasm_svg_graphics::figures; use geom_2d::point::Point; use wasm_svg_graphics::renderer::Renderer; // Declare renderer (must be mutable) let mut renderer = Renderer::new("svg_parent_id") .expect("Failed to create renderer!"); // Generate circle let circle = figures::preset::circle(10); // Adds the named container 'named_container' to the svg root renderer.create_named_container("named_container", "root"); // Render circle (since it's the first time of rendering this shape, // the renderer will add the shape's definition) renderer.append_to_container("named_container", &circle, &Point::new(10, 10)); // Now the container contains the circle figure // --snip // Update the contents of the named container renderer.update_named("named_container", &circle, &Point::new(20, 20)); // Now the container contains the circle at a different position
pub fn hide_named(&self, name: &str)
[src]
Hides a named item in the DOM, this can be undone by the show_named method.
Arguments
name
- Name of item to hide
Examples
use wasm_svg_graphics::figures; use geom_2d::point::Point; use wasm_svg_graphics::renderer::Renderer; // Declare renderer (must be mutable) let mut renderer = Renderer::new("svg_parent_id") .expect("Failed to create renderer!"); // Generate circle let circle = figures::preset::circle(10); // Render circle (since it's the first time of rendering this shape, // the renderer will add the shape's definition) renderer.render_named("named_circle", &circle, &Point::new(10, 10)); // --snip // Hides the named figure renderer.hide_named("named_circle");
pub fn show_named(&self, name: &str)
[src]
Shows a named item in the DOM, this undoes the hide_named method.
Arguments
name
- Name of item to show
Examples
use wasm_svg_graphics::figures; use geom_2d::point::Point; use wasm_svg_graphics::renderer::Renderer; // Declare renderer (must be mutable) let mut renderer = Renderer::new("svg_parent_id") .expect("Failed to create renderer!"); // Generate circle let circle = figures::preset::circle(10); // Render circle (since it's the first time of rendering this shape, // the renderer will add the shape's definition) renderer.render_named("named_circle", &circle, &Point::new(10, 10)); // Hides the named figure renderer.hide_named("named_circle"); // --snip // Show the named figure again renderer.show_named("named_circle");
pub fn append_to_container(
&mut self,
name: &str,
figure: &Figure,
location: &Point
)
[src]
&mut self,
name: &str,
figure: &Figure,
location: &Point
)
Appends a figure to a named container
Arguments
name
- The name of either a named containerfigure
- Figure object, used when adding to the domlocation
- the location where to add thefigure
Panics
Will panic when a name passed in is in use by a pure figure.
Examples
use wasm_svg_graphics::figures; use geom_2d::point::Point; use wasm_svg_graphics::renderer::Renderer; // Declare renderer (must be mutable) let mut renderer = Renderer::new("svg_parent_id") .expect("Failed to create renderer!"); // Generate circle let circle = figures::preset::circle(10); // Adds the named container 'named_container' to the svg root renderer.create_named_container("named_container", "root"); // Render circle (since it's the first time of rendering this shape, // the renderer will add the shape's definition) renderer.append_to_container("named_container", &circle, &Point::new(10, 10)); // Now the container contains the circle figure
pub fn delete_named(&mut self, name: &str)
[src]
Deletes a named item from the DOM and from internal entries. But will not delete definitions
Arguments
name
- Name of item to delete
Examples
use wasm_svg_graphics::figures; use geom_2d::point::Point; use wasm_svg_graphics::renderer::Renderer; // Declare renderer (must be mutable) let mut renderer = Renderer::new("svg_parent_id") .expect("Failed to create renderer!"); // Generate circle let circle = figures::preset::circle(10); // Render circle (since it's the first time of rendering this shape, // the renderer will add the shape's definition) renderer.render_named("named_circle", &circle, &Point::new(10, 10)); // --snip // Delete the named figure renderer.delete_named("named_circle"); // Renders the circle with "named_circle" name again. // This would normally panic, since a name is redeclared, // but since the named figure is deleted, it will not. :) renderer.render_named("named_circle", &circle, &Point::new(20, 20));
pub fn does_name_exist(&self, name: &str) -> bool
[src]
Will return if a certain name exists and therefore cannot be used for a declaration.
Arguments
- 'name' - Name to check
Examples
use wasm_svg_graphics::figures; use geom_2d::point::Point; use wasm_svg_graphics::renderer::Renderer; // Declare renderer (must be mutable) let mut renderer = Renderer::new("svg_parent_id") .expect("Failed to create renderer!"); // Generate circle let circle = figures::preset::circle(10); // Will be set to false let does_named_circle_exist = renderer.does_name_exist("named_circle"); // Render circle (since it's the first time of rendering this shape, // the renderer will add the shape's definition) renderer.render_named("named_circle", &circle, &Point::new(10, 10)); // Will be set to true let does_named_circle_exist = renderer.does_name_exist("named_circle"); // Delete the named figure renderer.delete_named("named_circle"); // Will be set to false let does_named_circle_exist = renderer.does_name_exist("named_circle"); // Renders the circle with "named_circle" name again. // This would normally panic, since a name is redeclared, // but since the named figure is deleted, it will not. :) renderer.render_named("named_circle", &circle, &Point::new(20, 20)); // Will be set to true let does_named_circle_exist = renderer.does_name_exist("named_circle");
pub fn create_named_container(&mut self, name: &str, parent: &str)
[src]
Creates a new named container in the parent
Arguments
name
- Name of the named container used for later referenceparent
- Name a container, which to use as parent ("root" is used for the SVG root)
Examples
use wasm_svg_graphics::figures; use geom_2d::point::Point; use wasm_svg_graphics::renderer::Renderer; // Declare renderer (must be mutable) let mut renderer = Renderer::new("svg_parent_id") .expect("Failed to create renderer!"); // Generate circle let circle = figures::preset::circle(10); // Adds the named container 'named_container' to the svg root renderer.create_named_container("named_container", "root"); // Render circle (since it's the first time of rendering this shape, // the renderer will add the shape's definition) renderer.append_to_container("named_container", &circle, &Point::new(10, 10));
pub fn is_container(&self, name: &str) -> bool
[src]
Will return whether a given name is used for a named container, instead of a pure figure
Arguments
name
- Name to check
Note
Will output false if the name is not in use
Examples
use wasm_svg_graphics::figures; use geom_2d::point::Point; use wasm_svg_graphics::renderer::Renderer; // Declare renderer (must be mutable) let mut renderer = Renderer::new("svg_parent_id") .expect("Failed to create renderer!"); // Generate circle let circle = figures::preset::circle(10); // Render circle (since it's the first time of rendering this shape, // the renderer will add the shape's definition) renderer.render_named("named_circle", &circle, &Point::new(10, 10)); // Create a named container renderer.create_named_container("named_container", "root"); println!("{}", renderer.is_container("named_circle")); // false println!("{}", renderer.is_container("named_container")); // true println!("{}", renderer.is_container("not_in_use_name")); // false
pub fn adjust_viewbox(&self, x: i32, y: i32, width: i32, height: i32)
[src]
Adjusts the viewbox of the svg
Arguments
x
- The top-left x-coordinate of the viewboxy
- The top-left y-coordinate of the viewboxwidth
- The width of the viewboxheight
- The height of the viewbox
Note
By default this is set to DEFAULT_VIEWBOX.
Examples
use wasm_svg_graphics::figures; use geom_2d::point::Point; use wasm_svg_graphics::renderer::Renderer; // Declare renderer (must be mutable) let mut renderer = Renderer::new("svg_parent_id") .expect("Failed to create renderer!"); // Adjust the viewbox renderer.adjust_viewbox(0, 0, 50, 50);
Auto Trait Implementations
impl RefUnwindSafe for Renderer
impl Send for Renderer
impl Sync for Renderer
impl Unpin for Renderer
impl UnwindSafe for Renderer
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,