Rendering to views in mojox

About Monkey 2 Forums Monkey 2 Programming Help Rendering to views in mojox

Tagged: 

This topic contains 14 replies, has 4 voices, and was last updated by  peterigz 1 year ago.

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #11362

    peterigz
    Participant

    I’m just getting into using mojox and getting to grips with how views work etc.

    I can’t figure out why the following code doesn’t render anything in the WorldView, I’m sure it’s something obvious but any ideas what I’m doing wrong?

    Thanks!

    #11363

    Hezkore
    Participant

    You may need RequestRender() inside of the Windows OnRender method and not your View.

    #11368

    peterigz
    Participant

    After a bit of experimenting, this seemed to work ok:

    If I used “100%” with “top” then that would work but the height would be set to the height of the window, not the remaining space. Not sure how you get it to set the height to the remaining space only. Not specifying any size at all meant the size was basically 0. Don’t know if that’s correct behaviour or not or if there’s some other things that I’m missing.

    #11371

    nerobot
    Participant

    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.

    #11373

    Mark Sibly
    Keymaster

    Change this…

    MainView.AddView(WorldDoc, "top")

    …to this…

    MainView.ContentView=WorldDoc

    The problem here is that ‘border’ views added to a DockingView (ie: views added via AddView, not the ContentView) should implement the OnMeasure method, as this is how the docking view knows how high (for top/bottom views) or wide (for left/right views) the border views should be for layout.

    The ContentView of a DockingView does not actually need to implement OnMeasure as it gets all the remaining space once the border top/bottom/left/right views are added. The size of the ContentView as returned by OnMeasure is effectively ignored.

    I think OnMeasure might return 0,0 by default. It’d probaby be better if it returned 16,16 or something else non-null so in cases like this at least something gets rendered.

    #11374

    nerobot
    Participant

    Maybe add Property PrefferedSize:Vec2i()  as an alternative way to specify view size.

    #11387

    peterigz
    Participant

    Thanks Mark, that makes a bit more sense now.

    #11393

    peterigz
    Participant

    Is there an event that I can hook into that I can initialise certain things after the width and height of the view has been calculated?

    At the moment if I try and set something up where I need to know the calculated width and height of the view I can’t put it in New() because width and height are both 0 at that point. OnLayout seems to be called every frame. I’ll also need something like OnResize for when the window/view is resized. Or is it just a case of checking manually if the width/height have changed?

    Edit: sorry might have lot’s of questions about mojox! 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.

    #11401

    Mark Sibly
    Keymaster

    Have a look at this thread for a similar discussion re: mojox and how layout works in general (near the end).

    MojoX GUI questions

    Use window method UpdateWindow( False ) in window ctor to force a full window layout which will update all view sizes. Views aren’t normally resized until just before rendering during a layout phase – more info here:

    http://monkeycoder.co.nz/forums/reply/10228/

    In general, mojox is designed to automate layout as much as possible, making it highly reactive. However, people who are used to maxgui etc and having to do layout ‘by hand’ might find it a bit confusing.

    How do I change the font of the menus?

    There may actually be no programmatic way to do that right now, I will have a closer look at some point. You should be able to do this by setting the MenuButton{} style in a theme file though. I would actually recommend using a theme file anyway, but it really should be possible to set menu button font programmatically too.

    #11408

    peterigz
    Participant

    Thanks, I had seen that thread but didn’t notice the stuff about layout. So basically use a flag for the initial layout, that’s fair enough.

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

    #11410

    nerobot
    Participant

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

    minimal style’s part to change menus font.

    #11412

    peterigz
    Participant

    Thanks nerobot. I was just trying to do this in code like:

    Can you do it like that? I tried on the menu and menu bar but nothing changed. I know the font is loaded ok because the same code is working on the render view.

    #11414

    nerobot
    Participant

    I’ve got it! 🙂

    #11421

    Mark Sibly
    Keymaster

    Yuck! But it works…

    What’s probably needed is something like SetStyle in the Theme class, so you can programmatically set any style used by the gui internals that you don’t get to directly create, like MenuButton etc. Will look into adding this.

    A theme json file is still IMO the best way to do all styling…

    (hmm…does F1 no longer show docs? It shows the status bar quick-help but it used to open actual docs I think?)

    #11423

    peterigz
    Participant

    Thanks Nerobot/Mark, I guess I should look into doing it via a theme instead then,  that looks like the cleanest way of doing it.

    And yes I noticed that F1 doesn’t always show the docs (sometimes it does work though)

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

You must be logged in to reply to this topic.