Skip to content
Browse files

Swaps out @jlaxson's SC.SegmentedView#shouldAutoResize for @publickea…

…ting's suggestion that the behavior be mediated by setting shouldHandleOverflow to NO. (There is currently no way to prevent resizing in a static-width segmented view with shouldHandleOverflow: NO; if that's a need, it shouldn't be hard to implement.)
  • Loading branch information...
1 parent e39017b commit 3f9128971e9ce7da0b97221a3dbd71975a90fb7c @dcporter dcporter committed Feb 15, 2014
Showing with 16 additions and 39 deletions.
  1. +7 −7 frameworks/desktop/tests/views/segmented/ui.js
  2. +9 −32 frameworks/desktop/views/segmented.js
View
14 frameworks/desktop/tests/views/segmented/ui.js
@@ -192,17 +192,17 @@ var pane;
itemTitleKey: "title",
layout: { height: 25 }
})
- .add("3_items,1_sel,shouldAutoResize", SC.SegmentedView, {
+ .add("3_items,1_sel,shouldHandleOverflow", SC.SegmentedView, {
items: "Item1 Item2 Item3".w(),
value: "Item2",
layout: { height: 25, width: 0 },
- shouldAutoResize: YES
+ shouldHandleOverflow: NO
})
- .add("3_items,1_sel,shouldAutoResize,flexible_layout", SC.SegmentedView, {
+ .add("3_items,1_sel,shouldHandleOverflow,flexible_layout", SC.SegmentedView, {
items: "Item1 Item2 Item3".w(),
value: "Item2",
layout: { height: 25, left: 0, right: 0 },
- shouldAutoResize: YES
+ shouldHandleOverflow: NO
});
@@ -553,14 +553,14 @@ var pane;
SC.RunLoop.end();
});
- test("shouldAutoResize", function() {
+ test("shouldHandleOverflow", function() {
var segmentedView;
- segmentedView = pane.view('3_items,1_sel,shouldAutoResize');
+ segmentedView = pane.view('3_items,1_sel,shouldHandleOverflow');
ok(segmentedView.getPath('layout.width') !== 0, "View auto-resized to fit the present items.");
- segmentedView = pane.view('3_items,1_sel,shouldAutoResize,flexible_layout');
+ segmentedView = pane.view('3_items,1_sel,shouldHandleOverflow,flexible_layout');
ok(SC.none(segmentedView.getPath('layout.width')), "Having flexible layout prevents view from auto-resizing.")
});
View
41 frameworks/desktop/views/segmented.js
@@ -257,6 +257,10 @@ SC.SegmentedView = SC.View.extend(SC.Control,
If YES, overflowing items are placed into a menu and an overflow segment is
added to popup that menu.
+ If NO, the SegmentedView will resize itself to fit its items. (Note that this
+ behavior will be prevented if you specify a flexible layout, e.g. `{ left: 0,
+ right: 0 }`, for your view.
+
@type Boolean
@default YES
*/
@@ -296,23 +300,6 @@ SC.SegmentedView = SC.View.extend(SC.Control,
*/
segmentViewClass: SC.SegmentView,
- /**
- Set to YES if you would like your SegmentedView to size itself based on its
- visible segments. Useful if you're using SegmentedView in a flowed context
- (for example if its parent view has `childViewLayout: SC.View.HORIZONTAL_STACK`).
-
- The view will not auto-resize unless you define an initial value for the layout
- property which will be auto-resized (i.e. `width` when in the default horizontal
- orientation). This is to prevent the view from inappropriately adding width to a
- flexible (`{ left: 0, right: 0 }`) layout.
-
- Has no effect if `shouldHandleOverflow` is NO.
-
- @type Boolean
- @default NO
- */
- shouldAutoResize: NO,
-
/** @private
The following properties are used to map items to child views. Item keys
are looked up on the item based on this view's value for each 'itemKey'.
@@ -505,9 +492,7 @@ SC.SegmentedView = SC.View.extend(SC.Control,
}
// Force a segment remeasure to check overflow
- if (this.get('shouldHandleOverflow')) {
- this.invokeLast(this.remeasure);
- }
+ this.invokeLast(this.remeasure);
}.observes('*items.[]'),
/** @private
@@ -525,9 +510,7 @@ SC.SegmentedView = SC.View.extend(SC.Control,
childView.updateItem(this, item);
// Reset our measurements (which depend on width/height or title) and adjust visible views
- if (this.get('shouldHandleOverflow')) {
- this.invokeLast(this.remeasure);
- }
+ this.invokeLast(this.remeasure);
}
},
@@ -539,7 +522,7 @@ SC.SegmentedView = SC.View.extend(SC.Control,
visibleDim = isHorizontal ? this.$().width() : this.$().height();
// Only overflow if we've gone below the minimum dimension required to fit all the segments
- if (this.get('shouldHandleOverflow') && (this.get('isOverflowing') || visibleDim <= this.cachedMinimumDim)) {
+ if (this.get('isOverflowing') || visibleDim <= this.cachedMinimumDim) {
this.invokeLast(this.remeasure);
}
},
@@ -548,18 +531,14 @@ SC.SegmentedView = SC.View.extend(SC.Control,
Whenever visibility changes, we need to check to see if we're overflowing.
*/
isVisibleInWindowDidChange: function () {
- if (this.get('shouldHandleOverflow')) {
- this.invokeLast(this.remeasure);
- }
+ this.invokeLast(this.remeasure);
}.observes('isVisibleInWindow'),
/** @private
Calling this method forces the segments to be remeasured and will also adjust the
segments for overflow if necessary.
*/
remeasure: function () {
- if (!this.get('shouldHandleOverflow')) { return; }
-
var childViews = this.get('childViews'),
overflowView;
@@ -583,8 +562,6 @@ SC.SegmentedView = SC.View.extend(SC.Control,
This method is called to adjust the segment views to see if we need to handle for overflow.
*/
adjustOverflow: function () {
- if (!this.get('shouldHandleOverflow')) { return; }
-
var childViews = this.get('childViews'),
childView,
value = this.get('value'),
@@ -595,7 +572,7 @@ SC.SegmentedView = SC.View.extend(SC.Control,
curElementsDim = 0,
dimToFit, length, i,
isOverflowing = NO,
- wantsAutoResize = this.get('shouldAutoResize'),
+ wantsAutoResize = !this.get('shouldHandleOverflow'),
canAutoResize = !SC.none(this.getPath('layout.%@'.fmt(layoutProperty))),
willAutoResize = wantsAutoResize && canAutoResize;

0 comments on commit 3f91289

Please sign in to comment.
Something went wrong with that request. Please try again.