About Monkey 2 › Forums › Monkey 2 Programming Help › Creating custom dialogs.
Tagged: dialog mojox
This topic contains 2 replies, has 2 voices, and was last updated by
TurkeyLurker 1 year, 6 months ago.
-
AuthorPosts
-
October 4, 2017 at 5:56 am #10959
I’m currently working on a project to develop a gui application but I can’t figure out modal dialogs. I get as far as actually running a custom dialog, but after searching through ted2 source I simply don’t quite get how to customize a dialog. Here is my basic code:
[/crayon]Monkey1234567891011121314151617181920212223242526272829303132333435363738394041424344454647[crayon-5cba95327e189737929361 inline="true" ]Namespace dlghelp#Import "<std>"#Import "<mojo>"#Import "<mojox>"Using std..Using mojo..Using mojox..Class MainWindow Extends WindowField _mdlg:MyModalDialog = NullMethod New()Super.New( "Dialog Help",640,480,WindowFlags.Resizable )Local label:=New Label( "Idle" )label.Gravity=New Vec2f( .5,0 )Local button:=New Button( "Click ME!" )button.Clicked=Lambda()New Fiber( Lambda()Local iresult:Int = MyModalDialog.Run("Title",Null,New String[]("Ok","Cancel"), 0, 0)End )EndLocal dockingView:=New DockingViewdockingView.AddView( label,"top" )dockingView.ContentView=buttonContentView=dockingViewEndEndClass MyModalDialog Extends Dialog' I want to change the size of the dialog and add buttons and text fields' but I don't know how. :)End ClassFunction Main:Void()New AppInstanceNew MainWindowApp.Run()End FunctionOctober 4, 2017 at 9:18 am #10967Dialogs have a ContentView property which is where you put the ‘contents’ of the dialog (which is often itself a DockingView that contains other views, or a list view etc) and you can use Dialog.AddAction to add “Okay”,”Cancel” etc buttons/actions.
Open() and Close() are used to show/hide the dialog, and you can use fibers to ‘block’ until the dialog has closed (although you don’t have to).
Here’s a minimal example:
Monkey12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576#Import "<std>"#Import "<mojo>"#Import "<mojox>"Using std..Using mojo..Using mojox..Class MyDialog Extends DialogField result:=New Future<Int>Method New()Title="Dialog Title"Local label:=New Label( "Content of the dialog goes here" )label.TextGravity=New Vec2f( .5,.5 ) 'center the textContentView=labelMinSize=New Vec2i( 160,120 ) 'dialog has a MinSizeAddAction( "Okay" ).Triggered=Lambda()result.Set( 1 )EndAddAction( "Cancel" ).Triggered=lambda()result.Set( 0 )EndEndMethod Run:Int()Open()Local r:=result.Get()Close()Return rEndEndClass MyWindow Extends WindowMethod New()Super.New( "Simple Mojo Gui App",640,480,WindowFlags.Resizable )Local button:=New Button( "Create Dialog" )button.Clicked=Lambda()New Fiber( lambda()Local dialog:=New MyDialogLocal r:=dialog.Run()TextDialog.Run( "MyDialog result","MyDialog result="+r,New String[]( "Okay" ) )End )EndContentView=buttonEndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndOctober 4, 2017 at 9:29 am #10970Thanks Mark! This puts me on the right path.
-
AuthorPosts
You must be logged in to reply to this topic.