Set up slidier widths properly.

This commit is contained in:
Pietro Gagliardi 2015-08-21 16:31:17 -04:00
parent ff4f8fbd58
commit ba0cb12c74
1 changed files with 24 additions and 2 deletions

View File

@ -1,6 +1,26 @@
// 14 august 2015
#import "uipriv_darwin.h"
// Horizontal sliders have no intrinsic width; we'll use the default Interface Builder width for them.
// This will also be used for the initial frame size, to ensure the slider is always horizontal (see below).
#define sliderWidth 92
@interface libui_intrinsicWidthNSSlider : NSSlider
@end
@implementation libui_intrinsicWidthNSSlider
- (NSSize)intrinsicContentSize
{
NSSize s;
s = [super intrinsicContentSize];
s.width = sliderWidth;
return s;
}
@end
struct uiSlider {
uiDarwinControl c;
NSSlider *slider;
@ -95,8 +115,10 @@ uiSlider *uiNewSlider(intmax_t min, intmax_t max)
s = (uiSlider *) uiNewControl(uiSliderType());
s->slider = [[NSSlider alloc] initWithFrame:NSZeroRect];
// TODO vertical is defined by wider than tall
// a horizontal slider is defined as one where the width > height, not by a flag
// to be safe, don't use NSZeroRect, but make it horizontal from the get-go
s->slider = [[libui_intrinsicWidthNSSlider alloc]
initWithFrame:NSMakeRect(0, 0, sliderWidth, 2)];
[s->slider setMinValue:min];
[s->slider setMaxValue:max];
[s->slider setAllowsTickMarkValuesOnly:NO];