Prechádzať zdrojové kódy

Added filepathfield and optionsfield to mojox.

Mark Sibly 9 rokov pred
rodič
commit
6b688c54c6

+ 89 - 0
modules/mojox/filepathfield.monkey2

@@ -0,0 +1,89 @@
+
+#if __TARGET__<>"emscripten"
+
+Namespace mojox
+
+Class FilePathField Extends DockingView
+
+	Field FilePathChanged:Void()
+
+	Method New( path:String="",fileType:FileType=std.filesystem.FileType.File )
+	
+		_fileType=fileType
+
+		_textField=New TextField( path )
+		
+		_textField.TextChanged+=Lambda()
+		
+			FilePathChanged()
+		End
+
+		_pathButton=New PushButton( "..." )
+		
+		_pathButton.Clicked=Lambda()
+		
+			New Fiber( Lambda()
+		
+				Local future:=New Future<String>
+			
+				App.Idle+=Lambda()
+					If _fileType=FileType.Directory
+						future.Set( requesters.RequestDir( "Select Directory",_textField.Text ) )
+					Else
+						future.Set( requesters.RequestFile( "Select File",_filter,False,_textField.Text ) )
+					Endif
+				End
+				
+				Local path:=future.Get()
+				If Not path Return
+				
+				_textField.Text=path
+				
+				FilePathChanged()
+			End )
+		End
+		
+		AddView( _pathButton,"right" )
+
+		ContentView=_textField
+
+		MaxSize=New Vec2i( 320,0 )
+	End
+	
+	Property FileFilter:String()
+	
+		Return _filter
+	
+	Setter( filter:String )
+	
+		_filter=filter
+	End
+	
+	Property FilePath:String()
+	
+		Return _textField.Text
+	
+	Setter( path:String )
+	
+		_textField.Text=path
+	End
+	
+	Property FileType:FileType()
+	
+		Return _fileType
+	
+	Setter( fileType:FileType )
+	
+		_fileType=fileType
+	End
+	
+	Private
+
+	Field _filter:String	
+	Field _textField:TextField
+	Field _pathButton:PushButton
+	Field _fileType:FileType
+
+End
+
+#endif

+ 62 - 0
modules/mojox/optionsfield.monkey2

@@ -0,0 +1,62 @@
+
+Namespace mojox
+
+Class OptionsField Extends DockingView
+
+	Field CurrentChanged:Void()
+
+	Method New( options:String[],current:Int=0 )
+	
+		_options=options
+		
+		_current=current
+		
+		_group=New CheckGroup
+		
+		_group.CheckedChanged+=Lambda()
+		
+			For Local i:=0 Until _checks.Length
+				If _group.Checked=_checks[i]
+					_current=i
+					CurrentChanged()
+					Return
+				Endif
+			Next
+			
+		End
+
+		_checks=New CheckButton[options.Length]
+		
+		For Local i:=0 Until options.Length
+		
+			_checks[i]=New CheckButton( _options[i],,_group )
+			
+			AddView( _checks[i],"left" )
+		
+		Next
+		
+		_checks[_current].Checked=True
+	End
+	
+	Property Current:Int()
+	
+		Return _current
+	
+	Setter( current:Int )
+	
+		_current=current
+		
+		_checks[_current].Checked=True
+	End
+	
+	Private
+
+	Field _options:String[]
+	
+	Field _current:Int
+	
+	Field _group:CheckGroup
+	
+	Field _checks:CheckButton[]
+	
+End