About Monkey 2 › Forums › Monkey 2 Programming Help › Create a CustomView and add it into a DockingView
This topic contains 4 replies, has 2 voices, and was last updated by
cocon 1 year, 3 months ago.
-
AuthorPosts
-
January 1, 2018 at 12:05 am #12540
Do you know how can I create my own view class and add GUI elements to it?
[Old Code Deleted]
January 1, 2018 at 12:03 pm #12548Try to add in constructor of CustomView:
Monkey1Layout="fill"And possibly right there:
dockingView.Layout=”fill”
January 1, 2018 at 3:56 pm #12549Hi Nerobot, I had a look at the monkey examples and I figured out that by looking at the “stargate.monkey2” example.
Monkey1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859#import "<std>"#import "<mojo>"#import "<mojox>"Using std..Using mojo..Using mojox..Class CustomView Extends ViewMethod New(a:String, b:String)Local dockingView := New DockingViewdockingView.AddView( New Button( a ),"top","50%" )dockingView.AddView( New Button( b ),"bottom","50%" )AddView( dockingView )EndMethod AddView( view:View )AddChildView( view )_views.Push( view )EndMethod RemoveView( view:View )RemoveChildView( view )_views.Remove( view )EndMethod OnLayout() OverrideFor Local view:=Eachin _viewsview.Frame = RectNextEndField _views:=New Stack<View>EndClass MyWindow Extends WindowMethod New()Super.New( "DockingView Demo",640,480,WindowFlags.Resizable )Local dockingView:=New DockingViewdockingView.AddView( New CustomView("LEFT 1", "LEFT 2"),"left","50%" )dockingView.AddView( New CustomView("RIGHT 1", "RIGHT 2"),"right","50%" )ContentView=dockingViewEndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndThis is a reimplementation of what other GUI elements do, such as the Label or something else. For example instead of managing the stack with the views myself I found that I can extend the label and have the same idea.
I think that a new GUI element to be added to mojox, for example currently the hierarchy goes like this: View > Label, View > Button, then this new element would be done like this, View > ViewComponent.
How it should be named? i.e: ViewComponent, ViewNode, ViewControl, etc.
January 1, 2018 at 6:01 pm #12550Naming depends on what that component will do.
I don’t understand what do you want to achieve here. Kind of container? But we already have DockingView as a good container.
January 1, 2018 at 6:38 pm #12551Oh, you ‘re saying that I would just use DockingView instead.
It seems that this is what works best.
Monkey123456789101112131415161718192021222324252627282930313233343536#import "<std>"#import "<mojo>"#import "<mojox>"Using std..Using mojo..Using mojox..Class CustomView Extends DockingViewMethod New(a:String, b:String)Local b1 := New Button( a )Local b2 := New Button( b )AddView( b1 ,"top","50%" )AddView( b2 ,"bottom","50%" )EndEndClass MyWindow Extends WindowMethod New()Super.New( "DockingView Demo",640,480,WindowFlags.Resizable )Local dockingView:=New DockingViewdockingView.AddView( New CustomView("LEFT 1", "LEFT 2"),"left","50%" )dockingView.AddView( New CustomView("RIGHT 1", "RIGHT 2"),"right","50%" )ContentView=dockingViewEndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndHopefully all of these snippets posted into this forum will be used to create a nice collection of examples.
-
AuthorPosts
You must be logged in to reply to this topic.