Hello guys,
thinking, how to easily define styles, based on simple selection rules, i sketched the class, MorphStyle. The principle how it works is simple: - you creating a style, add adding actions to it - you then applying style to morph or group of morphs. Example: | style | style := MorphStyle new submorphs model: #Browser; color: Color red. style applyTo: World. Let me describe in detail, what it does, when you applying it: style applyTo: World. Style initializing its current selection to be a collection with single element - { World }. Next thing, which it does is applying any actions , which we specified during building the style, namely: 'submorphs' - replacing the current selection by gathering all submorphs of it, i.e. selection before: #( World ) selection after: #( World's submorphs ) 'model: #Browser' - filter the current selection and leave only those entries, which respond to #model and model class name is #Browser selection before: #( world's submorphs ) selection after: { Browser SystemWindow#1. Browser SystemWindow#2. Browser SystemWindow#3.Browser SystemWindow#4. } 'color: Color red'. - since there's no such method in MorphStyle, it is trapped by DNU handler and converted to a #sendMessage: action. A #sendMessage: action sends a specified message to current selection, i.e.: { Browser SystemWindow#1. .... Browser SystemWindow#N. } do: [:morph | message sendTo: morph ]. So, as result, if you doIt : | style | style := MorphStyle new submorphs model: #Browser; color: Color red. style applyTo: World. all browser windows color will be changed to red color. Some words about potential uses of this stuff. - theming, (through defining own style sheets). In contrast to existing implementation, we're free to define anything, which morph understands , not just colors, border or fillstyle, but also, layout, fonts, position etc etc. - defining styles in various ways: following snippet sets the 'browse' button color to red for all browser windows and illustrating how one style could reuse another one. | browseButton buttonStyle browsers | buttonStyle := MorphStyle new color: Color blue. browseButton := MorphStyle new allSubmorphs; has: #label equalTo: 'browse'. browsers := MorphStyle new model: #Browser. browseButton style: buttonStyle. "browseButton reusing buttonStyle" browsers style: browseButton. "browser style reusing browseButton style" browsers applyTo: World submorphs. It can be easily integrated with Morphic when using some global theme, all we need is: - add Morph>>applyThemeStyles ^ World currentTheme applyStylesTo: self - send #applyStyles to morph, when its added to World. Also, we could integrate it with toolbuilder which will allow us to define morph layouts, fonts, colors & initial properties more flexibly than currently are . Non-morphic builders could just ignore the #setStyles: message. Comments, suggestions , as always welcome. -- Best regards, Igor Stasenko AKA sig. MorphStyle.st (5K) Download Attachment |
Free forum by Nabble | Edit this page |