//
//  MMTableCell.m
//  iPhly
//
//  Created by Ari Krupnik on 6/29/11.
//  Copyright 2011 lib.aero. All rights reserved.
//

#import "MMSlider.h"


@implementation MMTableCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        CGRect sliderFrame = [[self contentView] frame];
        sliderFrame.size.height = [self height] -10;
        sliderFrame.size.width -= 30;
        sliderFrame.origin.x += 5;
        sliderFrame.origin.y += 5;
        slider=[[MMSlider alloc] initWithFrame:sliderFrame];
        [[self contentView] addSubview:slider];
        
        [self setSelectionStyle:UITableViewCellSelectionStyleNone];
    }
    return self;
}

- (float)value {
    return [slider value];
}
- (void)setValue:(float)value {
    [slider setValue:value];
}
- (float)minValue {
    return [slider minValue];
}
- (void)setMinValue:(float)minValue {
    [slider setMinValue:minValue];
}
- (float)maxValue {
    return [slider maxValue];
}
- (void)setMaxValue:(float)maxValue {
    [slider setMaxValue:maxValue];
}

- (UILabel*)textLabel {
    if (!label) {
        label = [[UILabel alloc] initWithFrame:CGRectMake(5, 2, [self frame].size.width-30, 21)];
        [label setTextAlignment:UITextAlignmentCenter];
        [[self contentView] addSubview:label];
        CGRect sliderFrame=[slider frame];
        sliderFrame.origin.y+=21;
        [slider setFrame:sliderFrame];
    }
    return label;
}

- (CGFloat) height {
    float f = label ? 96 : 75;
    return f;
}

- (void)dealloc {
    [slider release];
    [label release];
    [super dealloc];
}

@end
