瀏覽代碼

Moka: adds `minimumThickness` to MKSplitView

Nicolas Petton 11 年之前
父節點
當前提交
250b9b3dc0
共有 4 個文件被更改,包括 258 次插入72 次删除
  1. 144 54
      js/Moka-Controllers.js
  2. 56 1
      js/Moka-Views.js
  3. 45 16
      st/Moka-Controllers.st
  4. 13 1
      st/Moka-Views.st

+ 144 - 54
js/Moka-Controllers.js

@@ -930,6 +930,24 @@ smalltalk.MKScrollController);
 
 smalltalk.addClass('MKSplitController', smalltalk.MKController, [], 'Moka-Controllers');
 smalltalk.MKSplitController.comment="I am the abstract controller for `MKSplitView`.";
+smalltalk.addMethod(
+smalltalk.method({
+selector: "minimumThickness",
+category: 'accessing',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $1;
+$1=_st(self._view())._minimumThickness();
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"minimumThickness",{},smalltalk.MKSplitController)})},
+args: [],
+source: "minimumThickness\x0a\x09^ self view minimumThickness",
+messageSends: ["minimumThickness", "view"],
+referencedClasses: []
+}),
+smalltalk.MKSplitController);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "onResize:helper:",
@@ -937,35 +955,53 @@ category: 'actions',
 fn: function (anEvent,aJQuery){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
-self._subclassResponsibility();
+self._placeSplitter_(self._positionForSplitter_(aJQuery));
 return self}, function($ctx1) {$ctx1.fill(self,"onResize:helper:",{anEvent:anEvent,aJQuery:aJQuery},smalltalk.MKSplitController)})},
 args: ["anEvent", "aJQuery"],
-source: "onResize: anEvent helper: aJQuery\x0a\x09self subclassResponsibility",
-messageSends: ["subclassResponsibility"],
+source: "onResize: anEvent helper: aJQuery\x0a\x09self placeSplitter: (self positionForSplitter: aJQuery)",
+messageSends: ["placeSplitter:", "positionForSplitter:"],
 referencedClasses: []
 }),
 smalltalk.MKSplitController);
 
-
-
-smalltalk.addClass('MKBottomFixedVerticalSplitController', smalltalk.MKSplitController, [], 'Moka-Controllers');
-smalltalk.MKBottomFixedVerticalSplitController.comment="I am an alternative controller for `MKVerticalSplitView`.\x0a\x0aWhen the splitter is moved, the second view is set a fixed size, thus resizing will preserve the height of the second view, while the first view will be resized.";
 smalltalk.addMethod(
 smalltalk.method({
-selector: "onResize:helper:",
+selector: "placeSplitter:",
 category: 'actions',
-fn: function (anEvent,aJQuery){
+fn: function (aJQuery){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
-self._placeSplitter_(_st(_st(_st(self._view())._domSize())._y()).__minus(_st(_st(aJQuery)._position())._top()));
-return self}, function($ctx1) {$ctx1.fill(self,"onResize:helper:",{anEvent:anEvent,aJQuery:aJQuery},smalltalk.MKBottomFixedVerticalSplitController)})},
-args: ["anEvent", "aJQuery"],
-source: "onResize: anEvent helper: aJQuery\x0a\x09self placeSplitter: self view domSize y - aJQuery position top",
-messageSends: ["placeSplitter:", "-", "y", "domSize", "view", "top", "position"],
+self._subclassResponsibility();
+return self}, function($ctx1) {$ctx1.fill(self,"placeSplitter:",{aJQuery:aJQuery},smalltalk.MKSplitController)})},
+args: ["aJQuery"],
+source: "placeSplitter: aJQuery\x0a\x09self subclassResponsibility",
+messageSends: ["subclassResponsibility"],
 referencedClasses: []
 }),
-smalltalk.MKBottomFixedVerticalSplitController);
+smalltalk.MKSplitController);
+
+smalltalk.addMethod(
+smalltalk.method({
+selector: "positionForSplitter:",
+category: 'private',
+fn: function (aJQuery){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $1;
+$1=self._subclassResponsibility();
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"positionForSplitter:",{aJQuery:aJQuery},smalltalk.MKSplitController)})},
+args: ["aJQuery"],
+source: "positionForSplitter: aJQuery\x0a\x09^ self subclassResponsibility",
+messageSends: ["subclassResponsibility"],
+referencedClasses: []
+}),
+smalltalk.MKSplitController);
 
+
+
+smalltalk.addClass('MKBottomFixedVerticalSplitController', smalltalk.MKSplitController, [], 'Moka-Controllers');
+smalltalk.MKBottomFixedVerticalSplitController.comment="I am an alternative controller for `MKVerticalSplitView`.\x0a\x0aWhen the splitter is moved, the second view is set a fixed size, thus resizing will preserve the height of the second view, while the first view will be resized.";
 smalltalk.addMethod(
 smalltalk.method({
 selector: "placeSplitter:",
@@ -1009,26 +1045,39 @@ referencedClasses: []
 }),
 smalltalk.MKBottomFixedVerticalSplitController);
 
-
-
-smalltalk.addClass('MKLeftFixedHorizontalSplitController', smalltalk.MKSplitController, [], 'Moka-Controllers');
-smalltalk.MKLeftFixedHorizontalSplitController.comment="I am the controller for `MKHorizontalSplitView`.\x0a\x0aWhen the splitter is moved, the left view is set a fixed size, thus resizing will preserve the width of the first view, while the second view will be resized.";
 smalltalk.addMethod(
 smalltalk.method({
-selector: "onResize:helper:",
-category: 'actions',
-fn: function (anEvent,aJQuery){
+selector: "positionForSplitter:",
+category: 'private',
+fn: function (aJQuery){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
-self._placeSplitter_(_st(_st(aJQuery)._position())._left());
-return self}, function($ctx1) {$ctx1.fill(self,"onResize:helper:",{anEvent:anEvent,aJQuery:aJQuery},smalltalk.MKLeftFixedHorizontalSplitController)})},
-args: ["anEvent", "aJQuery"],
-source: "onResize: anEvent helper: aJQuery\x0a\x09self placeSplitter: aJQuery position left",
-messageSends: ["placeSplitter:", "left", "position"],
+var $6,$5,$4,$3,$7,$2,$1;
+$6=self._view();
+$ctx1.sendIdx["view"]=1;
+$5=_st($6)._domSize();
+$ctx1.sendIdx["domSize"]=1;
+$4=_st($5)._y();
+$ctx1.sendIdx["y"]=1;
+$3=_st($4).__minus(_st(_st(aJQuery)._position())._top());
+$ctx1.sendIdx["-"]=1;
+$7=self._minimumThickness();
+$ctx1.sendIdx["minimumThickness"]=1;
+$2=_st($3)._max_($7);
+$1=_st($2)._min_(_st(_st(_st(self._view())._domSize())._y()).__minus(self._minimumThickness()));
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"positionForSplitter:",{aJQuery:aJQuery},smalltalk.MKBottomFixedVerticalSplitController)})},
+args: ["aJQuery"],
+source: "positionForSplitter: aJQuery\x0a\x09^ ((self view domSize y - aJQuery position top) \x0a\x09\x09max: self minimumThickness) min: (self view domSize y - self minimumThickness)",
+messageSends: ["min:", "max:", "-", "y", "domSize", "view", "top", "position", "minimumThickness"],
 referencedClasses: []
 }),
-smalltalk.MKLeftFixedHorizontalSplitController);
+smalltalk.MKBottomFixedVerticalSplitController);
 
+
+
+smalltalk.addClass('MKLeftFixedHorizontalSplitController', smalltalk.MKSplitController, [], 'Moka-Controllers');
+smalltalk.MKLeftFixedHorizontalSplitController.comment="I am the controller for `MKHorizontalSplitView`.\x0a\x0aWhen the splitter is moved, the left view is set a fixed size, thus resizing will preserve the width of the first view, while the second view will be resized.";
 smalltalk.addMethod(
 smalltalk.method({
 selector: "placeSplitter:",
@@ -1064,26 +1113,32 @@ referencedClasses: []
 }),
 smalltalk.MKLeftFixedHorizontalSplitController);
 
-
-
-smalltalk.addClass('MKRightFixedHorizontalSplitController', smalltalk.MKSplitController, [], 'Moka-Controllers');
-smalltalk.MKRightFixedHorizontalSplitController.comment="I am an alternative controller for `MKHorizontalSplitView`.\x0a\x0aWhen the splitter is moved, the second view is set a fixed size, thus resizing will preserve the width of the second view, while the first view will be resized.";
 smalltalk.addMethod(
 smalltalk.method({
-selector: "onResize:helper:",
-category: 'actions',
-fn: function (anEvent,aJQuery){
+selector: "positionForSplitter:",
+category: 'private',
+fn: function (aJQuery){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
-self._placeSplitter_(_st(_st(_st(self._view())._domSize())._x()).__minus(_st(_st(aJQuery)._position())._left()));
-return self}, function($ctx1) {$ctx1.fill(self,"onResize:helper:",{anEvent:anEvent,aJQuery:aJQuery},smalltalk.MKRightFixedHorizontalSplitController)})},
-args: ["anEvent", "aJQuery"],
-source: "onResize: anEvent helper: aJQuery\x0a\x09self placeSplitter: self view domSize x - aJQuery position left",
-messageSends: ["placeSplitter:", "-", "x", "domSize", "view", "left", "position"],
+var $3,$4,$2,$1;
+$3=_st(_st(aJQuery)._position())._left();
+$4=self._minimumThickness();
+$ctx1.sendIdx["minimumThickness"]=1;
+$2=_st($3)._max_($4);
+$1=_st($2)._min_(_st(_st(_st(self._view())._domSize())._x()).__minus(self._minimumThickness()));
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"positionForSplitter:",{aJQuery:aJQuery},smalltalk.MKLeftFixedHorizontalSplitController)})},
+args: ["aJQuery"],
+source: "positionForSplitter: aJQuery\x0a\x09^ (aJQuery position left max: self minimumThickness)\x0a\x09\x09min: (self view domSize x - self minimumThickness)",
+messageSends: ["min:", "max:", "left", "position", "minimumThickness", "-", "x", "domSize", "view"],
 referencedClasses: []
 }),
-smalltalk.MKRightFixedHorizontalSplitController);
+smalltalk.MKLeftFixedHorizontalSplitController);
 
+
+
+smalltalk.addClass('MKRightFixedHorizontalSplitController', smalltalk.MKSplitController, [], 'Moka-Controllers');
+smalltalk.MKRightFixedHorizontalSplitController.comment="I am an alternative controller for `MKHorizontalSplitView`.\x0a\x0aWhen the splitter is moved, the second view is set a fixed size, thus resizing will preserve the width of the second view, while the first view will be resized.";
 smalltalk.addMethod(
 smalltalk.method({
 selector: "placeSplitter:",
@@ -1127,26 +1182,39 @@ referencedClasses: []
 }),
 smalltalk.MKRightFixedHorizontalSplitController);
 
-
-
-smalltalk.addClass('MKTopFixedVerticalSplitController', smalltalk.MKSplitController, [], 'Moka-Controllers');
-smalltalk.MKTopFixedVerticalSplitController.comment="I am the controller for `MKVerticalSplitView`.\x0a\x0aWhen the splitter is moved, the top view is set a fixed size, thus resizing will preserve the height of the first view, while the second view will be resized.";
 smalltalk.addMethod(
 smalltalk.method({
-selector: "onResize:helper:",
-category: 'actions',
-fn: function (anEvent,aJQuery){
+selector: "positionForSplitter:",
+category: 'private',
+fn: function (aJQuery){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
-self._placeSplitter_(_st(_st(aJQuery)._position())._top());
-return self}, function($ctx1) {$ctx1.fill(self,"onResize:helper:",{anEvent:anEvent,aJQuery:aJQuery},smalltalk.MKTopFixedVerticalSplitController)})},
-args: ["anEvent", "aJQuery"],
-source: "onResize: anEvent helper: aJQuery\x0a\x09self placeSplitter: aJQuery position top",
-messageSends: ["placeSplitter:", "top", "position"],
+var $6,$5,$4,$3,$7,$2,$1;
+$6=self._view();
+$ctx1.sendIdx["view"]=1;
+$5=_st($6)._domSize();
+$ctx1.sendIdx["domSize"]=1;
+$4=_st($5)._x();
+$ctx1.sendIdx["x"]=1;
+$3=_st($4).__minus(_st(_st(aJQuery)._position())._left());
+$ctx1.sendIdx["-"]=1;
+$7=self._minimumThickness();
+$ctx1.sendIdx["minimumThickness"]=1;
+$2=_st($3)._max_($7);
+$1=_st($2)._min_(_st(_st(_st(self._view())._domSize())._x()).__minus(self._minimumThickness()));
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"positionForSplitter:",{aJQuery:aJQuery},smalltalk.MKRightFixedHorizontalSplitController)})},
+args: ["aJQuery"],
+source: "positionForSplitter: aJQuery\x0a\x09^ ((self view domSize x - aJQuery position left)\x0a\x09\x09max: self minimumThickness)\x0a\x09\x09\x09min: (self view domSize x - self minimumThickness)",
+messageSends: ["min:", "max:", "-", "x", "domSize", "view", "left", "position", "minimumThickness"],
 referencedClasses: []
 }),
-smalltalk.MKTopFixedVerticalSplitController);
+smalltalk.MKRightFixedHorizontalSplitController);
+
+
 
+smalltalk.addClass('MKTopFixedVerticalSplitController', smalltalk.MKSplitController, [], 'Moka-Controllers');
+smalltalk.MKTopFixedVerticalSplitController.comment="I am the controller for `MKVerticalSplitView`.\x0a\x0aWhen the splitter is moved, the top view is set a fixed size, thus resizing will preserve the height of the first view, while the second view will be resized.";
 smalltalk.addMethod(
 smalltalk.method({
 selector: "placeSplitter:",
@@ -1182,5 +1250,27 @@ referencedClasses: []
 }),
 smalltalk.MKTopFixedVerticalSplitController);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "positionForSplitter:",
+category: 'private',
+fn: function (aJQuery){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $3,$4,$2,$1;
+$3=_st(_st(aJQuery)._position())._top();
+$4=self._minimumThickness();
+$ctx1.sendIdx["minimumThickness"]=1;
+$2=_st($3)._max_($4);
+$1=_st($2)._min_(_st(_st(_st(self._view())._domSize())._y()).__minus(self._minimumThickness()));
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"positionForSplitter:",{aJQuery:aJQuery},smalltalk.MKTopFixedVerticalSplitController)})},
+args: ["aJQuery"],
+source: "positionForSplitter: aJQuery\x0a\x09^ (aJQuery position top max: self minimumThickness)\x0a\x09\x09min: (self view domSize y - self minimumThickness)",
+messageSends: ["min:", "max:", "top", "position", "minimumThickness", "-", "y", "domSize", "view"],
+referencedClasses: []
+}),
+smalltalk.MKTopFixedVerticalSplitController);
+
 
 });

+ 56 - 1
js/Moka-Views.js

@@ -1818,7 +1818,7 @@ smalltalk.MKSourceListView);
 
 
 
-smalltalk.addClass('MKSplitView', smalltalk.MKLayoutView, ['firstView', 'secondView', 'splitter', 'thickness'], 'Moka-Views');
+smalltalk.addClass('MKSplitView', smalltalk.MKLayoutView, ['firstView', 'secondView', 'splitter', 'thickness', 'minimumThickness'], 'Moka-Views');
 smalltalk.MKSplitView.comment="I am the superclass of all split views. I arrange two child view with a splitter between them.\x0a\x0a## API\x0a\x0aCreate instances using the class-side method `firstView:secondView:`.";
 smalltalk.addMethod(
 smalltalk.method({
@@ -1856,6 +1856,22 @@ referencedClasses: []
 }),
 smalltalk.MKSplitView);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "defaultMinimumThickness",
+category: 'defaults',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+return (50);
+}, function($ctx1) {$ctx1.fill(self,"defaultMinimumThickness",{},smalltalk.MKSplitView)})},
+args: [],
+source: "defaultMinimumThickness\x0a\x09^ 50",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.MKSplitView);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "defaultThickness",
@@ -1907,6 +1923,45 @@ referencedClasses: ["MKDecorator"]
 }),
 smalltalk.MKSplitView);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "minimumThickness",
+category: 'accessing',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $2,$1;
+$2=self["@minimumThickness"];
+if(($receiver = $2) == nil || $receiver == null){
+$1=self._defaultMinimumThickness();
+} else {
+$1=$2;
+};
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"minimumThickness",{},smalltalk.MKSplitView)})},
+args: [],
+source: "minimumThickness\x0a\x09^ minimumThickness ifNil: [ self defaultMinimumThickness ]",
+messageSends: ["ifNil:", "defaultMinimumThickness"],
+referencedClasses: []
+}),
+smalltalk.MKSplitView);
+
+smalltalk.addMethod(
+smalltalk.method({
+selector: "minimumThickness:",
+category: 'accessing',
+fn: function (aNumber){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+self["@minimumThickness"]=aNumber;
+return self}, function($ctx1) {$ctx1.fill(self,"minimumThickness:",{aNumber:aNumber},smalltalk.MKSplitView)})},
+args: ["aNumber"],
+source: "minimumThickness: aNumber\x0a\x09minimumThickness := aNumber",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.MKSplitView);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "renderContentOn:",

+ 45 - 16
st/Moka-Controllers.st

@@ -328,12 +328,28 @@ MKController subclass: #MKSplitController
 !MKSplitController commentStamp!
 I am the abstract controller for `MKSplitView`.!
 
+!MKSplitController methodsFor: 'accessing'!
+
+minimumThickness
+	^ self view minimumThickness
+! !
+
 !MKSplitController methodsFor: 'actions'!
 
 onResize: anEvent helper: aJQuery
+	self placeSplitter: (self positionForSplitter: aJQuery)
+!
+
+placeSplitter: aJQuery
 	self subclassResponsibility
 ! !
 
+!MKSplitController methodsFor: 'private'!
+
+positionForSplitter: aJQuery
+	^ self subclassResponsibility
+! !
+
 MKSplitController subclass: #MKBottomFixedVerticalSplitController
 	instanceVariableNames: ''
 	package: 'Moka-Controllers'!
@@ -344,10 +360,6 @@ When the splitter is moved, the second view is set a fixed size, thus resizing w
 
 !MKBottomFixedVerticalSplitController methodsFor: 'actions'!
 
-onResize: anEvent helper: aJQuery
-	self placeSplitter: self view domSize y - aJQuery position top
-!
-
 placeSplitter: aNumber
 	| splitter |
 	splitter := self view splitter asJQuery.
@@ -360,6 +372,13 @@ placeSplitter: aNumber
 	self view firstView asJQuery css: 'bottom' put: aNumber asMokaCssString
 ! !
 
+!MKBottomFixedVerticalSplitController methodsFor: 'private'!
+
+positionForSplitter: aJQuery
+	^ ((self view domSize y - aJQuery position top) 
+		max: self minimumThickness) min: (self view domSize y - self minimumThickness)
+! !
+
 MKSplitController subclass: #MKLeftFixedHorizontalSplitController
 	instanceVariableNames: ''
 	package: 'Moka-Controllers'!
@@ -370,16 +389,19 @@ When the splitter is moved, the left view is set a fixed size, thus resizing wil
 
 !MKLeftFixedHorizontalSplitController methodsFor: 'actions'!
 
-onResize: anEvent helper: aJQuery
-	self placeSplitter: aJQuery position left
-!
-
 placeSplitter: aNumber
 	self view firstView asJQuery css: 'width' put: aNumber asMokaCssString.
 	self view splitter asJQuery css: 'left' put: aNumber asMokaCssString.
 	self view secondView asJQuery css: 'left' put: aNumber asMokaCssString
 ! !
 
+!MKLeftFixedHorizontalSplitController methodsFor: 'private'!
+
+positionForSplitter: aJQuery
+	^ (aJQuery position left max: self minimumThickness)
+		min: (self view domSize x - self minimumThickness)
+! !
+
 MKSplitController subclass: #MKRightFixedHorizontalSplitController
 	instanceVariableNames: ''
 	package: 'Moka-Controllers'!
@@ -390,10 +412,6 @@ When the splitter is moved, the second view is set a fixed size, thus resizing w
 
 !MKRightFixedHorizontalSplitController methodsFor: 'actions'!
 
-onResize: anEvent helper: aJQuery
-	self placeSplitter: self view domSize x - aJQuery position left
-!
-
 placeSplitter: aNumber
 	| splitter |
 	splitter := self view splitter asJQuery.
@@ -406,6 +424,14 @@ placeSplitter: aNumber
 	self view firstView asJQuery css: 'right' put: aNumber asMokaCssString
 ! !
 
+!MKRightFixedHorizontalSplitController methodsFor: 'private'!
+
+positionForSplitter: aJQuery
+	^ ((self view domSize x - aJQuery position left)
+		max: self minimumThickness)
+			min: (self view domSize x - self minimumThickness)
+! !
+
 MKSplitController subclass: #MKTopFixedVerticalSplitController
 	instanceVariableNames: ''
 	package: 'Moka-Controllers'!
@@ -416,13 +442,16 @@ When the splitter is moved, the top view is set a fixed size, thus resizing will
 
 !MKTopFixedVerticalSplitController methodsFor: 'actions'!
 
-onResize: anEvent helper: aJQuery
-	self placeSplitter: aJQuery position top
-!
-
 placeSplitter: aNumber
 	self view firstView asJQuery css: 'height' put: aNumber asMokaCssString.
 	self view splitter asJQuery css: 'top' put: aNumber asMokaCssString.
 	self view secondView asJQuery css: 'top' put: aNumber asMokaCssString
 ! !
 
+!MKTopFixedVerticalSplitController methodsFor: 'private'!
+
+positionForSplitter: aJQuery
+	^ (aJQuery position top max: self minimumThickness)
+		min: (self view domSize y - self minimumThickness)
+! !
+

+ 13 - 1
st/Moka-Views.st

@@ -650,7 +650,7 @@ cssClass
 ! !
 
 MKLayoutView subclass: #MKSplitView
-	instanceVariableNames: 'firstView secondView splitter thickness'
+	instanceVariableNames: 'firstView secondView splitter thickness minimumThickness'
 	package: 'Moka-Views'!
 !MKSplitView commentStamp!
 I am the superclass of all split views. I arrange two child view with a splitter between them.
@@ -677,6 +677,14 @@ firstView: aView
 	firstView := MKDecorator decorate: aView
 !
 
+minimumThickness
+	^ minimumThickness ifNil: [ self defaultMinimumThickness ]
+!
+
+minimumThickness: aNumber
+	minimumThickness := aNumber
+!
+
 secondView
 	^ secondView
 !
@@ -705,6 +713,10 @@ thickness: aNumber
 
 !MKSplitView methodsFor: 'defaults'!
 
+defaultMinimumThickness
+	^ 50
+!
+
 defaultThickness
 	^ 300
 ! !