Adding MojoX "view"

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.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #5328

    Hezkore
    Participant

    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?

    #5331

    nerobot
    Participant

    In 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.

    #5332

    Hezkore
    Participant

    Yeah 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.

    #5333

    nerobot
    Participant

    Right, 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.

    #5336

    Hezkore
    Participant

    Well 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.

    #5337

    nerobot
    Participant

    To 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()

    #5338

    Hezkore
    Participant

    Ah yes, thanks!
    This should really be in the documents…

    How do I get the syntax highlighter working for my custom CodeTextView?

    #5339

    nerobot
    Participant

    I looked the code. The file ted2textview.monkey2 contains needed logic

    So you should extend Ted2CodeTextView and set properly FileType property to make it works.

    Also ReadOnly=True will be good. 🙂

    #5394

    Hezkore
    Participant

    @nerobot

    I’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.

    #5401

    Hezkore
    Participant

    It’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.

    #5402

    nerobot
    Participant

    Nice work!

    About scroll. There is no such property in mojox. Try to use

    maxScroll=Max ( 0, Rect.Height-VisibleRect.Height )

    #5424

    nerobot
    Participant

    Try 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.

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.