[gtkmm-documentation/wip/dboles/radiobutton-group: 1/2] Drop pointless/confusing class around RadioButtons



commit 780c74e64ea55543458def03722d9cccb5da276d
Author: Daniel Boles <dboles src gmail com>
Date:   Fri Jun 28 18:17:44 2019 +0100

    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 0e645d7..244903e 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>
+Gtk::RadioButton rb1("button1");
+Gtk::RadioButton rb2("button2");
+Gtk::RadioButton rb3("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 &gtkmm; 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&lt;Gtk::RadioButton&gt;(group, "button1");
-  auto m_rb2 = Gtk::make_managed&lt;Gtk::RadioButton&gt;(group, "button2");
-  auto m_rb3 = Gtk::make_managed&lt;Gtk::RadioButton&gt;(group, "button3");
-}</programlisting>
+<programlisting>
+Gtk::RadioButton::Group group;
+Gtk::RadioButton rb1(group, "button1");
+Gtk::RadioButton rb2(group, "button2");
+Gtk::RadioButton rb3(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]