The Trunk: Morphic-mt.891.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Morphic-mt.891.mcz

commits-2
Marcel Taeumel uploaded a new version of Morphic to project The Trunk:
http://source.squeak.org/trunk/Morphic-mt.891.mcz

==================== Summary ====================

Name: Morphic-mt.891
Author: mt
Time: 17 April 2015, 12:13:43.291 am
UUID: 0fbb53cb-5750-2245-ad81-db3dab199a01
Ancestors: Morphic-mt.890

Simplified button morphs. Allow them to shrink to a very narrow size. Only draw the first letter of the label then. Still, balloonTexts can give more information on the button. (Icons possible.)

Also modifies UserDialogBoxMorph to be aware that buttons now can shrink quite a bit.

=============== Diff against Morphic-mt.890 ===============

Item was changed:
  AlignmentMorph subclass: #PluggableButtonMorph
+ instanceVariableNames: 'model label font getStateSelector actionSelector getLabelSelector getMenuSelector shortcutCharacter askBeforeChanging triggerOnMouseDown offColor onColor feedbackColor showSelectionFeedback allButtons arguments argumentsProvider argumentsSelector style'
- instanceVariableNames: 'model label getStateSelector actionSelector getLabelSelector getMenuSelector shortcutCharacter askBeforeChanging triggerOnMouseDown offColor onColor feedbackColor showSelectionFeedback allButtons arguments argumentsProvider argumentsSelector style'
  classVariableNames: 'GradientButton RoundedButtonCorners'
  poolDictionaries: ''
  category: 'Morphic-Pluggable Widgets'!
 
  !PluggableButtonMorph commentStamp: '<historical>' prior: 0!
  A PluggableButtonMorph is a combination of an indicator for a boolean value stored in its model and an action button. The action of a button is often, but not always, to toggle the boolean value that it shows. Its pluggable selectors are:
 
  getStateSelector fetch a boolean value from the model
  actionSelector invoke this button's action on the model
  getLabelSelector fetch this button's lable from the model
  getMenuSelector fetch a pop-up menu for this button from the model
 
  Any of the above selectors can be nil, meaning that the model does not supply behavior for the given action, and the default behavior should be used. For example, if getStateSelector is nil, then this button shows the state of a read-only boolean that is always false.
 
  The model informs its view(s) of changes by sending #changed: to itself with getStateSelector as a parameter. The view tells the model when the button is pressed by sending actionSelector.
 
  If the actionSelector takes one or more arguments, then the following are relevant:
  arguments A list of arguments to provide when the actionSelector is called.
  argumentsProvider The object that is sent the argumentSelector to obtain arguments, if dynamic
  argumentsSelector The message sent to the argumentProvider to obtain the arguments.
 
  Options:
  askBeforeChanging have model ask user before allowing a change that could lose edits
  triggerOnMouseDown do this button's action on mouse down (vs. up) transition
  shortcutCharacter a place to record an optional shortcut key
  !

Item was added:
+ ----- Method: PluggableButtonMorph>>drawBackgroundOn: (in category 'drawing') -----
+ drawBackgroundOn: aCanvas
+ | cc gradient borderColor fill |
+ cc := self color.
+ cc isTransparent ifTrue:[cc := Color gray: 0.9].
+ self enabled ifFalse:[cc := Color lightGray].
+ cc brightness > 0.9 ifTrue:[cc := cc adjustBrightness: 0.9 - cc brightness].
+ showSelectionFeedback ifTrue:[
+ borderColor := cc muchDarker.
+ gradient := GradientFillStyle ramp: {
+ 0.0 -> cc muchDarker.
+ 0.1-> (cc adjustBrightness: -0.2).
+ 0.5 -> cc.
+ 0.9-> (cc adjustBrightness: -0.1).
+ 1 -> cc muchDarker}.
+ cc := cc muchDarker.
+ ] ifFalse:[
+ borderColor := Color lightGray.
+ gradient := GradientFillStyle ramp: {
+ 0.0 -> Color white.
+ 0.1-> (cc adjustBrightness: 0.05).
+ 0.6 -> (cc darker)}.
+ ].
+ gradient origin: bounds topLeft.
+ gradient direction: 0@self height.
+
+ PluggableButtonMorph gradientButton
+ ifFalse: [fill := SolidFillStyle color: cc]
+ ifTrue: [fill := gradient].
+
+ ^ self wantsRoundedCorners
+ ifTrue: [aCanvas
+ frameAndFillRoundRect: bounds
+ radius: self class preferredCornerRadius
+ fillStyle: fill
+ borderWidth: 1
+ borderColor: borderColor]
+ ifFalse: [aCanvas
+ frameAndFillRectangle: self innerBounds
+ fillColor: fill asColor
+ borderWidth: 1
+ borderColor: borderColor darker;
+ fillRectangle: (self innerBounds insetBy: 1)
+ fillStyle: fill]!

Item was added:
+ ----- Method: PluggableButtonMorph>>drawLabelOn: (in category 'drawing') -----
+ drawLabelOn: aCanvas
+
+ | fontToUse labelToUse labelWidth |
+ label ifNil: [^ self].
+
+ label isMorph ifTrue: [
+ label privateFullMoveBy: (self center - label center).
+ aCanvas fullDrawMorph: label.
+ ^ self].
+
+ labelToUse := label asString.
+ fontToUse := font ifNil: [Preferences standardButtonFont].
+
+ "Support very narrow buttons."
+ (self width < ((fontToUse widthOf: $m)*4) and: [labelToUse size > 3]) ifTrue: [
+ labelToUse := label first asString. "Show first character only."
+ fontToUse := fontToUse emphasized: (TextEmphasis bold) emphasisCode].
+
+ labelWidth := fontToUse widthOfString: labelToUse.
+
+ aCanvas
+ drawString: labelToUse
+ at: (self center x - (labelWidth //2) max: (self left + 2)) @ (self center y - (fontToUse height //2))
+ font: fontToUse
+ color: Color black.
+ !

Item was changed:
  ----- Method: PluggableButtonMorph>>drawOn: (in category 'drawing') -----
  drawOn: aCanvas
- | cc gradient borderColor fill |
- cc := self color.
- cc isTransparent ifTrue:[cc := Color gray: 0.9].
- self enabled ifFalse:[cc := Color lightGray].
- cc brightness > 0.9 ifTrue:[cc := cc adjustBrightness: 0.9 - cc brightness].
- showSelectionFeedback ifTrue:[
- borderColor := cc muchDarker.
- gradient := GradientFillStyle ramp: {
- 0.0 -> cc muchDarker.
- 0.1-> (cc adjustBrightness: -0.2).
- 0.5 -> cc.
- 0.9-> (cc adjustBrightness: -0.1).
- 1 -> cc muchDarker}.
- cc := cc muchDarker.
- ] ifFalse:[
- borderColor := Color lightGray.
- gradient := GradientFillStyle ramp: {
- 0.0 -> Color white.
- 0.1-> (cc adjustBrightness: 0.05).
- 0.6 -> (cc darker)}.
- ].
- gradient origin: bounds topLeft.
- gradient direction: 0@self height.
 
+ self drawBackgroundOn: aCanvas.
+
+ aCanvas
+ clipBy: (self bounds insetBy: (2@0 corner: 2@0))
+ during: [:c | self drawLabelOn: c].!
- PluggableButtonMorph gradientButton
- ifFalse: [fill := SolidFillStyle color: cc]
- ifTrue: [fill := gradient].
-
- ^ self wantsRoundedCorners
- ifTrue: [aCanvas
- frameAndFillRoundRect: bounds
- radius: self class preferredCornerRadius
- fillStyle: fill
- borderWidth: 1
- borderColor: borderColor]
- ifFalse: [aCanvas
- frameAndFillRectangle: self innerBounds
- fillColor: fill asColor
- borderWidth: 1
- borderColor: borderColor darker;
- fillRectangle: (self innerBounds insetBy: 1)
- fillStyle: fill]!

Item was changed:
  ----- Method: PluggableButtonMorph>>label:font: (in category 'accessing') -----
  label: aStringOrTextOrMorph font: aFont
  "Label this button with the given string or morph."
 
+ font := aFont.
+ label := aStringOrTextOrMorph isText
+ ifTrue: [aStringOrTextOrMorph asMorph]
+ ifFalse: [aStringOrTextOrMorph].
+ self changed.
+ !
- | r |
- self removeAllMorphs.
- "nest label in a row for centering"
- r := AlignmentMorph newRow
- borderWidth: 0;
- layoutInset: 0;
- color: Color transparent;
- hResizing: #shrinkWrap;
- vResizing: #spaceFill;
- wrapCentering: #center; cellPositioning: #leftCenter.
- aStringOrTextOrMorph isMorph
- ifTrue: [
- label := aStringOrTextOrMorph.
- r addMorph: aStringOrTextOrMorph]
- ifFalse: [
- label := aStringOrTextOrMorph asString.
- r addMorph: (StringMorph contents: label font: aFont)].
- self addMorph: r.
- !

Item was added:
+ ----- Method: PluggableButtonMorph>>minExtent (in category 'geometry') -----
+ minExtent
+
+ ^ label isMorph
+ ifTrue: [label minExtent]
+ ifFalse: [16@16]!

Item was changed:
  ----- Method: UserDialogBoxMorph class>>confirm:orCancel:title:at: (in category 'utilities') -----
  confirm: aString orCancel: cancelBlock title: titleString at: aPointOrNil
 
  ^(self new
  title: titleString;
  label: aString;
+ addSelectedButton: 'Yes' translated value: true;
+ addButton: 'No' translated  value: false;
+ addCancelButton: 'Cancel' translated  value: nil;
- addSelectedButton: '       Yes       ' translated value: true;
- addButton: '        No        ' translated  value: false;
- addCancelButton: '     Cancel     ' translated  value: nil;
  runModalIn: ActiveWorld forHand: ActiveHand at: aPointOrNil)
  ifNil: [ cancelBlock value ]!

Item was changed:
  ----- Method: UserDialogBoxMorph class>>confirm:title:at: (in category 'utilities') -----
  confirm: aString title: titleString at: aPointOrNil
  "UserDialogBoxMorph confirm: 'Make your choice carefully' withCRs title: 'Do you like chocolate?'"
  ^self new
  title: titleString;
  label: aString;
+ addSelectedButton: 'Yes' translated value: true;
+ addCancelButton: 'No' translated  value: false;
- addSelectedButton: '       Yes       ' translated value: true;
- addCancelButton: '        No        ' translated  value: false;
  runModalIn: ActiveWorld forHand: ActiveHand at: aPointOrNil!

Item was changed:
  ----- Method: UserDialogBoxMorph class>>confirm:title:trueChoice:falseChoice:at: (in category 'utilities') -----
  confirm: aString title: titleString trueChoice: trueChoice falseChoice: falseChoice at: aPointOrNil
  "UserDialogBoxMorph confirm: 'Make your choice carefully' withCRs title: 'Do you like chocolate?' trueChoice: 'Oh yessir!!' falseChoice: 'Not so much...'"
  ^self new
  title: titleString;
  label: aString;
+ addSelectedButton: trueChoice translated value: true;
+ addCancelButton: falseChoice translated value: false;
- addSelectedButton: '   ', trueChoice translated, '   ' value: true;
- addCancelButton: '   ', falseChoice translated, '   '  value: false;
  runModalIn: ActiveWorld forHand: ActiveHand at: aPointOrNil!

Item was changed:
  ----- Method: UserDialogBoxMorph class>>confirm:title:trueChoice:falseChoice:default:triggerAfter:at: (in category 'utilities') -----
  confirm: aString title: titleString trueChoice: trueChoice falseChoice: falseChoice default: default triggerAfter: seconds at: aPointOrNil
  "UserDialogBoxMorph confirm: 'I like hot java' title: 'What do you say?' trueChoice: 'You bet!!' falseChoice: 'Nope' default: false triggerAfter: 12 at: 121@212"
  ^self new
  title: titleString;
  label: aString;
+ addButton: trueChoice translated value: true selected: default performActionOnEscape: false;
+ addButton: falseChoice translated value: false selected: default not performActionOnEscape: true;
- addButton: '   ', trueChoice translated, '   ' value: true selected: default performActionOnEscape: false;
- addButton: '   ', falseChoice translated, '   ' value: false selected: default not performActionOnEscape: true;
  triggerAfter: seconds;
  runModalIn: ActiveWorld forHand: ActiveHand at: aPointOrNil!

Item was changed:
  ----- Method: UserDialogBoxMorph class>>inform:title:at: (in category 'utilities') -----
  inform: aString title: titleString at: aPointOrNil
  "UserDialogBoxMorph inform: 'Squeak is great!!' title: 'Will you look at this:'"
 
  ^self new
  title: titleString;
  label: aString;
+ addSelectedCancelButton: 'OK' translated value: nil;
- addSelectedCancelButton: '       OK       ' translated value: nil;
  runModalIn: ActiveWorld forHand: ActiveHand at: aPointOrNil!

Item was changed:
  ----- Method: UserDialogBoxMorph>>addButton:value:selected:performActionOnEscape: (in category 'constructing') -----
  addButton: buttonLabel value: buttonValue selected: isSelected performActionOnEscape: performActionOnEscape
  "Adds a button with the given label and value.
  The value is returned if the user presses the button."
  | button |
  button := PluggableButtonMorphPlus new
  label: buttonLabel ;
  action: [ self closeDialog: buttonValue ] ;
  onColor: self buttonColor twiceLighter
  offColor: self buttonColor twiceLighter.
+ button hResizing: #spaceFill; vResizing: #spaceFill.
  isSelected ifTrue: [ self selectButton: button ].
  performActionOnEscape ifTrue: [ self performActionOnEscapeOf: button ].
  self registerKeyFor: button.
  buttonRow addMorphBack: button!

Item was changed:
  ----- Method: UserDialogBoxMorph>>initialize (in category 'initialization') -----
  initialize
 
  | titleRow cc |
  super initialize.
  self color: Color white.
  self listDirection: #topToBottom; wrapCentering: #center;
  hResizing: #shrinkWrap; vResizing: #shrinkWrap.
  self layoutInset: -1 @ -1; cellInset: 5@5.
  self borderStyle: BorderStyle thinGray.
  self useRoundedCorners.
  self hasDropShadow: true.
  self useSoftDropShadow
  ifFalse: [
  self
  shadowColor: (TranslucentColor r: 0.0 g: 0.0 b: 0.0 alpha: 0.666);
  shadowOffset: 1 @ 1]
  ifTrue: [
  self
  shadowColor: (TranslucentColor r: 0.0 g: 0.0 b: 0.0 alpha: 0.01);
  shadowOffset: (10@8 corner: 10@12)].
 
  cc := Color gray: 0.8.
  titleRow := AlignmentMorph newRow.
  titleRow hResizing: #spaceFill; vResizing: #shrinkWrap.
  titleRow useRoundedCorners.
  titleRow borderStyle: BorderStyle thinGray.
  titleRow layoutInset: (2@5 corner: (2@ (5 + Morph preferredCornerRadius))).
  titleRow color: cc.
  titleRow fillStyle: self titleGradient.
 
  titleMorph := StringMorph new.
  titleMorph emphasis: 1.
  titleRow addMorph: titleMorph.
  labelMorph := TextMorph new.
+ labelMorph margins: (Preferences standardButtonFont widthOf: $x) * 2  @ 0.
- labelMorph margins: 5@5.
  labelMorph lock.
+ buttonRow := AlignmentMorph newRow
+ vResizing: #rigid;
+ height: (Preferences standardButtonFont height * 5);
+ hResizing: #spaceFill;
+ layoutInset: (Preferences standardButtonFont widthOf: $x) * 2;
+ cellInset: (Preferences standardButtonFont widthOf: $x) * 2.
- buttonRow := AlignmentMorph newRow vResizing: #shrinkWrap.
- buttonRow hResizing: #shrinkWrap; layoutInset: 5@5; cellInset: 5@5.
  buttonRow color: Color transparent.
  self
  addMorphBack: titleRow ;
  addMorphBack: labelMorph ;
  addMorphBack: buttonRow.
  keyMap := Dictionary new!