@@ -1085,22 +1085,21 @@ -(void)save_figure:(id)sender
1085
1085
[self ->handler installCallbacks: actions forButtons: buttons];
1086
1086
1087
1087
NSFont * font = [NSFont systemFontOfSize: 0.0 ];
1088
- rect.size .width = 300 ;
1089
- rect.size .height = 0 ;
1090
- rect.origin .x += height;
1091
- NSTextView * messagebox = [[NSTextView alloc ] initWithFrame: rect];
1088
+ // rect.origin.x is now at the far right edge of the buttons
1089
+ // we want the messagebox to take up the rest of the toolbar area
1090
+ rect.size .width = bounds.size .width - rect.origin .x ;
1091
+ rect.origin .x = bounds.size .width - rect.size .width ;
1092
+ NSTextView * messagebox = [[[NSTextView alloc ] initWithFrame: rect] autorelease ];
1092
1093
if (@available (macOS 10.11 , *)) {
1093
1094
messagebox.textContainer .maximumNumberOfLines = 2 ;
1094
1095
messagebox.textContainer .lineBreakMode = NSLineBreakByTruncatingTail;
1096
+ messagebox.alignment = NSTextAlignmentRight;
1095
1097
}
1096
1098
[messagebox setFont: font];
1097
1099
[messagebox setDrawsBackground: NO ];
1098
1100
[messagebox setSelectable: NO ];
1099
1101
/* if selectable, the messagebox can become first responder,
1100
1102
* which is not supposed to happen */
1101
- rect = [messagebox frame ];
1102
- rect.origin .y = 0.5 * (height - rect.size .height );
1103
- [messagebox setFrameOrigin: rect.origin];
1104
1103
[[window contentView ] addSubview: messagebox];
1105
1104
[messagebox release ];
1106
1105
[[window contentView ] display ];
@@ -1130,25 +1129,29 @@ -(void)save_figure:(id)sender
1130
1129
{
1131
1130
const char * message;
1132
1131
1133
- if (!PyArg_ParseTuple (args, " y " , &message)) { return NULL ; }
1132
+ if (!PyArg_ParseTuple (args, " s " , &message)) { return NULL ; }
1134
1133
1135
1134
NSTextView * messagebox = self->messagebox ;
1136
1135
1137
1136
if (messagebox) {
1138
1137
NSString * text = [NSString stringWithUTF8String: message];
1139
1138
[messagebox setString: text];
1140
1139
1141
- // Adjust width with the window size
1140
+ // Adjust width and height with the window size and content
1142
1141
NSRect rectWindow = [messagebox.superview frame ];
1143
1142
NSRect rect = [messagebox frame ];
1143
+ // Entire region to the right of the buttons
1144
1144
rect.size .width = rectWindow.size .width - rect.origin .x ;
1145
1145
[messagebox setFrame: rect];
1146
-
1147
- // Adjust height with the content size
1146
+ // We want to control the vertical position of
1147
+ // the rect by the content size to center it vertically
1148
+ // TODO: This seems to disable the cursor updates with newlines that
1149
+ // are included in the image hover text. It is only when trying
1150
+ // to set the frame height based on the contentRect's size.
1148
1151
[messagebox.layoutManager ensureLayoutForTextContainer: messagebox.textContainer];
1149
- NSRect contentSize = [messagebox.layoutManager usedRectForTextContainer: messagebox.textContainer];
1150
- rect = [messagebox frame ] ;
1151
- rect.origin . y = 0.5 * (self-> height - contentSize. size .height ) ;
1152
+ NSRect contentRect = [messagebox.layoutManager usedRectForTextContainer: messagebox.textContainer];
1153
+ rect. origin . y = 0.5 * (self-> height - contentRect. size . height ) ;
1154
+ rect.size . height = contentRect. size .height ;
1152
1155
[messagebox setFrame: rect];
1153
1156
}
1154
1157
0 commit comments