neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
button.hpp
Go to the documentation of this file.
1// button.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2015, 2020 Leigh Johnston. All Rights Reserved.
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
23#include <neogfx/core/event.hpp>
29
30namespace neogfx
31{
32 extern template class widget<i_button>;
33
34 template <typename ButtonInterface = i_button>
35 class button : public widget<ButtonInterface>, protected i_mnemonic
36 {
38 // events
39 public:
40 define_declared_event(Pressed, pressed)
41 define_declared_event(Clicked, clicked)
42 define_declared_event(DoubleClicked, double_clicked)
43 define_declared_event(RightClicked, right_clicked)
44 define_declared_event(Released, released)
45 public:
46 define_declared_event(Toggled, toggled)
47 define_declared_event(Checked, checked)
48 define_declared_event(Unchecked, unchecked)
49 define_declared_event(Indeterminate, indeterminate)
50 // types
51 public:
52 typedef ButtonInterface button_interface;
53 // button
54 public:
56 button(std::string const& aText, alignment aAlignment = alignment::Left | alignment::VCenter);
57 button(const i_texture& aTexture, alignment aAlignment = alignment::Left | alignment::VCenter);
58 button(const i_image& aImaget, alignment aAlignment = alignment::Left | alignment::VCenter);
59 button(std::string const& aText, const i_texture& aTexture, alignment aAlignment = alignment::Left | alignment::VCenter);
60 button(std::string const& aText, const i_image& aImaget, alignment aAlignment = alignment::Left | alignment::VCenter);
62 button(i_widget& aParent, std::string const& aText, alignment aAlignment = alignment::Left | alignment::VCenter);
63 button(i_widget& aParent, const i_texture& aTexture, alignment aAlignment = alignment::Left | alignment::VCenter);
64 button(i_widget& aParent, const i_image& aImage, alignment aAlignment = alignment::Left | alignment::VCenter);
65 button(i_widget& aParent, std::string const& aText, const i_texture& aTexture, alignment aAlignment = alignment::Left | alignment::VCenter);
66 button(i_widget& aParent, std::string const& aText, const i_image& aImage, alignment aAlignment = alignment::Left | alignment::VCenter);
68 button(i_layout& aLayout, std::string const& aText, alignment aAlignment = alignment::Left | alignment::VCenter);
69 button(i_layout& aLayout, const i_texture& aTexture, alignment aAlignment = alignment::Left | alignment::VCenter);
70 button(i_layout& aLayout, const i_image& aImage, alignment aAlignment = alignment::Left | alignment::VCenter);
71 button(i_layout& aLayout, std::string const& aText, const i_texture& aTexture, alignment aAlignment = alignment::Left | alignment::VCenter);
72 button(i_layout& aLayout, std::string const& aText, const i_image& aImage, alignment aAlignment = alignment::Left | alignment::VCenter);
73 ~button();
74 // widget
75 public:
76 using base_type::as_widget;
77 neogfx::size_policy size_policy() const override;
78 size maximum_size(optional_size const&) const override;
79 neogfx::padding padding() const override;
80 // i_button
81 public:
82 bool is_pressed() const override;
83 button_checkable checkable() const override;
84 void set_checkable(button_checkable aCheckable = button_checkable::BiState) override;
85 bool is_checked() const override;
86 bool is_unchecked() const override;
87 bool is_indeterminate() const override;
88 void check() override;
89 void uncheck() override;
90 void set_indeterminate() override;
91 void set_checked(bool aChecked) override;
92 void toggle() override;
93 // button
94 public:
95 i_string const& text() const;
96 void set_text(i_string const& aText);
97 const texture& image() const;
98 void set_image(i_string const& aImageUri);
99 void set_image(const neogfx::image& aImage);
100 void set_image(const texture& aImage);
101 void set_image_extents(const optional_size& aImageExtents);
102 const neogfx::label& label() const;
103 neogfx::label& label();
104 const neogfx::text_widget& text_widget() const;
106 const neogfx::image_widget& image_widget() const;
108 // widget
109 protected:
110 void mouse_button_pressed(mouse_button aButton, const point& aPosition, key_modifiers_e aKeyModifiers) override;
111 void mouse_button_double_clicked(mouse_button aButton, const point& aPosition, key_modifiers_e aKeyModifiers) override;
112 void mouse_button_released(mouse_button aButton, const point& aPosition) override;
113 protected:
114 bool key_pressed(scan_code_e aScanCode, key_code_e aKeyCode, key_modifiers_e aKeyModifiers) override;
115 // button
116 protected:
117 virtual void handle_clicked();
118 protected:
119 virtual bool can_toggle() const;
120 virtual const std::optional<bool>& checked_state() const;
121 virtual bool set_checked_state(const std::optional<bool>& aCheckedState);
122 protected:
123 std::string mnemonic() const override;
124 void mnemonic_execute() override;
125 i_widget& mnemonic_widget() override;
126 private:
127 void init();
128 private:
129 sink iSink;
130 bool iPressed;
131 button_checkable iCheckable;
132 button_checked_state iCheckedState;
133 horizontal_layout iLayout;
135 };
136}
bool mnemonic(glyph_char const &g)
basic_padding< dimension > padding
mouse_button
Definition i_mouse.hpp:31
button_checkable
Definition i_button.hpp:30
#define meta_object(...)
Definition i_object.hpp:28
#define define_declared_event(name, declName,...)
Definition event.hpp:195