123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- Namespace mojox
- #rem monkeydoc @hidden
- #end
- Class DialogTitle Extends Button
- Field Dragged:Void( v:Vec2i )
- Method New( text:String="" )
- Super.New( text )
-
- Style=GetStyle( "DialogTitle" )
- End
-
- Private
-
- Field _org:Vec2i
- Field _drag:Bool
- Field _hover:Bool
-
- Method OnMouseEvent( event:MouseEvent ) Override
-
- Select event.Type
- Case EventType.MouseDown
- _drag=True
- _org=event.Location
- Case EventType.MouseUp
- _drag=False
- Case EventType.MouseEnter
- _hover=True
- Case EventType.MouseLeave
- _hover=False
- Case EventType.MouseMove
- If _drag Dragged( event.Location-_org )
- End
-
- If _drag
- StyleState="active"
- Else If _hover
- StyleState="hover"
- Else
- StyleState=""
- Endif
-
- End
- End
- #rem monkeydoc The dialog class.
- #end
- Class Dialog Extends View
- #rem monkeydoc Creates a new dialog.
- #end
- Method New()
-
- Style=GetStyle( "Dialog" )
-
- _title=New DialogTitle
- _title.Dragged=Lambda( vec:Vec2i )
- Frame+=vec
- RequestRender()
- End
-
- _content=New DockingView
- _content.Style=GetStyle( "DialogContent" )
-
- _actions=New DockingView
- _actions.Style=GetStyle( "DialogActions" )
- _actions.Layout="float"
-
- _docker=New DockingView
- _docker.AddView( _title,"top" )
- _docker.ContentView=_content
- _docker.AddView( _actions,"bottom" )
-
- AddChildView( _docker )
- End
-
- Method New( title:String,contentView:View=Null )
- Self.New()
-
- Title=title
-
- If contentView ContentView=contentView
- End
-
- #rem monkeydoc Dialog title.
- #end
- Property Title:String()
-
- Return _title.Text
-
- Setter( title:String )
-
- _title.Text=title
- End
-
- #rem monkeydoc Dialog content view.
- #end
- Property ContentView:View()
-
- Return _content.ContentView
-
- Setter( contentView:View )
-
- _content.ContentView=contentView
- End
-
- #rem monkeydoc Adds an action to the dialog.
- #end
- Method AddAction( action:Action )
- Local button:=New PushButton( action )
-
- _actions.AddView( button,"left" )
- End
-
- Method AddAction:Action( label:String,icon:Image=Null )
-
- Local action:=New Action( label,icon )
- AddAction( action )
- Return action
- End
-
- #rem monkeydoc Binds an action to a key.
- #end
- Method SetKeyAction( key:Key,action:Action )
-
- _keyActions[key]=action
- End
- #rem monkeydoc Opens the dialog.
- #end
- Method Open()
- Assert( Not _window,"Dialog is already open" )
-
- _window=App.ActiveWindow
-
- Local size:=MeasureLayoutSize()
-
- Local origin:=(_window.Rect.Size-size)/2
-
- Frame=New Recti( origin,origin+size )
-
- _window.AddChildView( Self )
- End
-
- #rem monkeydoc Closes the dialog.
- #end
- Method Close()
- Assert( _window,"Dialog is not open" )
-
- _window.RemoveChildView( Self )
-
- _window=Null
- End
- #if __TARGET__<>"emscripten"
-
- #rem monkeydoc Creates and runs a modal dialog.
- #end
- Function Run:Int( title:String,view:View,actions:String[],onEnter:Int=-1,onEscape:Int=-1 )
-
- Local dialog:=New Dialog( title )
-
- dialog.ContentView=view
-
- Local future:=New Future<Int>
-
- For Local i:=0 Until actions.Length
-
- Local action:=dialog.AddAction( actions[i] )
-
- action.Triggered=Lambda()
-
- future.Set( i )
-
- End
- If i=onEnter dialog.SetKeyAction( Key.Enter,action )
-
- If i=onEscape dialog.SetKeyAction( Key.Escape,action )
- Next
-
- dialog.Open()
-
- App.BeginModal( dialog )
-
- Local result:=future.Get()
- App.EndModal()
-
- dialog.Close()
-
- Return result
- End
-
- #end
-
- Protected
-
- Method OnMeasure:Vec2i() Override
- Return _docker.LayoutSize
- End
-
- Method OnLayout() Override
- _docker.Frame=Rect
- End
-
- Method OnKeyEvent( event:KeyEvent ) Override
-
- Select event.Type
- Case EventType.KeyDown
- Local action:=_keyActions[event.Key]
- If action action.Trigger()
- End
-
- event.Eat()
- End
-
- Private
-
- Field _title:DialogTitle
- Field _content:DockingView
- Field _actions:DockingView
- Field _docker:DockingView
-
- Field _keyActions:=New Map<Key,Action>
-
- Field _window:Window
- End
- #rem monkeydoc The TextDialog class.
- #end
- Class TextDialog Extends Dialog
- #rem monkeydoc Creates a new text dialog.
- #end
- Method New( title:String="",text:String="" )
- Super.New( title )
-
- _label=New Label( text )
- _label.TextGravity=New Vec2f( .5,.5 )
-
- ContentView=_label
- End
-
- #rem monkeydoc Dialog text.
- #end
- Property Text:String()
-
- Return _label.Text
-
- Setter( text:String )
-
- _label.Text=text
- End
-
- #if __TARGET__<>"emscripten"
-
- #rem monkeydoc Creates and runs a modal text dialog.
- #end
- Function Run:Int( title:String,text:String,actions:String[],onEnter:Int=-1,onEscape:Int=-1 )
-
- Local dialog:=New TextDialog( title,text )
-
- Local result:=New Future<Int>
-
- For Local i:=0 Until actions.Length
-
- Local action:=dialog.AddAction( actions[i] )
-
- action.Triggered=Lambda()
-
- result.Set( i )
- End
-
- If i=onEnter dialog.SetKeyAction( Key.Enter,action )
-
- If i=onEscape dialog.SetKeyAction( Key.Escape,action )
-
- Next
-
- dialog.Open()
-
- App.BeginModal( dialog )
-
- Local r:=result.Get()
-
- App.EndModal()
-
- dialog.Close()
-
- Return r
- End
-
- #end
-
- Private
-
- Field _label:Label
-
- End
- #rem monkeydoc The ProgressDialog class.
- #end
- Class ProgressDialog Extends Dialog
- #rem monkeydoc Creates a new progress dialog.
- #end
- Method New( title:String="",text:String="" )
- Super.New( title )
-
- _label=New Label( text )
-
- _progress=New ProgressBar
-
- Local docker:=New DockingView
-
- docker.AddView( _label,"top" )
-
- docker.AddView( _progress,"top" )
-
- ContentView=docker
- End
-
- #rem monkeydoc Dialog text.
- #end
- Property Text:String()
-
- Return _label.Text
-
- Setter( text:String )
-
- _label.Text=text
- End
-
- Private
-
- Field _label:Label
-
- Field _progress:ProgressBar
-
- End
|