Label.st
branchjv
changeset 5808 ed5f9b2098ea
parent 5760 9a0b5601b3f4
parent 5782 0a043d77cff7
child 5809 a5cecde02b21
equal deleted inserted replaced
5776:74d9c599d5d1 5808:ed5f9b2098ea
    90 
    90 
    91 
    91 
    92     model operation (ST-80 style):
    92     model operation (ST-80 style):
    93       labels with a model, aspectMsg and labelMsg react to 
    93       labels with a model, aspectMsg and labelMsg react to 
    94       changes of the aspect, and send a labelMsg-message 
    94       changes of the aspect, and send a labelMsg-message 
    95       to the model in order to aquire a new labelString or image.
    95       to the model in order to acquire a new labelString or image.
    96       The model should send 'self changed:aspectMsg' if it thinks the label 
    96       The model should send 'self changed:aspectMsg' if it thinks the label 
    97       should change and return a string or image from the labelMsg-message.
    97       should change and return a string or image from the labelMsg-message.
    98 
    98 
    99         label model:aModel.
    99         label model:aModel.
   100         label aspect:aspectSymbol.
   100         label aspect:aspectSymbol.
   138         fixSize             <Boolean>       if true, a change of the logo change will not
   138         fixSize             <Boolean>       if true, a change of the logo change will not
   139                                             resize the label; otherwise, its size is adjusted.
   139                                             resize the label; otherwise, its size is adjusted.
   140                                             default:false.
   140                                             default:false.
   141 
   141 
   142         labelMsg            <Symbol>        if non-nil, this is sent to the model to
   142         labelMsg            <Symbol>        if non-nil, this is sent to the model to
   143                                             aquire the labelString or labelImage.
   143                                             acquire the labelString or labelImage.
   144                                             If nil, the label stays as is
   144                                             If nil, the label stays as is
   145 
   145 
   146     [styleSheet parameters:]
   146     [styleSheet parameters:]
   147 
   147 
   148       labelForegroundColor    <Color>         color to draw foreground pixels (i.e. the string)
   148       labelForegroundColor    <Color>         color to draw foreground pixels (i.e. the string)
   632         ...
   632         ...
   633 
   633 
   634 
   634 
   635     concrete example (track a counters value):
   635     concrete example (track a counters value):
   636       (here, the default aspect #value is used both to notify the label about
   636       (here, the default aspect #value is used both to notify the label about
   637        changes and to aquire a new value from the model).
   637        changes and to acquire a new value from the model).
   638                                                                         [exBegin]
   638                                                                         [exBegin]
   639         |top l model|
   639         |top l model|
   640 
   640 
   641         model := ValueHolder new.
   641         model := ValueHolder new.
   642         model value:'0'.
   642         model value:'0'.
  1302 
  1302 
  1303     converter := aConverter
  1303     converter := aConverter
  1304 !
  1304 !
  1305 
  1305 
  1306 labelMessage 
  1306 labelMessage 
  1307     "return the symbol used to aquire the labelString/image from the model
  1307     "return the symbol used to acquire the labelString/image from the model
  1308      when the aspect changes.
  1308      when the aspect changes.
  1309      The default is nil, which means: leave the label unchanged."
  1309      The default is nil, which means: leave the label unchanged."
  1310 
  1310 
  1311     ^ labelMsg
  1311     ^ labelMsg
  1312 !
  1312 !
  1313 
  1313 
  1314 labelMessage:aSymbol 
  1314 labelMessage:aSymbol 
  1315     "set the symbol used to aquire the labelString/image from the model.
  1315     "set the symbol used to acquire the labelString/image from the model.
  1316      The default is nil, which means: leave the label unchanged."
  1316      The default is nil, which means: leave the label unchanged."
  1317 
  1317 
  1318     labelMsg ~~ aSymbol ifTrue:[
  1318     labelMsg ~~ aSymbol ifTrue:[
  1319 	labelMsg := aSymbol.
  1319         labelMsg := aSymbol.
  1320 	self getLabelFromModel
  1320         self getLabelFromModel
  1321     ]
  1321     ]
  1322 !
  1322 !
  1323 
  1323 
  1324 model:aModel
  1324 model:aModel
  1325     super model:aModel.
  1325     super model:aModel.
  1801     "ask my model for the label to show.
  1801     "ask my model for the label to show.
  1802      Here, we use labelMsg (instead of aspectMsg). 
  1802      Here, we use labelMsg (instead of aspectMsg). 
  1803      This allows multiple labels to react on the same aspect, 
  1803      This allows multiple labels to react on the same aspect, 
  1804      but show different labels when changed 
  1804      but show different labels when changed 
  1805      (also, since labelMsg defaults to nil, constant labels
  1805      (also, since labelMsg defaults to nil, constant labels
  1806       which have a nil labelMsg will not try to aquire a labelString)."
  1806       which have a nil labelMsg will not try to acquire a labelString)."
  1807 
  1807 
  1808     |val|
  1808     |val|
  1809 
  1809 
  1810     (model notNil 
  1810     (model notNil 
  1811     and:[labelMsg notNil]) ifTrue:[
  1811     and:[labelMsg notNil]) ifTrue:[
  1812 	val := model perform:labelMsg.
  1812         val := model perform:labelMsg.
  1813 	converter notNil ifTrue:[
  1813         converter notNil ifTrue:[
  1814 	    val := converter printStringFor:val
  1814             val := converter printStringFor:val
  1815 	].
  1815         ].
  1816 	self label:val.
  1816         self label:val.
  1817     ].
  1817     ].
  1818 !
  1818 !
  1819 
  1819 
  1820 newLayout
  1820 newLayout
  1821     "recompute position/size after a change
  1821     "recompute position/size after a change