[]Struct gtk::SpinButton

pub struct SpinButton(_, _);

A SpinButton is an ideal way to allow the user to set the value of some attribute. Rather than having to directly type a number into a Entry, SpinButton allows the user to click on one of two arrows to increment or decrement the displayed value. A value can still be typed in, with the bonus that it can be checked to ensure it is in a given range.

The main properties of a SpinButton are through an adjustment. See the Adjustment section for more details about an adjustment's properties. Note that SpinButton will by default make its entry large enough to accomodate the lower and upper bounds of the adjustment, which can lead to surprising results. Best practice is to set both the Entry:width-chars and Entry:max-width-chars poperties to the desired number of characters to display in the entry.

CSS nodes

spinbutton.horizontal
├── undershoot.left
├── undershoot.right
├── entry
│   ╰── ...
├── button.down
╰── button.up
spinbutton.vertical
├── undershoot.left
├── undershoot.right
├── button.up
├── entry
│   ╰── ...
╰── button.down

GtkSpinButtons main CSS node has the name spinbutton. It creates subnodes for the entry and the two buttons, with these names. The button nodes have the style classes .up and .down. The Entry subnodes (if present) are put below the entry node. The orientation of the spin button is reflected in the .vertical or .horizontal style class on the main node.

Using a SpinButton to get an integer

// Provides a function to retrieve an integer value from a GtkSpinButton
// and creates a spin button to model percentage values.

gint
grab_int_value (GtkSpinButton *button,
                gpointer       user_data)
{
  return gtk_spin_button_get_value_as_int (button);
}

void
create_integer_spin_button (void)
{

  GtkWidget *window, *button;
  GtkAdjustment *adjustment;

  adjustment = gtk_adjustment_new (50.0, 0.0, 100.0, 1.0, 5.0, 0.0);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_container_set_border_width (GTK_CONTAINER (window), 5);

  // creates the spinbutton, with no decimal places
  button = gtk_spin_button_new (adjustment, 1.0, 0);
  gtk_container_add (GTK_CONTAINER (window), button);

  gtk_widget_show_all (window);
}

Using a SpinButton to get a floating point value

// Provides a function to retrieve a floating point value from a
// GtkSpinButton, and creates a high precision spin button.

gfloat
grab_float_value (GtkSpinButton *button,
                  gpointer       user_data)
{
  return gtk_spin_button_get_value (button);
}

void
create_floating_spin_button (void)
{
  GtkWidget *window, *button;
  GtkAdjustment *adjustment;

  adjustment = gtk_adjustment_new (2.500, 0.0, 5.0, 0.001, 0.1, 0.0);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_container_set_border_width (GTK_CONTAINER (window), 5);

  // creates the spinbutton, with three decimal places
  button = gtk_spin_button_new (adjustment, 0.001, 3);
  gtk_container_add (GTK_CONTAINER (window), button);

  gtk_widget_show_all (window);
}

Implements

SpinButtonExt, EntryExt, WidgetExt, glib::object::ObjectExt, BuildableExt, CellEditableExt, EditableExt, OrientableExt, SpinButtonSignals, WidgetExtManual, BuildableExtManual, EditableSignals

Implementations

impl SpinButton[src]

pub fn new<P: IsA<Adjustment>>(
    adjustment: Option<&P>,
    climb_rate: f64,
    digits: u32
) -> SpinButton
[src]

Creates a new SpinButton.

adjustment

the Adjustment object that this spin button should use, or None

climb_rate

specifies by how much the rate of change in the value will accelerate if you continue to hold down an up/down button or arrow key

digits

the number of decimal places to display

Returns

The new spin button as a Widget

pub fn with_range(min: f64, max: f64, step: f64) -> SpinButton[src]

Trait Implementations

impl Clone for SpinButton

impl Debug for SpinButton

impl Display for SpinButton[src]

impl Eq for SpinButton

impl Hash for SpinButton

impl IsA<Buildable> for SpinButton

impl IsA<CellEditable> for SpinButton

impl IsA<Editable> for SpinButton

impl IsA<Entry> for SpinButton

impl IsA<Orientable> for SpinButton

impl IsA<Widget> for SpinButton

impl Ord for SpinButton

impl<T: ObjectType> PartialEq<T> for SpinButton

impl<T: ObjectType> PartialOrd<T> for SpinButton

impl StaticType for SpinButton

Auto Trait Implementations

impl RefUnwindSafe for SpinButton

impl !Send for SpinButton

impl !Sync for SpinButton

impl Unpin for SpinButton

impl UnwindSafe for SpinButton

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Super, Sub> CanDowncast<Sub> for Super where
    Sub: IsA<Super>,
    Super: IsA<Super>, 

impl<T> Cast for T where
    T: ObjectType, 

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ObjectExt for T where
    T: ObjectType, 

impl<'a, T> ToGlibContainerFromSlice<'a, *const GList> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<List>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *const GPtrArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<PtrArray>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<Array>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GList> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<List>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GPtrArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<PtrArray>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> ToValue for T where
    T: SetValue + ?Sized

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.