Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bfaa382

Browse files
committed
format_coord text resizes with the window and the content
1 parent d0fc2e9 commit bfaa382

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/_macosx.m

100644100755
Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -931,8 +931,9 @@ - (void)save_figure:(id)sender;
931931
typedef struct {
932932
PyObject_HEAD
933933
NSPopUpButton* menu;
934-
NSText* messagebox;
934+
NSTextView* messagebox;
935935
NavigationToolbar2Handler* handler;
936+
int height;
936937
} NavigationToolbar2;
937938

938939
@implementation NavigationToolbar2Handler
@@ -1139,7 +1140,9 @@ -(void)save_figure:(id)sender
11391140
const float gap = 2;
11401141
const int height = 36;
11411142
const int imagesize = 24;
1142-
1143+
1144+
self->height = height;
1145+
11431146
const char* basedir;
11441147

11451148
obj = PyObject_GetAttrString((PyObject*)self, "canvas");
@@ -1252,7 +1255,7 @@ -(void)save_figure:(id)sender
12521255
rect.size.width = 300;
12531256
rect.size.height = 0;
12541257
rect.origin.x += height;
1255-
NSText* messagebox = [[NSText alloc] initWithFrame: rect];
1258+
NSTextView* messagebox = [[NSTextView alloc] initWithFrame: rect];
12561259
[messagebox setFont: font];
12571260
[messagebox setDrawsBackground: NO];
12581261
[messagebox setSelectable: NO];
@@ -1294,12 +1297,26 @@ -(void)save_figure:(id)sender
12941297

12951298
if(!PyArg_ParseTuple(args, "y", &message)) return NULL;
12961299

1297-
NSText* messagebox = self->messagebox;
1300+
NSTextView* messagebox = self->messagebox;
12981301

12991302
if (messagebox)
13001303
{ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
13011304
NSString* text = [NSString stringWithUTF8String: message];
13021305
[messagebox setString: text];
1306+
1307+
// Adjust width with the window size
1308+
NSRect window_rect = [messagebox.superview frame];
1309+
NSRect rect = [messagebox frame];
1310+
rect.size.width = window_rect.size.width - rect.origin.x;
1311+
[messagebox setFrame: rect];
1312+
1313+
// Adjust height with the content size
1314+
[messagebox.layoutManager ensureLayoutForTextContainer: messagebox.textContainer];
1315+
NSRect contentSize = [messagebox.layoutManager usedRectForTextContainer: messagebox.textContainer];
1316+
rect = [messagebox frame];
1317+
rect.origin.y = 0.5 * (self->height - contentSize.size.height);
1318+
[messagebox setFrame: rect];
1319+
13031320
[pool release];
13041321
}
13051322

0 commit comments

Comments
 (0)