Struct widgetry::GeomBatch

source ·
pub struct GeomBatch {
    pub(crate) list: Vec<(Fill, Tessellation, f64)>,
    pub autocrop_dims: bool,
}
Expand description

A mutable builder for a group of colored tessellated polygons.

Fields§

§list: Vec<(Fill, Tessellation, f64)>§autocrop_dims: bool

Implementations§

source§

impl GeomBatch

source

pub fn new() -> GeomBatch

Creates an empty batch.

source

pub fn push<F: Into<Fill>, T: Into<Tessellation>>(&mut self, fill: F, p: T)

Adds a single tessellated polygon, painted according to Fill

source

pub fn push_with_z<F: Into<Fill>, T: Into<Tessellation>>( &mut self, fill: F, p: T, z_offset: f64 )

Offset z value to render above/below other polygons. z must be in (-1, 0] to ensure we don’t traverse layers of the UI - to make sure we don’t inadvertently render something above a tooltip, etc.

source

pub fn unshift<F: Into<Fill>, T: Into<Tessellation>>(&mut self, fill: F, p: T)

Adds a single polygon to the front of the batch, painted according to Fill

source

pub fn shift(&mut self)

Removes the first polygon in the batch.

source

pub fn extend<F: Into<Fill>, T: Into<Tessellation>>( &mut self, fill: F, polys: Vec<T> )

Applies one Fill to many polygons.

source

pub fn append(&mut self, other: GeomBatch)

Appends all colored polygons from another batch to the current one.

source

pub fn consume(self) -> Vec<(Fill, Tessellation, f64)>

Returns the colored polygons in this batch, destroying the batch.

source

pub fn draw(self, g: &mut GfxCtx<'_>)

Draws the batch, consuming it. Only use this for drawing things once.

source

pub fn upload(self, ctx: &EventCtx<'_>) -> Drawable

Upload the batch of polygons to the GPU, returning something that can be cheaply redrawn many times later.

source

pub fn batch(self) -> Widget

Wrap in a Widget for layouting, so this batch can become part of a larger one.

source

pub fn into_widget(self, ctx: &EventCtx<'_>) -> Widget

Wrap in a Widget, so the batch can be drawn as part of a Panel.

source

pub fn get_bounds(&self) -> Bounds

Compute the bounds of all polygons in this batch.

source

pub fn autocrop(self) -> GeomBatch

Sets the top-left to 0, 0. Not sure exactly when this should be used.

source

pub fn is_empty(&self) -> bool

True when the batch is empty.

source

pub fn get_dims(&self) -> ScreenDims

Returns the width and height of all geometry contained in the batch.

source

pub fn load_svg<P: AsRef<Prerender>, I: AsRef<str>>( prerender: &P, filename: I ) -> GeomBatch

Returns a batch containing an SVG from a file.

source

pub fn load_svg_bytes<P: AsRef<Prerender>>( prerender: &P, labeled_bytes: (&str, &[u8]) ) -> GeomBatch

Returns a GeomBatch from the bytes of a utf8 encoded SVG string.

source

pub fn load_svg_bytes_uncached(raw: &[u8]) -> GeomBatch

Returns a GeomBatch from the bytes of a utf8 encoded SVG string.

Prefer to use load_svg_bytes, which caches the parsed SVG, unless the SVG was dynamically generated, or is otherwise unlikely to be reused.

source

pub fn color(self, transformation: RewriteColor) -> GeomBatch

Transforms all colors in a batch.

source

pub fn centered_on(self, center: Pt2D) -> GeomBatch

Translates the batch to be centered on some point.

source

pub fn translate(self, dx: f64, dy: f64) -> GeomBatch

Translates the batch by some offset.

source

pub fn rotate(self, angle: Angle) -> GeomBatch

Rotates each polygon in the batch relative to the center of that polygon.

source

pub fn rotate_around_batch_center(self, angle: Angle) -> GeomBatch

Rotates each polygon in the batch relative to the center of the entire batch.

source

pub fn multi_transform( self, scale: f64, center_on: Pt2D, rotate: Angle ) -> GeomBatch

Equivalent to self.scale(scale).centered_on(center_on).rotate_around_batch_center(rotate), but faster.

source

pub fn scale(self, factor: f64) -> GeomBatch

Scales the batch by some factor.

source

pub fn scale_xy(self, x_factor: f64, y_factor: f64) -> GeomBatch

source

pub fn scale_to_fit_width(self, width: f64) -> GeomBatch

Scales the batch so that the width matches something, preserving aspect ratio.

source

pub fn scale_to_fit_height(self, height: f64) -> GeomBatch

Scales the batch so that the height matches something, preserving aspect ratio.

source

pub fn scale_to_fit_square(self, dims: f64) -> GeomBatch

Scales the batch so that the width and height do not exceed some maximum, preserving aspect ratio.

source

pub fn set_z_offset(self, offset: f64) -> GeomBatch

Overrides the Z-ordering offset for the batch. Must be in (-1, 0], with values closer to -1 rendering on top.

source

pub fn into_geojson(self, gps_bounds: Option<&GPSBounds>) -> Vec<Feature>

Exports the batch to a list of GeoJSON features, labeling each colored triangle. Note the result will be very large and kind of meaningless – individual triangles are returned; any original polygons are lost. Z-values, alpha values from the color, and non-RGB fill patterns are lost. The world-space coordinates are optionally translated back to GPS.

source

pub fn build(self, ctx: &EventCtx<'_>) -> Drawable

Trait Implementations§

source§

impl Clone for GeomBatch

source§

fn clone(&self) -> GeomBatch

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for GeomBatch

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for GeomBatch

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl From<GeomBatch> for ToggleZoomedBuilder

source§

fn from(unzoomed: GeomBatch) -> Self

Converts to this type from the input type.
source§

impl<F: Into<Fill>, T: Into<Tessellation>> From<Vec<(F, T)>> for GeomBatch

source§

fn from(list: Vec<(F, T)>) -> GeomBatch

Creates a batch of filled polygons.

Auto Trait Implementations§

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
§

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

§

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.
§

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.
§

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.
§

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.
§

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

§

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.

§

impl<T> Instrument for T

§

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

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

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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

§

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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

§

fn is_within(&self, b: &G2) -> bool