3 ObjectGui : SCViewHolder {
5 this is a controller class:
6 it creates the views and implements the relationship between them and the model
7 model: the object for which this is a graphical user interface
8 view: this.view is the flow view (aka the arg layout) that is passed to guiBody
9 individual views/widgets are placed in it and their actions talk to either this object or the model
11 var <model,<dragSource;
13 guiBody { arg layout,bounds ... args;
14 /* implement this method in your gui subclass */
16 // if your model implement guiBody then call that
17 // this is a lazy way to write simple guis for simple objects
18 // where model/gui code separation is not especially important
19 // and where the controller class doesn't need to maintain any state or vars
20 if(model.respondsTo(\guiBody) and: {model.isKindOf(ObjectGui).not},{
21 model.guiBody(layout,bounds,*args)
32 gui { arg parent, bounds ... args;
34 layout=this.guify(parent,bounds);
35 layout.flow({ arg layout;
37 this.writeName(layout);
38 this.performList(\guiBody,[layout,bounds] ++ args);
39 },bounds).background_(this.background);
40 //if you created it, front it
42 layout.resizeToFit(true,true);
46 guify { arg parent,bounds,title;
47 // converts the parent to a FlowView or compatible object
48 // thus creating a window from nil if needed
49 // registers to remove self as dependent on model if window closes
51 bounds = bounds.asRect;
54 parent = PageLayout(title ?? {model.asString.copyRange(0,50)},bounds,front:false);
56 parent = parent.asPageLayout(bounds);
58 // i am not really a view in the hierarchy
59 parent.removeOnClose(this);
63 if(model.notNil,{ // a view has its model swapped with another
64 model.removeDependant(this);
66 model.addDependant(this);
70 model.addDependant(this);
74 model.removeDependant(this);
79 background { ^Color.clear }
82 this.prWriteName(layout,model.asString)
84 prWriteName { arg layout,name;
86 font = GUI.font.new(*GUI.skin.fontSpecs);
87 string = " " ++ (name);
89 string = string.copyRange(0,40) ++ "...";
91 dragSource = GUI.dragSource.new(layout,Rect(0,0,(string.bounds(font).width + 10).max(70),GUI.skin.buttonHeight))
92 .stringColor_(Color.new255(70, 130, 200))
94 .background_(Color.white)
96 .beginDragAction_({ model })