On 02 Apr 2014, at 12:10, Thomas Bany <mun.sys...@gmail.com> wrote: > Hi ! > > First, I apologyse for the wall of text. > > I'm trying my hands at Spec and I have few questions: > How can I implement an instance-dependent layout ? The usual solution is to have a method looking like this on instance side
rebuildMyLayout | layout | layout := self buildStateDependentLayout. self buildWithLayout: layout. buildStateDependentLayout ^ SpecLayout composed etc... > Regarding the layout method lookup, the documentation states that it "starts > on instance side, which allows a UI to have a more specific layout depending > on the state of the instance" > > I tried to simply put a layout in an instance method with the <spec: > #default> pragma. But not only was it not retrieved by > ComposableModel>#defaultSpecSelector but ComposableModel>#retrieveSpec: will > send the selector on the class anyway. > > What I ended up doing was overiding #openWithSpec (which worked) but I'm > pretty sure that my model is not composable at all. Indeed, overriding openWithSpec may be a bit hackish, but should still work :) Another solution could be to override defaultSpecSelector and/or retrieveSpec: > Is it possible to change the "skin" of the basic widget ? The hooks are basically here, but the Morphs have an issue with this. The “skin” of a Morph is supposed to be immutable, hence it takes back its default value at each refresh :S > > I would like to implement some sort of toggle button by changing the color of > ButtonModel and so far, I failed. I was not able to trace my color change up > to the PluggableButtonMorph because it seems to use anoucement and I'm a > Smalltalk rookie. > > I tried however to send #color: directly to the morph which does nothing: the > #changed method rolls it back to its previous value. So I may be doing > something wrong but it doesn't feel like the issue comes from Spec. Any clue ? > So far, it will not work, sorry :( > On a side note, I tried to send an argument to the selector that retrieve a > widget in the layout method. > And I came up with this : > > layout add: {#buttonAt: . 1}; add: {#buttonAt: . 2}; add: {#buttonAt: . 3} > > Is it how it's done ? That’s a solution. Then if you have a fixed number of buttons, you could also implement a getter for each. If you have an undetermined number of button, then DynamicComposableModel is for you. > Thanks in advance ! You are welcome :) Ben