If I create some radio buttons
R1 : Gnoga.Gui.Element.Form.Radio_Button_Type;
L1 : Gnoga.Gui.Element.Form.Label_Type;
R2 : Gnoga.Gui.Element.Form.Radio_Button_Type;
L2 : Gnoga.Gui.Element.Form.Label_Type;
and create them
R1.Create (Form => Form, Checked => True, Name => "R");
L1.Create (Form => Form, Label_For => R1, Content =>"R1", Auto_Place => False);
R2.Create (Form => Form, Checked => False, Name => "R");
L2.Create (Form => Form, Label_For => R2, Content =>"R2", Auto_Place => False);
then, if R1 has the black circle and R2 is empty,
R1.Checked
returns True. All straightforward and as expected.
However, Gnoga's radio buttons are rather low level. For a set of N buttons, you
have to declare N radio buttons and N labels, and come up with a name to tie
them all together. At a higher level, one should be able to declare and create a
whole set of buttons at once.
In an attempt to do so, I tried (assuming a "use" for Ada.Strings.Unbounded)
type Radio_Handle is private;
type Text_List is array (Positive range <>) of Unbounded_String;
function New_Radio_Buttons (Label : Text_List) return Radio_Handle;
-- Creates a set of Label'Length radio buttons with labels given by Label
function Active (Radio : Radio_Handle; Index : Positive) return Boolean;
-- Index refers to the button created with the label with index Index
"Active" seems more appropriate to me than "Checked".
For the full declaration of Radio_Handle
type Radio_Info is record
Button : Gnoga.Gui.Element.Form.Radio_Button_Type;
Label : Gnoga.Gui.Element.Form.Label_Type;
end record;
type Radio_List is array (Positive range <>) of Radio_Info;
type Radio_List_Ptr is access Radio_List;
type Radio_Handle is record
Radio : Radio_List_Ptr;
end record;
Assuming a global form Form, properly created, I implemented the functions as
Next_Button : Positive := 1;
function New_Radio_Buttons (Label : Text_List) return Radio_Handle is
Result : Radio_Handle;
Name : String := Next_Button'Image;
begin -- New_Radio_Buttons
Name (Name'First) := 'R';
Next_Button := Next_Button + 1;
Result.Radio := new Radio_List (Label'Range);
All_Buttons : for I in Label'Range loop
Result.Radio (I).Button.Create
(Form => Form, Checked => I = Label'First, Name => Name);
Result.Radio (I).Label.Create (Form => Form,
Label_For => Result.Radio (I).Button,
Content => To_String (Label (I) ),
Auto_Place => False);
end loop All_Buttons;
return Result;
end New_Radio_Buttons;
function Active (Radio : Radio_Handle; Index : Positive) return Boolean is
-- Empty
begin -- Active
return Radio.Radio (Index).Button.Checked;
end Active;
I then tried this out
Radio : Radio_Handle;
Radio := New_Radio_Buttons (Label => (1 => To_Unbounded_String ("R1"),
2 => To_Unbounded_String ("R2") ) );
which creates a set of 2 buttons with the appropriate labels and the black
circle in R1 as expected. However
Active (Radio, 1)
returns False when R1 has the black circle, and True when R2 has it. I expect
the opposite. I can't figure out what I've done wrong, and hope someone here
will see what I'm missing.
--
Jeff Carter
"You empty-headed animal-food-trough wiper."
Monty Python & the Holy Grail
04
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gnoga-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gnoga-list