UiTextureBuilder

Struct UiTextureBuilder 

Source
pub struct UiTextureBuilder<'a> { /* private fields */ }
Expand description

Builder for UiTexture.

Implementations§

Source§

impl<'a> UiTextureBuilder<'a>

Source

pub fn position(self, value: (f32, f32)) -> Self

Examples found in repository?
examples/hello.rs (line 51)
15fn main() {
16    let display = glutin::WindowBuilder::new()
17        .with_dimensions(640, 640)
18        .with_vsync()
19        .build_glium()
20        .unwrap();
21
22    let mut ui = Ui::new(&display);
23
24    let font =
25        FontTexture::new(&display, FONT_RAW, 50, FontTexture::ascii_character_list()).unwrap();
26
27    let text_display = ui.build_text_display(&font, "hello");
28
29    let mut text = UiTextBuilder::default()
30        .position((0.1, 0.1))
31        .size((0.15, 0.1))
32        .text(text_display)
33        .color((0.1, 0.1, 0.1, 1.0))
34        .build()
35        .unwrap();
36
37    let mut button1 = UiButtonBuilder::default()
38        .position((0.1, 0.1))
39        .size((0.15, 0.1))
40        .build()
41        .unwrap();
42
43    let mut button2 = UiButtonBuilder::default()
44        .position((0.5, 0.5))
45        .size((0.3, 0.3))
46        .build()
47        .unwrap();
48
49    let texture = SimpleTexture::from(&KNOB_BASE_WHITE_RAW, ImageFormat::PNG, &display).unwrap();
50    let knob_base = UiTextureBuilder::default()
51        .position((0.5, 0.5))
52        .size((0.3, 0.3))
53        .rotation(0.0)
54        .texture(&texture)
55        .build()
56        .unwrap();
57
58    let texture = SimpleTexture::from(&KNOB_LIGHT_RAW, ImageFormat::PNG, &display).unwrap();
59    let mut knob_light = UiTextureBuilder::default()
60        .position((0.5, 0.5))
61        .size((0.3, 0.3))
62        .rotation(0.0)
63        .texture(&texture)
64        .build()
65        .unwrap();
66
67    loop {
68        ui.update(|target, mouse, system| {
69            button1.update(&mouse);
70            button2.update(&mouse);
71
72            target.clear_color(0.4, 0.4, 0.4, 1.0);
73
74            match *button1.left() {
75                ButtonState::Pressed(_x, _y) => {
76                    text.set_text("world");
77                    text.color.0 += mouse.delta_position().0 * 2.55;
78                    text.color.1 += mouse.delta_position().1 * 2.55;
79                }
80                _ => {
81                    text.set_text("hello");
82                }
83            }
84            match *button1.right() {
85                ButtonState::Pressed(_x, _y) => {
86                    text.set_text("MOVE!");
87                    text.position.0 += mouse.delta_position().0 * 5.0;
88                    text.position.1 += mouse.delta_position().1 * 5.0;
89                    button1.position.0 += mouse.delta_position().0 * 5.0;
90                    button1.position.1 += mouse.delta_position().1 * 5.0;
91                }
92                _ => {
93                    text.set_text("hello");
94                }
95            }
96
97            match *button2.left() {
98                ButtonState::Pressed(_x, _y) => {
99                    knob_light.rotation += mouse.delta_position().1 * 360.0;
100                }
101                _ => (),
102            }
103            match *button2.right() {
104                ButtonState::Pressed(_x, _y) => {
105                    knob_light.rotation += mouse.delta_position().1 * 360.0 * 2.0;
106                }
107                _ => (),
108            }
109
110            text.draw(target, system);
111            knob_base.draw(target, system);
112            knob_light.draw(target, system);
113        });
114    }
115}
Source

pub fn size(self, value: (f32, f32)) -> Self

Examples found in repository?
examples/hello.rs (line 52)
15fn main() {
16    let display = glutin::WindowBuilder::new()
17        .with_dimensions(640, 640)
18        .with_vsync()
19        .build_glium()
20        .unwrap();
21
22    let mut ui = Ui::new(&display);
23
24    let font =
25        FontTexture::new(&display, FONT_RAW, 50, FontTexture::ascii_character_list()).unwrap();
26
27    let text_display = ui.build_text_display(&font, "hello");
28
29    let mut text = UiTextBuilder::default()
30        .position((0.1, 0.1))
31        .size((0.15, 0.1))
32        .text(text_display)
33        .color((0.1, 0.1, 0.1, 1.0))
34        .build()
35        .unwrap();
36
37    let mut button1 = UiButtonBuilder::default()
38        .position((0.1, 0.1))
39        .size((0.15, 0.1))
40        .build()
41        .unwrap();
42
43    let mut button2 = UiButtonBuilder::default()
44        .position((0.5, 0.5))
45        .size((0.3, 0.3))
46        .build()
47        .unwrap();
48
49    let texture = SimpleTexture::from(&KNOB_BASE_WHITE_RAW, ImageFormat::PNG, &display).unwrap();
50    let knob_base = UiTextureBuilder::default()
51        .position((0.5, 0.5))
52        .size((0.3, 0.3))
53        .rotation(0.0)
54        .texture(&texture)
55        .build()
56        .unwrap();
57
58    let texture = SimpleTexture::from(&KNOB_LIGHT_RAW, ImageFormat::PNG, &display).unwrap();
59    let mut knob_light = UiTextureBuilder::default()
60        .position((0.5, 0.5))
61        .size((0.3, 0.3))
62        .rotation(0.0)
63        .texture(&texture)
64        .build()
65        .unwrap();
66
67    loop {
68        ui.update(|target, mouse, system| {
69            button1.update(&mouse);
70            button2.update(&mouse);
71
72            target.clear_color(0.4, 0.4, 0.4, 1.0);
73
74            match *button1.left() {
75                ButtonState::Pressed(_x, _y) => {
76                    text.set_text("world");
77                    text.color.0 += mouse.delta_position().0 * 2.55;
78                    text.color.1 += mouse.delta_position().1 * 2.55;
79                }
80                _ => {
81                    text.set_text("hello");
82                }
83            }
84            match *button1.right() {
85                ButtonState::Pressed(_x, _y) => {
86                    text.set_text("MOVE!");
87                    text.position.0 += mouse.delta_position().0 * 5.0;
88                    text.position.1 += mouse.delta_position().1 * 5.0;
89                    button1.position.0 += mouse.delta_position().0 * 5.0;
90                    button1.position.1 += mouse.delta_position().1 * 5.0;
91                }
92                _ => {
93                    text.set_text("hello");
94                }
95            }
96
97            match *button2.left() {
98                ButtonState::Pressed(_x, _y) => {
99                    knob_light.rotation += mouse.delta_position().1 * 360.0;
100                }
101                _ => (),
102            }
103            match *button2.right() {
104                ButtonState::Pressed(_x, _y) => {
105                    knob_light.rotation += mouse.delta_position().1 * 360.0 * 2.0;
106                }
107                _ => (),
108            }
109
110            text.draw(target, system);
111            knob_base.draw(target, system);
112            knob_light.draw(target, system);
113        });
114    }
115}
Source

pub fn rotation(self, value: f32) -> Self

Examples found in repository?
examples/hello.rs (line 53)
15fn main() {
16    let display = glutin::WindowBuilder::new()
17        .with_dimensions(640, 640)
18        .with_vsync()
19        .build_glium()
20        .unwrap();
21
22    let mut ui = Ui::new(&display);
23
24    let font =
25        FontTexture::new(&display, FONT_RAW, 50, FontTexture::ascii_character_list()).unwrap();
26
27    let text_display = ui.build_text_display(&font, "hello");
28
29    let mut text = UiTextBuilder::default()
30        .position((0.1, 0.1))
31        .size((0.15, 0.1))
32        .text(text_display)
33        .color((0.1, 0.1, 0.1, 1.0))
34        .build()
35        .unwrap();
36
37    let mut button1 = UiButtonBuilder::default()
38        .position((0.1, 0.1))
39        .size((0.15, 0.1))
40        .build()
41        .unwrap();
42
43    let mut button2 = UiButtonBuilder::default()
44        .position((0.5, 0.5))
45        .size((0.3, 0.3))
46        .build()
47        .unwrap();
48
49    let texture = SimpleTexture::from(&KNOB_BASE_WHITE_RAW, ImageFormat::PNG, &display).unwrap();
50    let knob_base = UiTextureBuilder::default()
51        .position((0.5, 0.5))
52        .size((0.3, 0.3))
53        .rotation(0.0)
54        .texture(&texture)
55        .build()
56        .unwrap();
57
58    let texture = SimpleTexture::from(&KNOB_LIGHT_RAW, ImageFormat::PNG, &display).unwrap();
59    let mut knob_light = UiTextureBuilder::default()
60        .position((0.5, 0.5))
61        .size((0.3, 0.3))
62        .rotation(0.0)
63        .texture(&texture)
64        .build()
65        .unwrap();
66
67    loop {
68        ui.update(|target, mouse, system| {
69            button1.update(&mouse);
70            button2.update(&mouse);
71
72            target.clear_color(0.4, 0.4, 0.4, 1.0);
73
74            match *button1.left() {
75                ButtonState::Pressed(_x, _y) => {
76                    text.set_text("world");
77                    text.color.0 += mouse.delta_position().0 * 2.55;
78                    text.color.1 += mouse.delta_position().1 * 2.55;
79                }
80                _ => {
81                    text.set_text("hello");
82                }
83            }
84            match *button1.right() {
85                ButtonState::Pressed(_x, _y) => {
86                    text.set_text("MOVE!");
87                    text.position.0 += mouse.delta_position().0 * 5.0;
88                    text.position.1 += mouse.delta_position().1 * 5.0;
89                    button1.position.0 += mouse.delta_position().0 * 5.0;
90                    button1.position.1 += mouse.delta_position().1 * 5.0;
91                }
92                _ => {
93                    text.set_text("hello");
94                }
95            }
96
97            match *button2.left() {
98                ButtonState::Pressed(_x, _y) => {
99                    knob_light.rotation += mouse.delta_position().1 * 360.0;
100                }
101                _ => (),
102            }
103            match *button2.right() {
104                ButtonState::Pressed(_x, _y) => {
105                    knob_light.rotation += mouse.delta_position().1 * 360.0 * 2.0;
106                }
107                _ => (),
108            }
109
110            text.draw(target, system);
111            knob_base.draw(target, system);
112            knob_light.draw(target, system);
113        });
114    }
115}
Source

pub fn texture(self, value: &'a SimpleTexture) -> Self

Examples found in repository?
examples/hello.rs (line 54)
15fn main() {
16    let display = glutin::WindowBuilder::new()
17        .with_dimensions(640, 640)
18        .with_vsync()
19        .build_glium()
20        .unwrap();
21
22    let mut ui = Ui::new(&display);
23
24    let font =
25        FontTexture::new(&display, FONT_RAW, 50, FontTexture::ascii_character_list()).unwrap();
26
27    let text_display = ui.build_text_display(&font, "hello");
28
29    let mut text = UiTextBuilder::default()
30        .position((0.1, 0.1))
31        .size((0.15, 0.1))
32        .text(text_display)
33        .color((0.1, 0.1, 0.1, 1.0))
34        .build()
35        .unwrap();
36
37    let mut button1 = UiButtonBuilder::default()
38        .position((0.1, 0.1))
39        .size((0.15, 0.1))
40        .build()
41        .unwrap();
42
43    let mut button2 = UiButtonBuilder::default()
44        .position((0.5, 0.5))
45        .size((0.3, 0.3))
46        .build()
47        .unwrap();
48
49    let texture = SimpleTexture::from(&KNOB_BASE_WHITE_RAW, ImageFormat::PNG, &display).unwrap();
50    let knob_base = UiTextureBuilder::default()
51        .position((0.5, 0.5))
52        .size((0.3, 0.3))
53        .rotation(0.0)
54        .texture(&texture)
55        .build()
56        .unwrap();
57
58    let texture = SimpleTexture::from(&KNOB_LIGHT_RAW, ImageFormat::PNG, &display).unwrap();
59    let mut knob_light = UiTextureBuilder::default()
60        .position((0.5, 0.5))
61        .size((0.3, 0.3))
62        .rotation(0.0)
63        .texture(&texture)
64        .build()
65        .unwrap();
66
67    loop {
68        ui.update(|target, mouse, system| {
69            button1.update(&mouse);
70            button2.update(&mouse);
71
72            target.clear_color(0.4, 0.4, 0.4, 1.0);
73
74            match *button1.left() {
75                ButtonState::Pressed(_x, _y) => {
76                    text.set_text("world");
77                    text.color.0 += mouse.delta_position().0 * 2.55;
78                    text.color.1 += mouse.delta_position().1 * 2.55;
79                }
80                _ => {
81                    text.set_text("hello");
82                }
83            }
84            match *button1.right() {
85                ButtonState::Pressed(_x, _y) => {
86                    text.set_text("MOVE!");
87                    text.position.0 += mouse.delta_position().0 * 5.0;
88                    text.position.1 += mouse.delta_position().1 * 5.0;
89                    button1.position.0 += mouse.delta_position().0 * 5.0;
90                    button1.position.1 += mouse.delta_position().1 * 5.0;
91                }
92                _ => {
93                    text.set_text("hello");
94                }
95            }
96
97            match *button2.left() {
98                ButtonState::Pressed(_x, _y) => {
99                    knob_light.rotation += mouse.delta_position().1 * 360.0;
100                }
101                _ => (),
102            }
103            match *button2.right() {
104                ButtonState::Pressed(_x, _y) => {
105                    knob_light.rotation += mouse.delta_position().1 * 360.0 * 2.0;
106                }
107                _ => (),
108            }
109
110            text.draw(target, system);
111            knob_base.draw(target, system);
112            knob_light.draw(target, system);
113        });
114    }
115}
Source

pub fn build(self) -> Result<UiTexture<'a>, String>

Builds a new UiTexture.

§Errors

If a required field has not been initialized.

Examples found in repository?
examples/hello.rs (line 55)
15fn main() {
16    let display = glutin::WindowBuilder::new()
17        .with_dimensions(640, 640)
18        .with_vsync()
19        .build_glium()
20        .unwrap();
21
22    let mut ui = Ui::new(&display);
23
24    let font =
25        FontTexture::new(&display, FONT_RAW, 50, FontTexture::ascii_character_list()).unwrap();
26
27    let text_display = ui.build_text_display(&font, "hello");
28
29    let mut text = UiTextBuilder::default()
30        .position((0.1, 0.1))
31        .size((0.15, 0.1))
32        .text(text_display)
33        .color((0.1, 0.1, 0.1, 1.0))
34        .build()
35        .unwrap();
36
37    let mut button1 = UiButtonBuilder::default()
38        .position((0.1, 0.1))
39        .size((0.15, 0.1))
40        .build()
41        .unwrap();
42
43    let mut button2 = UiButtonBuilder::default()
44        .position((0.5, 0.5))
45        .size((0.3, 0.3))
46        .build()
47        .unwrap();
48
49    let texture = SimpleTexture::from(&KNOB_BASE_WHITE_RAW, ImageFormat::PNG, &display).unwrap();
50    let knob_base = UiTextureBuilder::default()
51        .position((0.5, 0.5))
52        .size((0.3, 0.3))
53        .rotation(0.0)
54        .texture(&texture)
55        .build()
56        .unwrap();
57
58    let texture = SimpleTexture::from(&KNOB_LIGHT_RAW, ImageFormat::PNG, &display).unwrap();
59    let mut knob_light = UiTextureBuilder::default()
60        .position((0.5, 0.5))
61        .size((0.3, 0.3))
62        .rotation(0.0)
63        .texture(&texture)
64        .build()
65        .unwrap();
66
67    loop {
68        ui.update(|target, mouse, system| {
69            button1.update(&mouse);
70            button2.update(&mouse);
71
72            target.clear_color(0.4, 0.4, 0.4, 1.0);
73
74            match *button1.left() {
75                ButtonState::Pressed(_x, _y) => {
76                    text.set_text("world");
77                    text.color.0 += mouse.delta_position().0 * 2.55;
78                    text.color.1 += mouse.delta_position().1 * 2.55;
79                }
80                _ => {
81                    text.set_text("hello");
82                }
83            }
84            match *button1.right() {
85                ButtonState::Pressed(_x, _y) => {
86                    text.set_text("MOVE!");
87                    text.position.0 += mouse.delta_position().0 * 5.0;
88                    text.position.1 += mouse.delta_position().1 * 5.0;
89                    button1.position.0 += mouse.delta_position().0 * 5.0;
90                    button1.position.1 += mouse.delta_position().1 * 5.0;
91                }
92                _ => {
93                    text.set_text("hello");
94                }
95            }
96
97            match *button2.left() {
98                ButtonState::Pressed(_x, _y) => {
99                    knob_light.rotation += mouse.delta_position().1 * 360.0;
100                }
101                _ => (),
102            }
103            match *button2.right() {
104                ButtonState::Pressed(_x, _y) => {
105                    knob_light.rotation += mouse.delta_position().1 * 360.0 * 2.0;
106                }
107                _ => (),
108            }
109
110            text.draw(target, system);
111            knob_base.draw(target, system);
112            knob_light.draw(target, system);
113        });
114    }
115}

Trait Implementations§

Source§

impl<'a> Default for UiTextureBuilder<'a>

Source§

fn default() -> UiTextureBuilder<'a>

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

Auto Trait Implementations§

§

impl<'a> Freeze for UiTextureBuilder<'a>

§

impl<'a> !RefUnwindSafe for UiTextureBuilder<'a>

§

impl<'a> !Send for UiTextureBuilder<'a>

§

impl<'a> !Sync for UiTextureBuilder<'a>

§

impl<'a> Unpin for UiTextureBuilder<'a>

§

impl<'a> !UnwindSafe for UiTextureBuilder<'a>

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

Source§

type Output = T

Should always be Self
Source§

impl<T> SetParameter for T

Source§

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result
where T: Parameter<Self>,

Sets value as a parameter of 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§

unsafe 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 = 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.