I've added text from your e-mails and your example to /gnoga/docs/articles/event_listeners.txt
Thanks! David Botton On Thu, Jun 11, 2015 at 8:12 PM Jeremiah Breeden <[email protected]> wrote: > Definitely ok with that. Feel free to change formatting or names to fit > your standards as well. I was going for overly descriptive. > > On Wed, Jun 10, 2015 at 8:24 PM, Rabbi David Botton <[email protected]> > wrote: > >> Thanks for example :) Perhaps a good thing to add to the docs directory, >> example of multiple event listeners. Ok with that? >> >> On Tue, Jun 9, 2015 at 8:48 AM Jeremiah Breeden < >> [email protected]> wrote: >> >>> Managed to gen something up. Didn't put any comments in it, so if it >>> isn't self explanatory, then just ask. I don't use this particular >>> implementation (I have some generic packages that I use to keep code down), >>> but I wanted to make something representative. I tested this in one of my >>> Gnoga playing projects. The big thing is Handle_On_Click gives you the >>> containing view type which allows you to modify other controls using the on >>> click from the button. You can also pass the on click event to other >>> parent views who may want to modify their own layouts based on that button >>> event. You would just need to add a public Add_On_Click_Listener (or >>> whatever name) procedure to Listener_View.View_Type (or whatever view you >>> create) and have it call the button's Add_On_Click_Listener procedure. >>> >>> Button_For_Listeners is the extended class for Gnoga's Button_Type >>> Listener_View is just a test view type that would contain a Button among >>> other controls. >>> >>> button_for_listeners.ads >>> >>> ----------------------------------------------------------------------------------------------------------------------------------- >>> with Gnoga.Gui.Element.Common; >>> with Ada.Containers.Vectors; >>> >>> package Button_For_Listeners is >>> >>> type Listener_Type is limited interface; >>> >>> type Button_Type is new Gnoga.Gui.Element.Common.Button_Type with >>> private; >>> >>> procedure Add_On_Click_Listener >>> (Self : in out Button_Type; >>> Listener : not null access Listener_Type'Class); >>> >>> procedure Handle_On_Click(Listener : in out Listener_Type; >>> Source : in out Button_Type'Class) is >>> abstract; >>> >>> >>> private >>> type Listener_Class_Access is access all Listener_Type'Class; >>> package Vectors is new >>> Ada.Containers.Vectors(Natural,Listener_Class_Access); >>> >>> type Button_Type is new Gnoga.Gui.Element.Common.Button_Type with >>> record >>> On_Click_Listeners : Vectors.Vector; >>> end record; >>> >>> end Button_For_Listeners; >>> >>> >>> >>> button_for_listeners.adb >>> >>> ----------------------------------------------------------------------------------------------------------------------------------- >>> with Gnoga.Gui.Base; >>> >>> package body Button_For_Listeners is >>> >>> procedure Gnoga_On_Click(Object : in out >>> Gnoga.Gui.Base.Base_Type'Class) is >>> Cursor : Vectors.Cursor := >>> Button_Type(Object).On_Click_Listeners.First; >>> begin >>> while Vectors.Has_Element(Cursor) loop >>> Vectors.Element(Cursor).Handle_On_Click(Button_Type(Object)); >>> Cursor := Vectors.Next(Cursor); >>> end loop; >>> end Gnoga_On_Click; >>> >>> procedure Add_On_Click_Listener >>> (Self : in out Button_Type; >>> Listener : not null access Listener_Type'Class) is >>> begin >>> Self.On_Click_Listeners.Append(Listener); >>> Self.On_Click_Handler(Gnoga_On_Click'Access); >>> end Add_On_Click_Listener; >>> >>> end Button_For_Listeners; >>> >>> >>> >>> >>> listener_view.ads >>> >>> ----------------------------------------------------------------------------------------------------------------------------------- >>> with Gnoga.Gui.View; >>> with Gnoga.Gui.Base; >>> with Button_For_Listeners; >>> >>> package Listener_View is >>> package Buttons renames Button_For_Listeners; >>> >>> type View_Type is new Gnoga.Gui.View.View_Type >>> and Buttons.Listener_Type with private; >>> >>> overriding >>> procedure Create >>> (Self : in out View_Type; >>> Parent : in out Gnoga.Gui.Base.Base_Type'Class; >>> ID : in String := ""); >>> >>> private >>> type Self_Ref_Type(Ref : access Buttons.Listener_Type'Class) >>> is limited null record; >>> >>> type View_Type is new Gnoga.Gui.View.View_Type >>> and Buttons.Listener_Type with record >>> Button : Buttons.Button_Type; >>> Self_Reference : Self_Ref_Type(View_Type'Access); >>> end record; >>> >>> overriding >>> procedure Handle_On_Click(Listener : in out View_Type; >>> Source : in out >>> Buttons.Button_Type'Class); >>> >>> end Listener_View; >>> >>> >>> >>> listener_view.adb >>> >>> ----------------------------------------------------------------------------------------------------------------------------------- >>> package body Listener_View is >>> procedure Create(Self : in out View_Type; >>> Parent : in out Gnoga.Gui.Base.Base_Type'Class; >>> ID : in String := "") is >>> begin >>> Gnoga.Gui.View.View_Type(Self).Create(Parent); >>> Self.Button.Create(Self,"Test Button"); >>> Self.Button.Add_On_Click_Listener(Self.Self_Reference.Ref); >>> end Create; >>> >>> Test_Count : Natural := 0; >>> >>> overriding >>> procedure Handle_On_Click(Listener : in out View_Type; >>> Source : in out >>> Buttons.Button_Type'Class) is >>> begin >>> Listener.Button.Text("Testing: " & Integer'Image(Test_Count)); >>> Test_Count := Test_Count + 1; >>> end Handle_On_Click; >>> >>> end Listener_View; >>> >>> >>> >>> On Sat, Jun 6, 2015 at 3:55 PM, Jeremiah Breeden < >>> [email protected]> wrote: >>> >>>> I could provide some example code, but I would want to pretty it up at >>>> least a bit. >>>> >>>> >>> ------------------------------------------------------------------------------ >>> _______________________________________________ >>> Gnoga-list mailing list >>> [email protected] >>> https://lists.sourceforge.net/lists/listinfo/gnoga-list >>> >> >> >> ------------------------------------------------------------------------------ >> >> _______________________________________________ >> Gnoga-list mailing list >> [email protected] >> https://lists.sourceforge.net/lists/listinfo/gnoga-list >> >> > > ------------------------------------------------------------------------------ > _______________________________________________ > Gnoga-list mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/gnoga-list >
------------------------------------------------------------------------------
_______________________________________________ Gnoga-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/gnoga-list
