pub struct Polygon<R: Runtime> {
pub app_handle: AppHandle<R>,
/* private fields */
}Expand description
Access to the Polygon APIs.
Fields§
§app_handle: AppHandle<R>Implementations§
Source§impl<R: Runtime> Polygon<R>
impl<R: Runtime> Polygon<R>
Sourcepub fn register(&self, id: &str) -> Result<()>
pub fn register(&self, id: &str) -> Result<()>
Register a default polygon with given id.
Frequent calls to this function may cause performance issues.
It is recommended to use register_all to register multiple polygons at once.
§Errors
This function will return an error if the id provided has already been registered.
§Example
// backend with rust
app.polygon().register("my-polygon")?;// frontend with js
import { register } from 'tauri-plugin-polygon-api';
await register('my-polygon');Sourcepub fn register_all<S: AsRef<str> + Debug>(&self, ids: Vec<S>) -> Result<()>
pub fn register_all<S: AsRef<str> + Debug>(&self, ids: Vec<S>) -> Result<()>
Register multiple polygons.
§Errors
This function will not return errors even if the id provided has already been registered.
§Example
// backend with rust
app.polygon().register(Vec::from(["my-polygon", "another-polygon"]))?;// frontend with js
import { registerAll } from 'tauri-plugin-polygon-api';
await registerAll(['my-polygon', 'another-polygon']);Sourcepub fn remove(&self, id: &str) -> Result<()>
pub fn remove(&self, id: &str) -> Result<()>
Remove a polygon physically.
After this function call ends, the specified polygon will be deleted physically, and needs to be re-registered before it can be used again.
Frequent calls to this function may cause performance issues.
It is recommended to use hide to disable the polygon logically.
§Errors
This function will return an error if the id provided can not be found.
§Example
// backend with rust
app.polygon().remove("my-polygon")?;// frontend with js
import { remove } from 'tauri-plugin-polygon-api';
await remove('my-polygon');Sourcepub fn update(&self, id: &str, points: Vec<(f64, f64)>) -> Result<()>
pub fn update(&self, id: &str, points: Vec<(f64, f64)>) -> Result<()>
Update vertices of the polygon by given id. Within these points, mouse events will not go through.
§Notice
- All positions should be converted to a
percentage based on the screen width. Position from 0 to 1, 0.1 means 10% of thescreen width. - At least
3points are required. - The order in which you define the points matters and can result in different shapes.
§Errors
This function will return an error if the id provided can not be found.
§Example
// backend with rust
app.polygon().update("my-polygon", vec![(0.0, 0.0), (0.1, 0.0), (0.1, 0.1), (0.0, 0.1)])?;// frontend with js
import { update } from 'tauri-plugin-polygon-api';
await update('my-polygon', {
id: "EXAMPLE",
polygon: [
[0, 0],
[0.1, 0],
[0.1, 0.1],
[0, 0.1]
]
})