Skip to main content

ShaderBinding

Struct ShaderBinding 

Source
pub struct ShaderBinding {
    pub handle: ShaderHandle,
    pub uniforms: UniformBlock,
}
Expand description

A shader handle plus the uniforms to bind for one draw.

Fields§

§handle: ShaderHandle§uniforms: UniformBlock

Implementations§

Source§

impl ShaderBinding

Source

pub fn stock(shader: StockShader) -> Self

Source

pub fn custom(name: &'static str) -> Self

Examples found in repository?
examples/custom_shader.rs (line 24)
22fn gradient_button(label: &str, top: Color, bottom: Color, radius: f32) -> El {
23    button(label).text_color(tokens::PRIMARY_FOREGROUND).shader(
24        ShaderBinding::custom("gradient")
25            .color("vec_a", top)
26            .color("vec_b", bottom)
27            .f32("vec_c", radius),
28    )
29}
More examples
Hide additional examples
examples/custom_paint.rs (line 60)
44fn graph_cell(lane: u8, selected: bool) -> El {
45    let lane_color = lane_palette(lane);
46    let ring_color = if selected {
47        Color::srgb_u8(245, 245, 250)
48    } else {
49        lane_color
50    };
51    let ring_w = if selected { 2.5 } else { 1.5 };
52    let radius = 5.0;
53    let line_w = 2.0;
54    let lane_frac = (lane as f32 + 0.5) / LANE_COUNT as f32;
55
56    El::new(Kind::Custom("graph_cell"))
57        .width(Size::Fixed(GRAPH_WIDTH))
58        .height(Size::Fixed(ROW_HEIGHT))
59        .shader(
60            ShaderBinding::custom("commit_node")
61                .color("vec_a", tokens::BACKGROUND)
62                .color("vec_b", ring_color)
63                .vec4("vec_c", [radius, ring_w, line_w, lane_frac]),
64        )
65        .fill(lane_color)
66}
Source

pub fn with(self, key: &'static str, value: UniformValue) -> Self

Source

pub fn set(&mut self, key: &'static str, value: UniformValue)

Source

pub fn color(self, key: &'static str, c: Color) -> Self

Examples found in repository?
examples/custom_shader.rs (line 25)
22fn gradient_button(label: &str, top: Color, bottom: Color, radius: f32) -> El {
23    button(label).text_color(tokens::PRIMARY_FOREGROUND).shader(
24        ShaderBinding::custom("gradient")
25            .color("vec_a", top)
26            .color("vec_b", bottom)
27            .f32("vec_c", radius),
28    )
29}
More examples
Hide additional examples
examples/custom_paint.rs (line 61)
44fn graph_cell(lane: u8, selected: bool) -> El {
45    let lane_color = lane_palette(lane);
46    let ring_color = if selected {
47        Color::srgb_u8(245, 245, 250)
48    } else {
49        lane_color
50    };
51    let ring_w = if selected { 2.5 } else { 1.5 };
52    let radius = 5.0;
53    let line_w = 2.0;
54    let lane_frac = (lane as f32 + 0.5) / LANE_COUNT as f32;
55
56    El::new(Kind::Custom("graph_cell"))
57        .width(Size::Fixed(GRAPH_WIDTH))
58        .height(Size::Fixed(ROW_HEIGHT))
59        .shader(
60            ShaderBinding::custom("commit_node")
61                .color("vec_a", tokens::BACKGROUND)
62                .color("vec_b", ring_color)
63                .vec4("vec_c", [radius, ring_w, line_w, lane_frac]),
64        )
65        .fill(lane_color)
66}
Source

pub fn f32(self, key: &'static str, v: f32) -> Self

Examples found in repository?
examples/custom_shader.rs (line 27)
22fn gradient_button(label: &str, top: Color, bottom: Color, radius: f32) -> El {
23    button(label).text_color(tokens::PRIMARY_FOREGROUND).shader(
24        ShaderBinding::custom("gradient")
25            .color("vec_a", top)
26            .color("vec_b", bottom)
27            .f32("vec_c", radius),
28    )
29}
Source

pub fn vec4(self, key: &'static str, v: [f32; 4]) -> Self

Examples found in repository?
examples/custom_paint.rs (line 63)
44fn graph_cell(lane: u8, selected: bool) -> El {
45    let lane_color = lane_palette(lane);
46    let ring_color = if selected {
47        Color::srgb_u8(245, 245, 250)
48    } else {
49        lane_color
50    };
51    let ring_w = if selected { 2.5 } else { 1.5 };
52    let radius = 5.0;
53    let line_w = 2.0;
54    let lane_frac = (lane as f32 + 0.5) / LANE_COUNT as f32;
55
56    El::new(Kind::Custom("graph_cell"))
57        .width(Size::Fixed(GRAPH_WIDTH))
58        .height(Size::Fixed(ROW_HEIGHT))
59        .shader(
60            ShaderBinding::custom("commit_node")
61                .color("vec_a", tokens::BACKGROUND)
62                .color("vec_b", ring_color)
63                .vec4("vec_c", [radius, ring_w, line_w, lane_frac]),
64        )
65        .fill(lane_color)
66}

Trait Implementations§

Source§

impl Clone for ShaderBinding

Source§

fn clone(&self) -> ShaderBinding

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ShaderBinding

Source§

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

Formats the value using the given formatter. Read more

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

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
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> ToOwned for T
where T: Clone,

Source§

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

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.