Skip to main content

State

Struct State 

Source
pub struct State<T>(/* private fields */);

Implementations§

Source§

impl<T: StateTrait> State<T>

Source

pub fn register_surface<V: Vertices, I: Into<SurfaceIndices>>( &mut self, name: impl Into<String>, vertices: V, indices: I, ) -> SurfaceMut<'_, T>

Register a new surface. If an existing one with same number of vertices and same faces exists, previous settings and data are recovered.

See Surface and SurfaceMut for how to add data to the created shape.

Source

pub fn get_surface_mut(&mut self, name: &str) -> Option<SurfaceMut<'_, T>>

Source

pub fn get_surface(&self, name: &str) -> Option<&Surface<T>>

Source

pub fn remove_surface(&mut self, name: &str)

Source

pub fn register_point_cloud<V: Vertices>( &mut self, name: impl Into<String>, positions: V, ) -> PointCloudMut<'_, T>

Register a new point cloud. If an existing one with same number of points exists, previous settings and data are recovered.

See PointCloud and PointCloudMut for how to add data to the created shape.

Source

pub fn get_point_cloud_mut( &mut self, name: &str, ) -> Option<PointCloudMut<'_, T>>

Source

pub fn get_point_cloud(&self, name: &str) -> Option<&PointCloud<T>>

Source

pub fn remove_point_cloud(&mut self, name: &str)

Source

pub fn register_segment<V: Vertices>( &mut self, name: impl Into<String>, positions: V, connections: Vec<[u32; 2]>, ) -> SegmentMut<'_, T>

Register a list of segments. If an existing one with same number of points and same connextions exists, previous settings and data are recovered.

See Segment and SegmentMut for how to add data to the created shape.

Arguments :

  • positions: segments extremities
  • connections: segments denoted by extremities indices
Source

pub fn get_segment_mut(&mut self, name: &str) -> Option<SegmentMut<'_, T>>

Source

pub fn get_segment(&self, name: &str) -> Option<&Segment<T>>

Source

pub fn remove_segment(&mut self, name: &str)

Source

pub fn load_from_state_file(&mut self, path: impl AsRef<Path>) -> Result<(), ()>

Available on crate feature saves and non-WebAssembly only.

Load app state from given file content.

Source

pub fn load_from_state_slice(&mut self, data: &[u8]) -> Result<(), ()>

Available on crate feature saves only.

Load app state from given buffer.

Source

pub fn save_state_file(&self, path: impl AsRef<Path>) -> Result<(), ()>

Available on crate feature saves and non-WebAssembly only.

Save current state in cbor into chosen file.

Source

pub fn save_state_vec(&self) -> Result<Vec<u8>, ()>

Available on crate feature saves only.

Save current state in cbor into buffer.

Source

pub fn get_settings_mut(&mut self) -> &mut Settings

Source

pub fn get_settings(&self) -> &Settings

Source

pub fn set_camera(&mut self, eye: [f32; 3], target: [f32; 3], up: [f32; 3])

Source

pub fn get_camera(&self) -> ([f32; 3], [f32; 3], [f32; 3])

Result is (eye, target, up).

Source§

impl State<InnerBareState>

Source

pub fn run<S: Into<String>>(self, width: u32, height: u32, id: Option<S>)

Show the window and start the app.

In wasm, width and height are ignored and css is used to define the dimensions (allowing for dimensions in % and vh/vw).

Arguments:

  • width: requested width of the app (no effect in wasm)
  • height: requested height of the app (no effect in wasm)
  • id: serves as window title, or id shape to attach to. If None uses "State".
use deuxfleurs::load_mesh;

let (spot_v, spot_f) = load_mesh("examples/assets/spot.obj").await.unwrap();
let mut handle = deuxfleurs::init();
handle.register_surface("Spot", spot_v, spot_f);
let mut handle = handle.run(1920, 1080, Some("deuxfleurs"));
Source

pub fn run_headless(self) -> RunningState

Available on non-WebAssembly only.

Run the app without a window. Allows running the app in environment where no display is available and taking screenshots automatically.

Currently only available on non wasm targets, as webGL requires a context.

use deuxfleurs::load_mesh;

let (spot_v, spot_f) = load_mesh("examples/assets/spot.obj").await.unwrap();
let mut handle = deuxfleurs::init();
handle.register_surface("Spot", spot_v, spot_f);
let mut handle = handle.run_headless();
handle.screenshot();
Source

pub fn run_with_callback<S: Into<String>, U: FnMut(&mut Ui, &mut RunningState)>( self, width: u32, height: u32, id: Option<S>, callback: U, )

Specify a callback that will be called once every frame.

Passes an egui::Ui and a RunningState arguments which can be used to add UI elements and modify state accordingly.

Source§

impl State<InnerGraphicalState>

Source

pub fn resize_scene(&mut self)

Fit camera and ground to match the visible shapes

Source

pub fn screenshot(&mut self)

Take a screenshot of the scene. The screenshot is then saved on disk under the name screenshot_[nnn].png, with nnn incrementing each time.

Source

pub fn screenshot_to_buffer(&mut self) -> Result<Vec<u8>, ()>

Take a screenshot of the scene. The screenshot is then returned as a vector oy bytes, each storing r g b a (in order) values of each pixel.

Should not fail, unless internal buffer storage is messed up.

Source

pub fn get_picked(&self) -> &Option<(String, Picked)>

Get current selected object: first the name, then index i and type of the selected element

Source

pub fn refresh(&mut self)

Politely ask to render the next frame, even if no change is detected

Auto Trait Implementations§

§

impl<T> Freeze for State<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for State<T>
where T: RefUnwindSafe,

§

impl<T> Send for State<T>
where T: Send,

§

impl<T> Sync for State<T>
where T: Sync,

§

impl<T> Unpin for State<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for State<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for State<T>
where T: UnwindSafe,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(value: T, _simd: S) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more