1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//! Buttons that can receive user input.

use widget_prelude::*;

use std::ptr;

/// A button that can be clicked momentarily and invoke a callback when this happens.
pub struct Button(IUPPtr);

impl Button {
    /// Create a new `Button` with no label.
    pub fn new() -> Button {
        unsafe {
            let ptr = ::iup_sys::IupButton(ptr::null(), ptr::null());
            Self::from_ptr(ptr)
        }
    }

    /// Set the label of this button. Can be blank.
    pub fn set_label<L: Into<String>>(self, label: L) -> Self {
        self.set_str_attribute(::attrs::TITLE, label);
        self        
    }
}

impl_widget! { Button, "button" }

impl_onclick! { Button }

impl ::image::ImageContainer for Button {}