About Monkey 2 › Forums › Monkey 2 Programming Help › Adding MojoX "view"
This topic contains 11 replies, has 2 voices, and was last updated by
nerobot 2 years, 4 months ago.
-
AuthorPosts
-
November 22, 2016 at 12:35 am #5328
I haven’t quite figured out how MojoX works, is a “view” the same as a MaxGui Gadget?
And what is ContentView?
The help documents haven’t really made things any more clear either.
But I figured I’d throw myself into it by adding my own gadget.
What I’d like to do is add a special typ of scrollbar to the Ted2Go Code text known as a “code map”
Basically instead of a scroller with a knob I want the entire code to be visible on the side in a very tiny font or just squarepants colours by the highlighter and draw a big square of the part you’re currently viewing. You can then draw the square up and down to scroll through the document.
Could someone point me in the right direction to get started on this?
November 22, 2016 at 2:32 am #5331In two words..
All Views extends base class View.
You need to draw text with highlighting, so is better to extends codetextview class (from ted2go/views folder) and customize font size.
Then add this view into codedocument in place where original codetextview added.
And write custom logic in OnRender and OnContentMouseEvent.
Also need to subscribe on codeView.TextChanged event to refresh text in your codemap view.
November 22, 2016 at 3:22 am #5332Yeah that’s what I’m trying to do.
But I just get a bunch of “Error : Private member ‘RenderLine’ cannot be accessed from here”.
I can’t Override the normal TextView render function and still use its data.
And if I try to Override “RenderLine” I get ” Method ‘RenderLine:Void(mojo.graphics.Canvas,Int)’ overrides a non-virtual superclass method”.
And even if I write my OWN RenderLine() method just called RL() I still can’t access any information from the super class.
“Error : Private member ‘_textColors’ cannot be accessed from here” etc.November 22, 2016 at 3:28 am #5333Right, not all is easy as we want.
But in your case you can ‘just’ use my CodeTextView to draw codemap, only thing is to set small font.
Or maybe change canvas.scale (not sure that will works) inside on your codemap OnRender.
Monkey1234Method OnRender( canvas:Canvas )canvas.Scale=0.1Super.OnRender( canvas )EndNovember 22, 2016 at 4:10 am #5336Well I already tried that.
With canvas.Scale(0.25,0.25) not all the lines are rendered.
And if I do Self.Style.Font = Font.Load(“DejaVuSansMono.ttf”,5) it (for some reason) applies to the normal CodeTextView too.November 22, 2016 at 4:17 am #5337To avoid applying to the normal CodeTextView you should add custom style for CodeMap – add new style in ted-default.json theme and then load it in CodeMap :: New()
Monkey12345Method New()Super.New()Style=GetStyle( "CodeMap" )Style.Font = Font.Load(“DejaVuSansMono.ttf”,5)EndNovember 22, 2016 at 4:28 am #5338Ah yes, thanks!
This should really be in the documents…How do I get the syntax highlighter working for my custom CodeTextView?
November 22, 2016 at 4:38 am #5339I looked the code. The file ted2textview.monkey2 contains needed logic
Monkey12345678910111213141516171819202122232425262728293031323334353637Class Ted2CodeTextView Extends CodeTextViewProperty FileType:String() 'where else we can store this type?return _typeSetter( value:String )_type=valueKeywords = KeywordsManager.Get(_type)Highlighter = HighlightersManager.Get(_type) '<==== HEREFormatter = FormattersManager.Get(_type)Document.TextHighlighter = Highlighter.PainterEndProperty FilePath:String()return _pathSetter(value:String)_path = valueEndProtectedMethod OnKeyEvent( event:KeyEvent ) OverrideTextViewKeyEventFilter.FilterKeyEvent( event,Self,FileType )If Not event.EatenSuper.OnKeyEvent( event )EndifEndPrivateField _type:StringField _path:StringEndSo you should extend Ted2CodeTextView and set properly FileType property to make it works.
Also ReadOnly=True will be good.
November 23, 2016 at 9:05 pm #5394I’m slowly making progress.
Do you know if there’s a way to get a scrollers MAX value/distance?I want to know how far a TextView can scroll.
November 24, 2016 at 1:12 am #5401It’s working pretty good now.
You can drag the view around to scroll or click somewhere to instantly jump there.
Or you can use the mouse wheel to scroll (a bit faster than scrolling via the normal TextView)
And it updates live as you type.Word-Wrap is an issue though.
The CodeMapView needs to wrap the words at the same location as the main TextView but there doesn’t seem to be any options for stuff like that.
November 24, 2016 at 1:33 am #5402Nice work!
About scroll. There is no such property in mojox. Try to use
maxScroll=Max ( 0, Rect.Height-VisibleRect.Height )
November 25, 2016 at 2:45 am #5424Try to add codemap’s codetextview into scrollableview and set size proportional to font size. So wrapping will be the same as ‘main’ codetextview. And disable horiz scroll if needed.
-
AuthorPosts
You must be logged in to reply to this topic.