| 1 |
#if defined(Hiro_Frame) |
| 2 |
|
| 3 |
@implementation CocoaFrame |
| 4 |
|
| 5 |
-(id) initWith:(hiro::mFrame&)frameReference { |
| 6 |
if(self = [super initWithFrame:NSMakeRect(0, 0, 0, 0)]) { |
| 7 |
frame = &frameReference; |
| 8 |
|
| 9 |
[self setTitle:@""]; |
| 10 |
} |
| 11 |
return self; |
| 12 |
} |
| 13 |
|
| 14 |
@end |
| 15 |
|
| 16 |
namespace hiro { |
| 17 |
|
| 18 |
auto pFrame::construct() -> void { |
| 19 |
cocoaView = cocoaFrame = [[CocoaFrame alloc] initWith:self()]; |
| 20 |
pWidget::construct(); |
| 21 |
|
| 22 |
setText(state().text); |
| 23 |
} |
| 24 |
|
| 25 |
auto pFrame::destruct() -> void { |
| 26 |
[cocoaView removeFromSuperview]; |
| 27 |
} |
| 28 |
|
| 29 |
auto pFrame::append(sSizable sizable) -> void { |
| 30 |
} |
| 31 |
|
| 32 |
auto pFrame::remove(sSizable sizable) -> void { |
| 33 |
} |
| 34 |
|
| 35 |
auto pFrame::setEnabled(bool enabled) -> void { |
| 36 |
pWidget::setEnabled(enabled); |
| 37 |
if(auto& sizable = state().sizable) sizable->setEnabled(enabled); |
| 38 |
} |
| 39 |
|
| 40 |
auto pFrame::setFont(const Font& font) -> void { |
| 41 |
[(CocoaFrame*)cocoaView setTitleFont:pFont::create(font)]; |
| 42 |
if(auto& sizable = state().sizable) sizable->setFont(font); |
| 43 |
} |
| 44 |
|
| 45 |
auto pFrame::setGeometry(Geometry geometry) -> void { |
| 46 |
bool empty = !state().text; |
| 47 |
Size size = pFont::size(self().font(true), state().text); |
| 48 |
pWidget::setGeometry({ |
| 49 |
geometry.x() - 3, geometry.y() - (empty ? size.height() - 2 : 1), |
| 50 |
geometry.width() + 6, geometry.height() + (empty ? size.height() + 2 : 5) |
| 51 |
}); |
| 52 |
if(auto& sizable = state().sizable) { |
| 53 |
sizable->setGeometry({ |
| 54 |
geometry.x() + 1, geometry.y() + (empty ? 1 : size.height() - 2), |
| 55 |
geometry.width() - 2, geometry.height() - (empty ? 1 : size.height() - 1) |
| 56 |
}); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
auto pFrame::setText(const string& text) -> void { |
| 61 |
[(CocoaFrame*)cocoaView setTitle:[NSString stringWithUTF8String:text]]; |
| 62 |
} |
| 63 |
|
| 64 |
auto pFrame::setVisible(bool visible) -> void { |
| 65 |
pWidget::setVisible(visible); |
| 66 |
if(auto& sizable = state().sizable) sizable->setVisible(visible); |
| 67 |
} |
| 68 |
|
| 69 |
} |
| 70 |
|
| 71 |
#endif |