Struct Polygon

Source
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>

Source

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');
Source

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']);
Source

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');
Source

pub fn show(&self, id: &str) -> Result<()>

Enable the polygon by given id.

§Errors

This function will return an error if the id provided can not be found.

§Example
// backend with rust
app.polygon().show("my-polygon")?;
// frontend with js
import { show } from 'tauri-plugin-polygon-api';
await show('my-polygon');
Source

pub fn hide(&self, id: &str) -> Result<()>

Disable the polygon logically by given id.

§Errors

This function will return an error if the id provided can not be found.

§Example
// backend with rust
app.polygon().hide("my-polygon")?;
// frontend with js
import { hide } from 'tauri-plugin-polygon-api';
await hide('my-polygon');
Source

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
  1. All positions should be converted to a percentage based on the screen width. Position from 0 to 1, 0.1 means 10% of the screen width.
  2. At least 3 points are required.
  3. 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]
    ]
})
Source

pub fn clear(&self) -> Result<()>

Clear all polygons physically.

§Example
// backend with rust
app.polygon().clear()?;
// frontend with js
import { clear } from 'tauri-plugin-polygon-api';
await clear();

Auto Trait Implementations§

§

impl<R> !Freeze for Polygon<R>

§

impl<R> !RefUnwindSafe for Polygon<R>

§

impl<R> Send for Polygon<R>

§

impl<R> Sync for Polygon<R>

§

impl<R> Unpin for Polygon<R>

§

impl<R> !UnwindSafe for Polygon<R>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T