Forum Replies Created
-
AuthorPosts
-
Since v1.1.08 we can get a similar result for some cases with ?.operator :
_img?.Draw( … ) but it’s overhead in this case.
It’s a feature of extensions!
We can write “safe” methods with that. Not only checking for nulls:
Monkey1234567' extension for some our class, likeMethod GetSafelySessionId()If Not Self or session.disposed Return -1Return session.idEndBelow is an example app to see Self is Null inside of extension:
Monkey12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849Namespace myapp#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class MyWindow Extends WindowMethod New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=Null )Super.New( title,width,height,flags )EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()canvas.DrawText( "Hello World!",Width/2,Height/2,.5,.5 )_img.Draw( canvas,50,50 )EndField _img:Image ' don't assign to test extensionEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndClass Image ExtensionMethod Draw( canvas:Canvas,x:Float,y:Float )If Selfcanvas.DrawImage( Self,x,y )ElsePrint "image is null"EndifEndEndSelf can be null inside of extension.
Monkey1234567891011121314151617181920212223242526272829303132333435363738Struct Vec2<T> ExtensionOperator |:Vec2<T>( other:Vec2<T> )Return Self+otherEndEndClass Pivot FinalConst Top:=v2f( 0,0 )Const Left:=v2f( 0,0 )Const Right:=v2f( 1,0 )Const Bottom:=v2f( 0,1 )Const HCenter:=v2f( .5,0 )Const VCenter:=v2f( 0,.5 )Const Center:=HCenter|VCenterConst TopLeft:=Top|LeftConst TopCenter:=Top|HCenterConst TopRight:=Top|RightConst BottomLeft:=Bottom|LeftConst BottomCenter:=Bottom|HCenterConst BottomRight:=Bottom|RightConst LeftTop:=Left|TopConst LeftCenter:=Left|VCenterConst LeftBottom:=Left|BottomConst RightTop:=Right|TopConst RightCenter:=Right|VCenterConst RightBottom:=Right|BottomEndI finished working on drag-n-drop inside of project tree.
Now we can organize our project folder structure without leaving IDE!
There can be some minor bugs. And need to gain window focus on files dropped…
Doing that I separated draggable tabs’ logic into own class(es) to re-use it
for any drag-n-drop stuff. Including project tree.
New in Project tree:
- Drag-n-drop for moving files and folders – just hold mouse left button and drag up or down until detach item;
- Hold Ctrl key to copy item instead of move;
- Drag-n-drop files / folders from your desktop explorer directly into custom folder in Project tree – to copy items into that folder;
- If you drop folder into project tree but on empty space – it will be opened as a project;
- Drop folder outside of project tree now have no effect;
- Drop files outside of project tree will open them as usual.
See the GIF below.
Attachments:
I’ve got it!
Monkey12345678910111213141516171819202122232425262728293031323334353637383940414243Class MyWindow Extends WindowMethod New()Super.New( "Simple Mojo Gui App",640,480,WindowFlags.Resizable )Local bar:=New MenuBarLocal menuFile:=New Menu( "File" )menuFile.AddAction( "Open" )menuFile.AddAction( "Save" )Local menuView:=New Menu( "View" )menuView.AddAction( "Goto line" )bar.AddMenu( menuFile )bar.AddMenu( menuView )Local dock:=New DockingViewdock.AddView( bar,"top" )ContentView=dock' apply custom font for all Menu and MenuButtonLocal font:=Font.Load( "asset::verdana.ttf",32 )Local unusedItem:=New MenuButton( "" )SetFont( unusedItem.Style,font )Local unusedMenu:=New Menu( "" )SetFont( unusedMenu.Style,font )EndEndFunction SetFont( style:Style,font:Font )style.Font=fontFor Local i:=Eachin style.States.ValuesSetFont( i,font )NextEndStill haven’t worked out this though: How do I change the font of the menus? I can change the font of other views ok using styles but the same method doesn’t seem to be working for menus.
Monkey12345678910111213141516{"extends":"default","fonts":{"super-big-font":"DejaVuSans.ttf,34"},"styles":{"MenuButton":{"extends":"Label","font":"super-big-font"}}}minimal style’s part to change menus font.
A few helpers for vectors – I started to use them instead of New Vec2_x(...):
Monkey12345678910111213Function v2f:Vec2f( x:Float,y:Float )Return New Vec2f( x,y )EndFunction v2f:Vec2f( v:Float )Return New Vec2f( v,v )EndFunction v2i:Vec2i( x:Int,y:Int )Return New Vec2i( x,y )EndFunction v2i:Vec2i( v:Int )Return New Vec2i( v,v )EndMaybe add Property PrefferedSize:Vec2i() as an alternative way to specify view size.
and I think a REFLECTION_FILTER equivalent also needs to be added before any of this is truly useful.
I’m waiting for such filter!:)
I want to have minimal reflection where each class/interface would have its own instance for Typeof – to have comparison of them, and type should have at least Name property.
You can override OnMeasure method for MainView to set its size.
You can use MinSize and MaxSize to specify bounds. Separately or both.
Also there is a ContentView property.
And there is a Layout property. For example Layout=”float” ; Gravity=new vec2f (.5,1) – align view at x-center&y-bottom.
And you can omit size param of AddView () to use view own size.
New version 1.1.08 is coming soon. You can see what’s new on github in VERSIONS.TXT of develop branch.
Some new stuff in v2.7 (in dev branch, will be merged into master today)
- Improved autocompletion for pointer-types.
- Added -> for dereferencing pointer types (v1.1.08 is coming with that).
- Added option “Place opened document to the left side” – it helps to use “Close to the right” tabs action for earlier opened tabs.
- Improved code templates – added dot-prefixes.
- Restored logic “save all opened tabs before compilation”.
Code templates
- Use Tab or mouse-click to choose template from completion list.
- You can add/remove your own templates in Preferences — CodeTemplates section.
- Now templates showing in completion even for ‘unknown’ vars (local variables).
- Now we can specify ‘where’ to show templates by adding dot-prefixes:
- Without dots – shows only for single idents like abc
- Single dot . – shows for any idents: single like abc ; and dot-separated like abc.def
- Double dot .. – shows only for dot-separated idents like abc.def
- Dots are used just for definition not for typing in code.
Examples
Monkey123456789101112"..adc":"AddComponent<${Cursor}>()","..gec":"GetComponent<${Cursor}>()","each":"For Local ${Cursor}:=Eachin _Next",".len":"Length"(^ it’s part of json, internal presentations of templates ^)
If we typed on a new line adc we can’t see ..adc template in completion because double-dots prefix require instanse.
But abrakadabra.a shows us adc template in the list, and we can insert AddComponent<>() by pressing Tab.
.len will work for both len and arr.len cases.
And each template will work when it typed as a single ident and will don’t work for myVar.each.
It’s useful for me, and you?
#define with #if
Monkey12345#if win64#define size_t long#else#define size_t int#endifIs there way to disable simulation for custom body?
I tried to use body.sleep function but got runtime error.
Will try to temporarily remove body from world.
EDIT: I found solution.
Monkey123456cpBodySetType(cpBody, cpBodyType)Const CP_BODY_TYPE_DYNAMIC:cpBodyTypeConst CP_BODY_TYPE_KINEMATIC:cpBodyTypeConst CP_BODY_TYPE_STATIC:cpBodyType'body.Type=CP_BODY_TYPE_KINEMATIC ' ** BUT crashes app if there is no shapes attached yet! ** -
AuthorPosts
