[gtkmm-documentation/wip/dboles/radiobutton-group: 15/16] Drop pointless/confusing class around RadioButtons
- From: Daniel Boles <dboles src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm-documentation/wip/dboles/radiobutton-group: 15/16] Drop pointless/confusing class around RadioButtons
- Date: Sun, 24 Nov 2019 19:40:09 +0000 (UTC)
commit b9368a00ceb93367989a52972b622d959e9ec619
Author: Daniel Boles <dboles src gmail com>
Date: Sun Nov 24 19:36:59 2019 +0000
Drop pointless/confusing class around RadioButtons
The 2nd example seems to have been trying to be like the 1st, which put
the 3 RadioButtons in a subclass of Window, for no real reason since
they were never then added to said Window... but the 2nd omitted to
declare its members and instead declared new local variables in the
constructor with m_ prefixes, which were managed unlike the 1st example!
Just drop all of that. There's no clear reason to use a containing class
here. By not doing so, we can present both examples in a comparable way.
docs/tutorial/C/index-in.docbook | 47 +++++++++++++---------------------------
1 file changed, 15 insertions(+), 32 deletions(-)
---
diff --git a/docs/tutorial/C/index-in.docbook b/docs/tutorial/C/index-in.docbook
index e06bae1..3c79c83 100644
--- a/docs/tutorial/C/index-in.docbook
+++ b/docs/tutorial/C/index-in.docbook
@@ -989,28 +989,17 @@ one RadioButton in a group can be selected at any one time.
There are two ways to set up a group of radio buttons. The first way
is to create the buttons, and set up their groups afterwards. Only
the constructors without a <classname>Gtk::RadioButton::Group</classname>
-parameter are used. In the following example, we
-make a new window class called <classname>RadioButtons</classname>, and then
-put three radio buttons in it:
+parameter are used. In the following example, we put 3 radio buttons in a group:
</para>
-<programlisting>class RadioButtons : public Gtk::Window
-{
-public:
- RadioButtons();
-
-protected:
- Gtk::RadioButton m_rb1, m_rb2, m_rb3;
-};
+<programlisting>
+auto rb1 = Gtk::make_managed<Gtk::RadioButton>("button1");
+auto rb2 = Gtk::make_managed<Gtk::RadioButton>("button2");
+auto rb3 = Gtk::make_managed<Gtk::RadioButton>("button3");
+rb2->join_group(*rb1);
+rb3->join_group(*rb1);
+</programlisting>
-RadioButtons::RadioButtons()
-: m_rb1("button1"),
- m_rb2("button2"),
- m_rb3("button3")
-{
- m_rb2.join_group(m_rb1);
- m_rb3.join_group(m_rb1);
-}</programlisting>
<para>
We told >kmm; to put all three <classname>RadioButton</classname>s in the
same group by using <methodname>join_group()</methodname> to tell the other
@@ -1020,7 +1009,7 @@ same group by using <methodname>join_group()</methodname> to tell the other
<para>
Note that you can't do
-<programlisting>m_rb2.set_group(m_rb1.get_group()); //doesn't work</programlisting>
+<programlisting>rb2.set_group(rb1.get_group());</programlisting>
because <methodname>get_group()</methodname> returns a <classname>RadioButton::Group</classname>
which is modified by <methodname>set_group()</methodname> and therefore is non-const.
</para>
@@ -1029,19 +1018,13 @@ which is modified by <methodname>set_group()</methodname> and therefore is non-c
The second way to set up radio buttons is to make a group first, and
then add radio buttons to it. Here's an example:
</para>
-<programlisting>class RadioButtons : public Gtk::Window
-{
-public:
- RadioButtons();
-};
-RadioButtons::RadioButtons()
-{
- Gtk::RadioButton::Group group;
- auto m_rb1 = Gtk::make_managed<Gtk::RadioButton>(group, "button1");
- auto m_rb2 = Gtk::make_managed<Gtk::RadioButton>(group, "button2");
- auto m_rb3 = Gtk::make_managed<Gtk::RadioButton>(group, "button3");
-}</programlisting>
+<programlisting>
+Gtk::RadioButton::Group group;
+auto rb1 = Gtk::make_managed<Gtk::RadioButton>(group, "button1");
+auto rb2 = Gtk::make_managed<Gtk::RadioButton>(group, "button2");
+auto rb3 = Gtk::make_managed<Gtk::RadioButton>(group, "button3");
+</programlisting>
<para>
We made a new group by simply declaring a variable, <literal>group</literal>,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]