2015-12-30 06:41:46 +00:00
|
|
|
#if defined(Hiro_Label)
|
|
|
|
|
2013-03-15 13:11:33 +00:00
|
|
|
@implementation CocoaLabel : NSTextField
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
-(id) initWith:(hiro::mLabel&)labelReference {
|
2013-03-15 13:11:33 +00:00
|
|
|
if(self = [super initWithFrame:NSMakeRect(0, 0, 0, 0)]) {
|
|
|
|
label = &labelReference;
|
|
|
|
|
|
|
|
[self setAlignment:NSLeftTextAlignment];
|
|
|
|
[self setBordered:NO];
|
|
|
|
[self setDrawsBackground:NO];
|
|
|
|
[self setEditable:NO];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
namespace hiro {
|
|
|
|
|
|
|
|
auto pLabel::construct() -> void {
|
|
|
|
@autoreleasepool {
|
|
|
|
cocoaView = cocoaLabel = [[CocoaLabel alloc] initWith:self()];
|
|
|
|
pWidget::construct();
|
|
|
|
|
|
|
|
setText(state().text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pLabel::destruct() -> void {
|
|
|
|
@autoreleasepool {
|
|
|
|
[cocoaView release];
|
|
|
|
}
|
|
|
|
}
|
2013-03-15 13:11:33 +00:00
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pLabel::minimumSize() const -> Size {
|
|
|
|
return pFont::size(self().font(true), state().text);
|
2013-04-09 13:31:46 +00:00
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pLabel::setAlignment(Alignment alignment) -> void {
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pLabel::setGeometry(Geometry geometry) -> void {
|
2013-04-09 13:31:46 +00:00
|
|
|
//NSTextField does not support vertical text centering:
|
|
|
|
//simulate this by adjusting the geometry placement (reduce height, move view down)
|
2015-12-30 06:41:46 +00:00
|
|
|
uint height = pFont::size(self().font(true), " ").height();
|
2013-04-09 13:31:46 +00:00
|
|
|
auto offset = geometry;
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
if(geometry.height() > height) {
|
|
|
|
uint diff = geometry.height() - height;
|
|
|
|
offset.setY(offset.y() + diff >> 1);
|
|
|
|
offset.setHeight(offset.height() - diff >> 1);
|
2013-04-09 13:31:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pWidget::setGeometry({
|
2015-12-30 06:41:46 +00:00
|
|
|
offset.x() - 3, offset.y() - 3,
|
|
|
|
offset.width() + 6, offset.height() + 6
|
2013-04-09 13:31:46 +00:00
|
|
|
});
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
auto pLabel::setText(const string& text) -> void {
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
[cocoaView setStringValue:[NSString stringWithUTF8String:text]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-12-30 06:41:46 +00:00
|
|
|
#endif
|