Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a faster method of scrolling to the bottom for MacOS text logs. #1611

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions addons/native_dialog/osx_dialog.m
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,7 @@ int _al_show_native_message_box(ALLEGRO_DISPLAY *display,

#pragma mark Text Log View

#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
@interface ALLEGLogView : NSTextView <NSWindowDelegate>
#else
@interface ALLogView : NSTextView
#endif
{
@public
ALLEGRO_NATIVE_DIALOG *textlog;
Expand Down Expand Up @@ -293,7 +289,23 @@ - (void)appendText: (NSString*)text
[store beginEditing];
[store appendAttributedString:attributedString];
[store endEditing];
[self scrollRangeToVisible: NSMakeRange(self.string.length, 0)];
}
@end

@interface ALLEGScrollView : NSScrollView <NSWindowDelegate>
{
}
- (void)appendText: (NSString*)text;
@end

@implementation ALLEGScrollView

- (void)appendText: (NSString*)text
{
ALLEGLogView *view = (ALLEGLogView *)[self documentView];
[view appendText:text];
float bottom = view.frame.size.height;
[self.contentView scrollToPoint: NSMakePoint(0, bottom)];
}
@end

Expand Down Expand Up @@ -321,7 +333,7 @@ bool _al_open_native_text_log(ALLEGRO_NATIVE_DIALOG *textlog)
[win setReleasedWhenClosed: NO];
[win setTitle: @"Allegro Text Log"];
[win setMinSize: NSMakeSize(128, 128)];
NSScrollView *scrollView = [[NSScrollView alloc] initWithFrame: rect];
ALLEGScrollView *scrollView = [[ALLEGScrollView alloc] initWithFrame: rect];
[scrollView setHasHorizontalScroller: YES];
[scrollView setHasVerticalScroller: YES];
[scrollView setAutohidesScrollers: YES];
Expand Down Expand Up @@ -349,7 +361,7 @@ bool _al_open_native_text_log(ALLEGRO_NATIVE_DIALOG *textlog)

/* Save handles for future use. */
textlog->window = win; // Non-owning reference
textlog->tl_textview = view; // Non-owning reference
textlog->tl_textview = scrollView; // Non-owning reference
});
/* Now notify al_show_native_textlog that the text log is ready. */
textlog->is_active = true;
Expand Down Expand Up @@ -378,9 +390,9 @@ void _al_close_native_text_log(ALLEGRO_NATIVE_DIALOG *textlog)
void _al_append_native_text_log(ALLEGRO_NATIVE_DIALOG *textlog)
{
if (textlog->is_active) {
ALLEGLogView *view = (ALLEGLogView *)textlog->tl_textview;
ALLEGScrollView *scrollView = (NSScrollView *)textlog->tl_textview;
NSString *text = [NSString stringWithUTF8String: al_cstr(textlog->tl_pending_text)];
[view performSelectorOnMainThread:@selector(appendText:)
[scrollView performSelectorOnMainThread:@selector(appendText:)
withObject:text
waitUntilDone:NO];

Expand Down
Loading