diff options
author | Teddy Wing | 2023-09-25 01:42:36 +0200 |
---|---|---|
committer | Teddy Wing | 2023-09-25 01:42:36 +0200 |
commit | 4157ed88b241631b194046692bbf0e4464e839e8 (patch) | |
tree | 9f79ebbc7969c248cf1a2d5bfe37a6f706743ea2 /src/Document.m | |
parent | d62c07399f546969e04541efa853ee4b882ec9bf (diff) | |
download | Base-Windowed-Application-4157ed88b241631b194046692bbf0e4464e839e8.tar.bz2 |
Document: Add placeholder label
Add a "Your document contents here" label to the center of the
NSDocument window similar to the one that Xcode's document-based app
template.
Took inspiration from this Stack Overflow answer to get the center point
of the window's content view:
https://stackoverflow.com/questions/6560842/getting-the-center-point-of-an-nsview/14811056#14811056
Diffstat (limited to 'src/Document.m')
-rw-r--r-- | src/Document.m | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/Document.m b/src/Document.m index 7b514eb..e50737d 100644 --- a/src/Document.m +++ b/src/Document.m @@ -6,10 +6,23 @@ { self = [super init]; if (self) { + _label = [[NSTextField alloc] + initWithFrame:NSMakeRect(0, 0, 180, 20)]; + [_label setStringValue:@"Your document contents here"]; + [_label setBezeled:NO]; + [_label setDrawsBackground:NO]; + [_label setEditable:NO]; + [_label setFont:[NSFont systemFontOfSize:18]]; } return self; } +- (void)dealloc +{ + [_label release]; + [super dealloc]; +} + // TODO: Are window controllers deallocated automatically by the parent? // [[NSWindowController alloc] initWithWindow:]? @@ -27,6 +40,30 @@ backing:NSBackingStoreBuffered defer:NO]; // [window setFrameAutosaveName:@"document"]; // document name? + [[window contentView] addSubview:_label]; + + // Center the label. + NSRect content_view_frame = [[window contentView] frame]; + // NSSize window_size = [[window contentView] bounds].size; + NSPoint content_view_center = NSMakePoint( + NSMidX(content_view_frame), + NSMidY(content_view_frame) + ); + NSRect label_frame = NSMakeRect( + content_view_center.x - 125, + content_view_center.y, + 250, + 28 + ); + [_label setFrame:label_frame]; + [_label setAutoresizingMask: + NSViewMinXMargin + | NSViewMaxXMargin + | NSViewMinYMargin + | NSViewMaxYMargin]; + + // TODO: Cascade, store previous top-left position. + // [window cascadeTopLeftFromPoint:NSMakePoint(100, 100)]; NSWindowController *window_controller = [[NSWindowController alloc] initWithWindow:window]; |