So after trying a bunch of implementations, I am leaning towards the
following:
Gnoga.Gui.Modal_Dialog.ads
**************************************************************
with Gnoga.Gui.Window;
with Gnoga.Types.Colors;
with Gnoga.Gui.View;
package Gnoga.Gui.Modal_Dialog is
type Dialog_Type is tagged limited private;
type Dialog_Access is access all Dialog_Type;
type Pointer_To_Dialog_Class is access all Dialog_Type'Class;
procedure Create
(Dialog : in out Dialog_Type;
Parent : in out Gnoga.Gui.Window.Window_Type'Class;
ID : in String := "");
function Get_View
(Dialog : in out Dialog_Type)
return Gnoga.Gui.View.View_Access;
procedure Show
(Dialog : in out Dialog_Type;
Show : Boolean := True);
procedure Center(Dialog : in out Dialog_Type);
procedure Background_Color
(Dialog : in out Dialog_Type;
Color : String);
procedure Background_Color
(Dialog : in out Dialog_Type;
Color : Gnoga.Types.Colors.Color_Enumeration);
private
type Dialog_Type is new Gnoga.Gui.View.View_Type with record
Main_View : Gnoga.Gui.View.View_Access := null;
end record;
end Gnoga.Gui.Modal_Dialog;
**************************************************************
Gnoga.Gui.Modal_Dialog.adb
**************************************************************
with Gnoga.Gui.Window;
with Gnoga.Gui.Base;
with Gnoga.Gui.Element;
package body Gnoga.Gui.Modal_Dialog is
procedure Create
(Dialog : in out Dialog_Type;
Parent : in out Gnoga.Gui.Window.Window_Type'Class;
ID : in String := "")
is
use type Gnoga.Gui.View.View_Access;
Old_View : Gnoga.Gui.Base.Pointer_To_Base_Class := Parent.Get_View;
begin
if Dialog.Main_View = null then
-- Create the Dialog
Gnoga.Gui.View.View_Type(Dialog).Create
(Parent => Parent,
ID => ID);
-- Creating a view using a window as a parent sets the view as the
-- window's main view. This line sets it back to the original.
Parent.Set_View(Old_View.all);
-- Configure the Modal Background
Dialog.Fill_Parent;
Dialog.Background_Color("Grey");
-- Set the default show/hide state
Dialog.Show(False);
-- Create the main view of the dialog
Dialog.Main_View := new Gnoga.Gui.View.View_Type;
Dialog.Main_View.Dynamic;
Dialog.Main_View.Create(Dialog);
Dialog.Main_View.Background_Color("White");
Dialog.Main_View.Position(Gnoga.Gui.Element.Fixed);
-- Center the view as a default
Dialog.Center;
end if;
end Create;
function Get_View
(Dialog : in out Dialog_Type)
return Gnoga.Gui.View.View_Access is
begin
return Dialog.Main_View;
end Get_View;
procedure Show
(Dialog : in out Dialog_Type;
Show : Boolean := True)
is
begin
if Show then
Dialog.Z_Index(Integer'Last);
Dialog.Opacity(1.0);
Dialog.Hidden(False);
else
Dialog.Hidden;
Dialog.Opacity(0.0);
Dialog.Z_Index(Integer'First);
end if;
end Show;
procedure Center(Dialog : in out Dialog_Type) is
begin
Dialog.Main_View.Top (Dialog.Position_Top
+ Dialog.Height/2
- Dialog.Main_View.Height/2);
Dialog.Main_View.Left(Dialog.Position_Left
+ Dialog.Width/2
- Dialog.Main_View.Width/2);
end Center;
procedure Background_Color
(Dialog : in out Dialog_Type;
Color : String)
is
begin
Gnoga.Gui.View.View_Type(Dialog).Background_Color(Color);
end Background_Color;
procedure Background_Color
(Dialog : in out Dialog_Type;
Color : Gnoga.Types.Colors.Color_Enumeration)
is
begin
Gnoga.Gui.View.View_Type(Dialog).Background_Color(Color);
end Background_Color;
end Gnoga.Gui.Modal_Dialog;
**************************************************************
This makes Dialog_Type completely private. It creates an intermediate view
to hold the dialog. Additionally, it puts the burden on the user to set
the size of the dialog. It does deviate from the standard Gnoga mentality,
but overall I think it works well.
usage changes:
***********************************************************
type App_Data(Main_Window : access Gnoga.Gui.Window.Window_Type'Class) is
new Gnoga.Types.Connection_Data_Type
with
record
Top_Level_View : Gnoga.Gui.View.View_Type;
Add_Bttn : Gnoga.Gui.Element.Common.Button_Type;
Scrollable : Gnoga.Gui.View.Console.Console_View_Type;
Views : View_List;
Modal : Gnoga.Gui.Modal_Dialog.Dialog_Type;
Modal_View : Gnoga.Gui.View.View_Type;
Show_Dlg_Bttn : Gnoga.Gui.Element.Common.Button_Type;
Hide_Dlg_Bttn : Gnoga.Gui.Element.Common.Button_Type;
-- Add other controls here
end record;
type App_Access is access all App_Data;
<snipped>
-- Create Dialog Frame
App.Modal.Create(App.Main_Window.all);
-- Attach a view to the dialog frame
App.Modal_View.Create(App.Modal.Get_View.all);
App.Modal_View.Width(400);
App.Modal_View.Height(300);
App.Modal_View.Put_Line("Modal Dialog");
App.Hide_Dlg_Bttn.Create(App.Modal_View,"Hide Dialog");
App.Hide_Dlg_Bttn.On_Click_Handler(On_Hide_Dlg_Click'Access);
***********************************************************
Thoughts?
On Tue, May 16, 2017 at 8:34 PM, Jeremiah Breeden wrote:
> I'll mess around with it more. What I posted earlier was just stuff I did
> for local small projects, so I never spent the needed time to make them a
> more general better solution.
>
> On Tue, May 16, 2017 at 12:43 PM, Gautier de Montmollin wrote:
>
>> There is a small banana skin with the Create method: when I try to
>> extend Gnoga.Gui.View.Modal_Dialog.Dialog_Type for containing its own
>> buttons and other elements, like this:
>> <snipped>
>>
>
------------------------------------------------------------------------------
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
Gnoga-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gnoga-list