mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-06 10:53:42 +00:00
Fixed: CPSegmentedControl did not take divider width into account when auto sizing. This resolves the incorrect tab sizes in CPTabView.
If a segmented control was initialised with a zero width and then expanded with setSegmentCount, it would not allocate space for any needed dividers. The more tabs were added the more the segmented control would be undersized. The fix is to automatically adjust the width when dividers are added or removed.
This commit is contained in:
@@ -94,7 +94,9 @@ CPSegmentSwitchTrackingMomentary = 2;
|
||||
if (_segments.length == aCount)
|
||||
return;
|
||||
|
||||
var height = CGRectGetHeight([self bounds]);
|
||||
var height = CGRectGetHeight([self bounds]),
|
||||
dividersBefore = MAX(0, _segments.length - 1),
|
||||
dividersAfter = MAX(0, aCount - 1);
|
||||
|
||||
if (_segments.length < aCount)
|
||||
{
|
||||
@@ -113,6 +115,14 @@ CPSegmentSwitchTrackingMomentary = 2;
|
||||
if (_selectedSegment >= _segments.length)
|
||||
_selectedSegment = -1;
|
||||
|
||||
// Make space for/remove space used by dividers.
|
||||
var thickness = [self currentValueForThemeAttribute:@"divider-thickness"],
|
||||
delta = thickness * (dividersAfter - dividersBefore),
|
||||
frame = [self frame];
|
||||
|
||||
if (delta)
|
||||
[self setFrameSize:CGSizeMake(frame.size.width + delta, frame.size.height)];
|
||||
|
||||
[self tileWithChangedSegment:0];
|
||||
}
|
||||
|
||||
@@ -607,7 +617,7 @@ CPSegmentSwitchTrackingMomentary = 2;
|
||||
segmentWidth = [segment width],
|
||||
themeState = _themeStates[aSegment] | (_themeState & CPThemeStateDisabled),
|
||||
contentInset = [self valueForThemeAttribute:@"content-inset" inState:themeState],
|
||||
font = [self valueForThemeAttribute:@"font" inState:themeState];
|
||||
font = [self font];
|
||||
|
||||
if (!segmentWidth)
|
||||
{
|
||||
|
||||
@@ -21,19 +21,26 @@
|
||||
[tabView setTabViewType:CPNoTabsBezelBorder];
|
||||
[tabView setTabViewType:CPTopTabsBezelBorder];
|
||||
|
||||
var view = [[CPView alloc] initWithFrame:CGRectMake(20, 20, 200, 200)];
|
||||
[view addSubview:[CPTextField labelWithTitle:@"First"]];
|
||||
var item = [[CPTabViewItem alloc] initWithIdentifier:@"a"];
|
||||
[item setView:view];
|
||||
[item setLabel:"Test"];
|
||||
[tabView addTabViewItem:item];
|
||||
var tabs = [
|
||||
"First Tab", "a label",
|
||||
"Second Tab", "another label",
|
||||
"Third Tab", "a third label",
|
||||
"Fourth Tab", "label 4",
|
||||
/*"5th Tab", "label 5",
|
||||
"6th Tab", "label 6",
|
||||
"7th Tab", "label 7",*/
|
||||
];
|
||||
|
||||
view = [[CPView alloc] initWithFrame:CGRectMake(20, 20, 200, 200)];
|
||||
[view addSubview:[CPTextField labelWithTitle:@"Second"]];
|
||||
item = [[CPTabViewItem alloc] initWithIdentifier:@"a"];
|
||||
[item setView:view];
|
||||
[item setLabel:"Test2"];
|
||||
[tabView addTabViewItem:item];
|
||||
for (var i = 0; i < tabs.length; i += 2)
|
||||
{
|
||||
var view = [[CPView alloc] initWithFrame:CGRectMake(20, 20, 200, 200)];
|
||||
[view addSubview:[CPTextField labelWithTitle:tabs[i + 1]]];
|
||||
|
||||
var item = [[CPTabViewItem alloc] initWithIdentifier:tabs[i]];
|
||||
[item setView:view];
|
||||
[item setLabel:tabs[i]];
|
||||
[tabView addTabViewItem:item];
|
||||
}
|
||||
|
||||
[contentView addSubview:tabView];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user