Nana C++ Library. Reference for users.
What we need to use nana
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
nana::button Class Reference

Define a button widget and provides the interfaces to be operational. More...

Inheritance diagram for nana::button:
nana::widget_object< category::widget_tag, drawerbase::button::trigger > nana::detail::widget_base nana::widget

Public Member Functions

 button ()
 
 button (window parent, bool visible)
 
 button (window parent, const ::std::string &caption, bool visible=true)
 
 button (window parent, const char *caption, bool visible=true)
 
 button (window parent, const nana::rectangle &=rectangle(), bool visible=true)
 
buttonicon (const nana::paint::image &image)
 Shows an icon in front of caption. More...
 
buttonenable_pushed (bool)
 
bool pushed () const
 
buttonpushed (bool)
 
buttonomitted (bool)
 Enables/Disables omitting displaying the caption if the text is too long. More...
 
buttonenable_focus_color (bool)
 Enables/Disables showing the caption with a special color to indicate the button is focused. More...
 
buttonset_bground (const pat::cloneable< element::element_interface > &)
 Sets a user-defined background element. More...
 
buttonset_bground (const std::string &)
 Sets a pre-defined background element by a name. More...
 
buttontransparent (bool enable)
 
bool transparent () const
 
buttonedge_effects (bool enable)
 
- Public Member Functions inherited from nana::widget_object< category::widget_tag, drawerbase::button::trigger >
 widget_object ()
 
 ~widget_object ()
 
event_typeevents () const
 
bool create (window parent_wd, bool visible)
 
bool create (window parent_wd, const rectangle &r={}, bool visible=true)
 
widget_objectborderless (bool enable)
 
bool borderless () const
 
scheme_typescheme () const
 
void filter_event (const event_code evt_code, const bool bDisabled)
 
void filter_event (const std::vector< event_code > evt_codes, const bool bDisabled)
 
void filter_event (const event_filter_status &evt_all_states)
 
bool filter_event (const event_code evt_code)
 
event_filter_status filter_event ()
 
void clear_filter ()
 
- Public Member Functions inherited from nana::detail::widget_base
window handle () const override
 Returns the handle of window, returns 0 if window is not created. More...
 
- Public Member Functions inherited from nana::widget
 widget ()=default
 
virtual ~widget ()=default
 
bool empty () const
 Determines whether the manipulator is handling a window. More...
 
void close ()
 
window parent () const
 
::std::string caption () const noexcept
 
::std::wstring caption_wstring () const noexcept
 
native_string_type caption_native () const noexcept
 
widgetcaption (std::string utf8)
 
widgetcaption (std::wstring)
 
template<typename... Args>
void i18n (std::string msgid, Args &&...args)
 
void i18n (i18n_eval)
 
void cursor (nana::cursor)
 
nana::cursor cursor () const
 Retrieves the shape of cursor. More...
 
void typeface (const paint::font &font)
 
paint::font typeface () const
 
bool enabled () const
 Determines whether the window is enabled for mouse and keyboard input. More...
 
void enabled (bool)
 
void enable_dropfiles (bool)
 Enables/Disables a window to accept dropped files. More...
 
void focus ()
 
bool focused () const
 
std::shared_ptr
< scroll_operation_interface
scroll_operation ()
 
void show ()
 Sets the window visible. More...
 
void hide ()
 Sets the window invisible. More...
 
bool visible () const
 
nana::size size () const
 
void size (const nana::size &)
 
void set_capture (bool ignore_children)
 Enables the widget to grab the mouse input. More...
 
void release_capture ()
 Disables the widget to grab the mouse input. More...
 
point pos () const
 
void move (int x, int y)
 
void move (const point &)
 
void move (const rectangle &)
 
void fgcolor (const nana::color &)
 
nana::color fgcolor () const
 
void bgcolor (const nana::color &)
 
nana::color bgcolor () const
 
general_eventsevents () const
 
void umake_event (event_handle eh) const
 Deletes an event callback by a handle. More...
 
widgetregister_shortkey (wchar_t)
 Registers a shortkey. To remove a registered key, pass 0. More...
 
widgettake_active (bool activated, window take_if_not_activated)
 
widgettooltip (const ::std::string &)
 
 operator dummy_bool_type () const
 
 operator window () const
 

Additional Inherited Members

- Public Types inherited from nana::widget_object< category::widget_tag, drawerbase::button::trigger >
using scheme_type = ::nana::widget_geometrics
 
using event_type = ::nana::general_events
 
- Public Types inherited from nana::widget
using native_string_type = detail::native_string_type
 
- Protected Types inherited from nana::widget_object< category::widget_tag, drawerbase::button::trigger >
typedef drawerbase::button::trigger drawer_trigger_t
 
- Protected Member Functions inherited from nana::widget_object< category::widget_tag, drawerbase::button::trigger >
drawerbase::button::triggerget_drawer_trigger ()
 
const drawerbase::button::triggerget_drawer_trigger () const
 
- Protected Member Functions inherited from nana::widget
std::unique_ptr
<::nana::detail::widget_notifier_interface
_m_wdg_notifier ()
 
virtual native_string_type _m_caption () const noexcept
 
virtual nana::cursor _m_cursor () const
 
virtual void _m_cursor (nana::cursor)
 
virtual void _m_close ()
 
virtual bool _m_enabled () const
 
virtual void _m_enabled (bool)
 
virtual std::shared_ptr
< scroll_operation_interface
_m_scroll_operation ()
 
virtual bool _m_show (bool)
 
virtual bool _m_visible () const
 
virtual void _m_size (const nana::size &)
 
virtual void _m_move (int x, int y)
 
virtual void _m_move (const rectangle &)
 
virtual void _m_typeface (const nana::paint::font &font)
 
virtual nana::paint::font _m_typeface () const
 
virtual void _m_fgcolor (const nana::color &)
 
virtual nana::color _m_fgcolor () const
 
virtual void _m_bgcolor (const nana::color &)
 
virtual nana::color _m_bgcolor () const
 
- Protected Attributes inherited from nana::detail::widget_base
window handle_ { nullptr }
 

Detailed Description

Define a button widget and provides the interfaces to be operational.

Notes

  1. The background image of button horizontally split into 5 parts and each part indicates one state. If the background of button is some area in the image, the area can be specified by using image_valid_area().
    background_button.jpg
    Background image of button horizontally split into 5 parts
    For example. There is an image of size 520 * 70 pixels, and a button background image is just 470 * 23 pixels at position (0, 0).
                int main()
                {
                  nana::form form;
                  nana::button btn(form, 5, 5, 94, 23);
                  btn.image(STR("button_image.bmp"));
                  btn.image_valid_area(nana::arrange::horizontal, nana::rectangle(0, 0, 94 * 5, 23));
                  form.show();
                  nana::exec();
                }
    

The button splits the area of image into 5 parts for each state. The order of parts are same with the order of definition of elements of enum in type button::state.

btn_over.jpg
  1. An image state can be disabled by calling image_enable() method. If a state is disabled, the button would averagely split the area of image into parts for each enabled state.
Examples:
a_group_impl.cpp, audio_player.cpp, background-effects.cpp, drag-button.cpp, example.button.cpp, example_menu.cpp, group.cpp, helloword_quit.cpp, helloworld_demo.cpp, listbox_inline_widget.cpp, loader_2.cpp, menu_popuper.cpp, MontiHall.cpp, place_login.cpp, widget_show2.cpp, and window-dragger.cpp.

Constructor & Destructor Documentation

nana::button::button ( )
nana::button::button ( window  parent,
bool  visible 
)
nana::button::button ( window  parent,
const ::std::string caption,
bool  visible = true 
)
nana::button::button ( window  parent,
const char *  caption,
bool  visible = true 
)
nana::button::button ( window  parent,
const nana::rectangle r = rectangle(),
bool  visible = true 
)

Member Function Documentation

button & nana::button::edge_effects ( bool  enable)
button & nana::button::enable_focus_color ( bool  eb)

Enables/Disables showing the caption with a special color to indicate the button is focused.

button & nana::button::enable_pushed ( bool  eb)
button & nana::button::icon ( const nana::paint::image image)

Shows an icon in front of caption.

Parameters
imageIcon to be shown. If image is empty, the current icon is erased from the button.
Returns
the reference of *this.
button & nana::button::omitted ( bool  om)

Enables/Disables omitting displaying the caption if the text is too long.

bool nana::button::pushed ( ) const
button & nana::button::pushed ( bool  psd)
button & nana::button::set_bground ( const pat::cloneable< element::element_interface > &  rv)

Sets a user-defined background element.

Examples:
example.button.cpp.
button & nana::button::set_bground ( const std::string name)

Sets a pre-defined background element by a name.

button & nana::button::transparent ( bool  enable)
bool nana::button::transparent ( ) const