Skip to main content

Spinbox

Struct Spinbox 

Source
pub struct Spinbox { /* private fields */ }
Expand description

Numerical entry control which allows users to set any value in a range by typing or incrementing/decrementing.

Implementations§

Source§

impl Spinbox

Source

pub fn show(&mut self)

Source

pub fn hide(&mut self)

Source

pub fn enable(&mut self)

Source

pub fn disable(&mut self)

Source

pub unsafe fn from_raw(uiSpinbox: *mut uiSpinbox) -> Spinbox

Create an ui struct for this control from the raw pointer for it.

§Unsafety

The given pointer must point to a valid control or memory unsafety may result.

Source

pub fn ptr(&self) -> *mut uiSpinbox

Return the underlying pointer for this control.

Source§

impl Spinbox

Source

pub fn new(min: i32, max: i32) -> Self

Examples found in repository?
examples/controlgallery/page2.rs (line 11)
4pub fn make_numbers_page(_ui: UI) -> Control {
5    // Left
6    let mut hbox = HorizontalBox::new();
7    let mut group_numbers = Group::new("Numbers");
8    let mut vbox_numbers = VerticalBox::new();
9    vbox_numbers.set_padded(true);
10
11    let mut spinner = Spinbox::new(0, 100);
12    let mut slider = Slider::new(0, 100);
13    let progressbar = ProgressBar::new();
14
15    spinner.on_changed({
16        let mut slider = slider.clone();
17        let mut progressbar = progressbar.clone();
18        move |val| -> () {
19            slider.set_value(val);
20            progressbar.set_value(val as u32);
21        }
22    });
23
24    slider.on_changed({
25        let mut spinner = spinner.clone();
26        let mut progressbar = progressbar.clone();
27        move |val| -> () {
28            spinner.set_value(val);
29            progressbar.set_value(val as u32);
30        }
31    });
32
33    vbox_numbers.append(spinner, LayoutStrategy::Compact);
34    vbox_numbers.append(slider, LayoutStrategy::Compact);
35    vbox_numbers.append(progressbar, LayoutStrategy::Compact);
36
37    group_numbers.set_child(vbox_numbers);
38    hbox.append(group_numbers.clone(), LayoutStrategy::Stretchy);
39
40    // Right
41    let mut group_lists = Group::new("Lists");
42    let mut vbox_lists = VerticalBox::new();
43    vbox_lists.set_padded(true);
44
45    let combobox = Combobox::new();
46    combobox.append("Combobox Item 1");
47    combobox.append("Combobox Item 2");
48    combobox.append("Combobox Item 3");
49
50    let mut combobox_editable = EditableCombobox::new();
51    combobox_editable.append("Editable Item 1");
52    combobox_editable.append("Editable Item 2");
53    combobox_editable.append("Editable Item 3");
54    combobox_editable.set_value("Custom Text");
55
56    let radiobuttons = RadioButtons::new();
57    radiobuttons.append("Radio Button 1");
58    radiobuttons.append("Radio Button 2");
59    radiobuttons.append("Radio Button 3");
60
61    let dummybox = VerticalBox::new();
62    vbox_lists.append(combobox, LayoutStrategy::Compact);
63    vbox_lists.append(combobox_editable, LayoutStrategy::Compact);
64    vbox_lists.append(radiobuttons, LayoutStrategy::Compact);
65    
66    // On MacOS, the last item in a list tends to take all the remaining space,
67    // regardless of our `LayoutStrategy`. Because we don't want the radio buttons
68    // to be all over the place, a dummy box is inserted to take the space instead
69    // without visually affecting the UI.
70    vbox_lists.append(dummybox, LayoutStrategy::Compact);
71
72    group_lists.set_child(vbox_lists);
73    hbox.append(group_lists.clone(), LayoutStrategy::Stretchy);
74
75    return hbox.into();
76}
More examples
Hide additional examples
examples/inputs.rs (line 46)
21fn main() {
22    // Initialize the UI framework.
23    let ui = UI::init().unwrap();
24
25    // Initialize the state of the application.
26    let state = Rc::new(RefCell::new(State {
27        slider_val: 1,
28        spinner_val: 1,
29        entry_val: "".into(),
30        password_val: "".into(),
31        multi_val: "".into(),
32    }));
33
34    // Set up the inputs for the application.
35    // While it's not necessary to create a block for this, it makes the code a lot easier
36    // to read; the indentation presents a visual cue informing the reader that these
37    // statements are related.
38    let (input_group, mut slider, mut spinner, mut entry, mut password, mut multi) = {
39        // The group will hold all the inputs
40        let mut input_group = Group::new("Inputs");
41        // The vertical box arranges the inputs within the groups
42        let mut input_vbox = VerticalBox::new();
43        input_vbox.set_padded(true);
44        // Numerical inputs
45        let slider = Slider::new(1, 100);
46        let spinner = Spinbox::new(1, 100);
47        let entry = Entry::new();
48        let password = PasswordEntry::new();
49        let multi = MultilineEntry::new();
50        // Add everything in hierarchy
51        // Note the reverse order here. Again, it's not necessary, but it improves
52        // readability.
53        input_vbox.append(slider.clone(), LayoutStrategy::Compact);
54        input_vbox.append(spinner.clone(), LayoutStrategy::Compact);
55        input_vbox.append(Spacer::new(), LayoutStrategy::Compact);
56        input_vbox.append(HorizontalSeparator::new(), LayoutStrategy::Compact);
57        input_vbox.append(Spacer::new(), LayoutStrategy::Compact);
58        input_vbox.append(entry.clone(), LayoutStrategy::Compact);
59        input_vbox.append(password.clone(), LayoutStrategy::Compact);
60        input_vbox.append(multi.clone(), LayoutStrategy::Stretchy);
61        input_group.set_child(input_vbox);
62        (input_group, slider, spinner, entry, password, multi)
63    };
64
65    // Set up the outputs for the application. Organization is very similar to the
66    // previous setup.
67    let (
68        output_group,
69        add_label,
70        sub_label,
71        text_label,
72        password_label,
73        bigtext_label,
74        progress_bar,
75    ) = {
76        let mut output_group = Group::new("Outputs");
77        let mut output_vbox = VerticalBox::new();
78        let add_label = Label::new("");
79        let sub_label = Label::new("");
80        let text_label = Label::new("");
81        let password_label = Label::new("");
82        let bigtext_label = Label::new("");
83        let progress_bar = ProgressBar::indeterminate();
84        output_vbox.append(add_label.clone(), LayoutStrategy::Compact);
85        output_vbox.append(sub_label.clone(), LayoutStrategy::Compact);
86        output_vbox.append(progress_bar.clone(), LayoutStrategy::Compact);
87        output_vbox.append(text_label.clone(), LayoutStrategy::Compact);
88        output_vbox.append(password_label.clone(), LayoutStrategy::Compact);
89        output_vbox.append(bigtext_label.clone(), LayoutStrategy::Stretchy);
90        output_group.set_child(output_vbox);
91        (
92            output_group,
93            add_label,
94            sub_label,
95            text_label,
96            password_label,
97            bigtext_label,
98            progress_bar,
99        )
100    };
101
102    // This horizontal box will arrange the two groups of controls.
103    let mut hbox = HorizontalBox::new();
104    hbox.append(input_group, LayoutStrategy::Stretchy);
105    hbox.append(output_group, LayoutStrategy::Stretchy);
106
107    // The window allows all constituent components to be displayed.
108    let mut window = Window::new(
109        &ui.clone(),
110        "Input Output Test",
111        300,
112        150,
113        WindowType::NoMenubar,
114    );
115    window.set_child(hbox);
116    window.show();
117
118    // These on_changed functions allow updating the application state when a
119    // control changes its value.
120
121    slider.on_changed({
122        let state = state.clone();
123        move |val| {
124            state.borrow_mut().slider_val = val;
125        }
126    });
127
128    spinner.on_changed({
129        let state = state.clone();
130        move |val| {
131            state.borrow_mut().spinner_val = val;
132        }
133    });
134
135    entry.on_changed({
136        let state = state.clone();
137        move |val| {
138            state.borrow_mut().entry_val = val;
139        }
140    });
141
142    password.on_changed({
143        let state = state.clone();
144        move |val| {
145            state.borrow_mut().password_val = val;
146        }
147    });
148
149    multi.on_changed({
150        let state = state.clone();
151        move |val| {
152            state.borrow_mut().multi_val = val;
153        }
154    });
155
156    // Rather than just invoking ui.run(), using EventLoop gives a lot more control
157    // over the user interface event loop.
158    // Here, the on_tick() callback is used to update the view against the state.
159    let mut event_loop = ui.event_loop();
160    event_loop.on_tick({
161        let mut add_label = add_label.clone();
162        let mut sub_label = sub_label.clone();
163        let mut text_label = text_label.clone();
164        let mut password_label = password_label.clone();
165        let mut bigtext_label = bigtext_label.clone();
166        let mut progress_bar = progress_bar.clone();
167        move || {
168            let state = state.borrow();
169
170            // Update all the outputs
171            add_label.set_text(&format!("Added: {}", state.slider_val + state.spinner_val));
172            sub_label.set_text(&format!(
173                "Subtracted: {}",
174                state.slider_val - state.spinner_val
175            ));
176            text_label.set_text(&format!("Text: {}", state.entry_val));
177            password_label.set_text(&format!("Secret Text: {}", state.password_val));
178            bigtext_label.set_text(&format!("Multiline Text: {}", state.multi_val));
179            progress_bar.set_value((state.slider_val + state.spinner_val) as u32)
180        }
181    });
182    event_loop.run();
183}
examples/inputs-grid.rs (line 46)
22fn main() {
23    // Initialize the UI framework.
24    let ui = UI::init().unwrap();
25
26    // Initialize the state of the application.
27    let state = Rc::new(RefCell::new(State {
28        slider_val: 1,
29        spinner_val: 1,
30        entry_val: "".into(),
31        password_val: "".into(),
32        multi_val: "".into(),
33    }));
34
35    // Create the grid which we'll use to lay out controls
36    let mut grid = LayoutGrid::new();
37    grid.set_padded(true);
38
39    // Set up the inputs for the application.
40    // While it's not necessary to create a block for this, it makes the code a lot easier
41    // to read; the indentation presents a visual cue informing the reader that these
42    // statements are related.
43    let (mut slider, mut spinner, mut entry, mut password, mut multi) = {
44        // Numerical inputs
45        let slider = Slider::new(1, 100);
46        let spinner = Spinbox::new(1, 100);
47        // Text inputs
48        let entry = Entry::new();
49        let password = PasswordEntry::new();
50        let multi = MultilineEntry::new();
51        // Add everything into the grid
52        grid.append(
53            slider.clone(),
54            // This is position (by slot) and size, expansion, and alignment.
55            // In this case, row 0, col 0, 1 by 1, compress as much as possible,
56            // and align to the fill.
57            0,
58            0,
59            1,
60            1,
61            GridExpand::Neither,
62            GridAlignment::Fill,
63            GridAlignment::Fill,
64        );
65        grid.append(
66            spinner.clone(),
67            // This one is at column zero, row 1.
68            0,
69            1,
70            1,
71            1,
72            GridExpand::Neither,
73            GridAlignment::Fill,
74            GridAlignment::Fill,
75        );
76        grid.append(
77            HorizontalSeparator::new(),
78            0,
79            3,
80            1,
81            1,
82            GridExpand::Neither,
83            GridAlignment::Fill,
84            GridAlignment::Fill,
85        );
86        grid.append(
87            entry.clone(),
88            0,
89            4,
90            1,
91            1,
92            GridExpand::Neither,
93            GridAlignment::Fill,
94            GridAlignment::Fill,
95        );
96        grid.append(
97            password.clone(),
98            0,
99            5,
100            1,
101            1,
102            GridExpand::Neither,
103            GridAlignment::Fill,
104            GridAlignment::Fill,
105        );
106        grid.append(
107            multi.clone(),
108            // The multiline entry is at column 0, row 1, and expands vertically.
109            0,
110            6,
111            1,
112            1,
113            GridExpand::Vertical,
114            GridAlignment::Fill,
115            GridAlignment::Fill,
116        );
117        (slider, spinner, entry, password, multi)
118    };
119
120    // Set up the outputs for the application. Organization is very similar to the
121    // previous setup.
122    let (add_label, sub_label, text_label, password_label, bigtext_label, progress_bar) = {
123        let add_label = Label::new("");
124        let sub_label = Label::new("");
125        let text_label = Label::new("");
126        let password_label = Label::new("");
127        let bigtext_label = Label::new("");
128        let progress_bar = ProgressBar::indeterminate();
129        grid.append(
130            add_label.clone(),
131            1,
132            0,
133            1,
134            1,
135            GridExpand::Neither,
136            GridAlignment::Fill,
137            GridAlignment::Fill,
138        );
139        grid.append(
140            sub_label.clone(),
141            1,
142            1,
143            1,
144            1,
145            GridExpand::Neither,
146            GridAlignment::Fill,
147            GridAlignment::Fill,
148        );
149        // We skip the #2 & 3 slots so that the text labels will align with their inputs.
150        // This is important because the big text label can expand vertically.
151        grid.append(
152            text_label.clone(),
153            1,
154            4,
155            1,
156            1,
157            GridExpand::Neither,
158            GridAlignment::Fill,
159            GridAlignment::Fill,
160        );
161        grid.append(
162            password_label.clone(),
163            1,
164            5,
165            1,
166            1,
167            GridExpand::Neither,
168            GridAlignment::Fill,
169            GridAlignment::Fill,
170        );
171        grid.append(
172            bigtext_label.clone(),
173            1,
174            6,
175            1,
176            1,
177            GridExpand::Neither,
178            GridAlignment::Fill,
179            GridAlignment::Fill,
180        );
181        grid.append(
182            progress_bar.clone(),
183            0,
184            7,
185            2,
186            1,
187            GridExpand::Neither,
188            GridAlignment::Fill,
189            GridAlignment::Fill,
190        );
191        (
192            add_label,
193            sub_label,
194            text_label,
195            password_label,
196            bigtext_label,
197            progress_bar,
198        )
199    };
200
201    // The window allows all constituent components to be displayed.
202    let mut window = Window::new(&ui, "Input Output Test", 300, 150, WindowType::NoMenubar);
203    window.set_child(grid);
204    window.show();
205
206    // These on_changed functions allow updating the application state when a
207    // control changes its value.
208
209    slider.on_changed({
210        let state = state.clone();
211        move |val| {
212            state.borrow_mut().slider_val = val;
213        }
214    });
215
216    spinner.on_changed({
217        let state = state.clone();
218        move |val| {
219            state.borrow_mut().spinner_val = val;
220        }
221    });
222
223    entry.on_changed({
224        let state = state.clone();
225        move |val| {
226            state.borrow_mut().entry_val = val;
227        }
228    });
229
230    password.on_changed({
231        let state = state.clone();
232        move |val| {
233            state.borrow_mut().password_val = val;
234        }
235    });
236
237    multi.on_changed({
238        let state = state.clone();
239        move |val| {
240            state.borrow_mut().multi_val = val;
241        }
242    });
243
244    // Rather than just invoking ui.run(), using EventLoop gives a lot more control
245    // over the user interface event loop.
246    // Here, the on_tick() callback is used to update the view against the state.
247    let mut event_loop = ui.event_loop();
248    event_loop.on_tick({
249        let mut add_label = add_label.clone();
250        let mut sub_label = sub_label.clone();
251        let mut text_label = text_label.clone();
252        let mut password_label = password_label.clone();
253        let mut bigtext_label = bigtext_label.clone();
254        let mut progress_bar = progress_bar.clone();
255        move || {
256            let state = state.borrow();
257
258            // Update all the outputs
259            add_label.set_text(&format!("Added: {}", state.slider_val + state.spinner_val));
260            sub_label.set_text(&format!(
261                "Subtracted: {}",
262                state.slider_val - state.spinner_val
263            ));
264            text_label.set_text(&format!("Text: {}", state.entry_val));
265            password_label.set_text(&format!("Secret Text: {}", state.password_val));
266            bigtext_label.set_text(&format!("Multiline Text: {}", state.multi_val));
267            progress_bar.set_value((state.slider_val + state.spinner_val) as u32);
268        }
269    });
270    event_loop.run();
271}
Source

pub fn new_unlimited() -> Self

Trait Implementations§

Source§

impl Clone for Spinbox

Source§

fn clone(&self) -> Spinbox

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 Drop for Spinbox

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Into<Control> for Spinbox

Source§

fn into(self) -> Control

Converts this type into the (usually inferred) input type.
Source§

impl NumericEntry for Spinbox

Source§

fn value(&self) -> i32

Source§

fn set_value(&mut self, value: i32)

Source§

fn on_changed<'ctx, F>(&mut self, callback: F)
where F: FnMut(i32) + 'static,

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