New: Allow a text based control to stay on a single line when wrapping

A private flag have been added in _CPImageAndTextView. It must be set
to YES when it does not make sense for a control to hold multiline text.
This is now the case for all CPSegmentedControl.

Test: In CPSegmentedControlTest, hit « Add Segment with flexible
width » button. The new label should be vertically centered.
This commit is contained in:
cacaodev committed 2016-12-02 09:10:39 +01:00
1 parent 1e0aacd811
commit d42562fdcb
2 files changed
+12 -1

No files matched your search

+6 -1
View File
@@ -604,7 +604,12 @@ CPSegmentSwitchTrackingMomentary = 2;
- (CPView)createEphemeralSubviewNamed:(CPString)aName
{
if ([aName hasPrefix:@"segment-content"])
return [[_CPImageAndTextView alloc] initWithFrame:CGRectMakeZero()];
{
var view = [[_CPImageAndTextView alloc] initWithFrame:CGRectMakeZero()];
[view _setUsesSingleLineMode:YES];
return view;
}
return [[CPView alloc] initWithFrame:CGRectMakeZero()];
}
+6
View File
@@ -66,6 +66,7 @@ var _CPimageAndTextViewFrameSizeChangedFlag = 1 << 0,
CPString _text;
CGSize _textSize;
BOOL _usesSingleLineMode @accessors;
unsigned _flags;
@@ -107,6 +108,8 @@ var _CPimageAndTextViewFrameSizeChangedFlag = 1 << 0,
}
_textSize = nil;
_usesSingleLineMode = NO;
[self setHitTests:NO];
}
@@ -725,6 +728,9 @@ var _CPimageAndTextViewFrameSizeChangedFlag = 1 << 0,
_lineBreakMode === CPLineBreakByWordWrapping)
{
_textSize = [_text sizeWithFont:_font inWidth:textRectWidth];
if (_usesSingleLineMode)
_textSize.height = [_font defaultLineHeightForFont];
}
else
{