git.y1.nz

SameBoy

Accurate GB/GBC emulator
download: https://git.y1.nz/archives/sameboy.tar.gz
README | Files | Log | Refs | LICENSE

commit 67d338164bcaa53a3028242d4b55190d44571863
parent e0432795005396fd1c3376b99eee18fbd62a06c7
Author: Lior Halphon <LIJI32@gmail.com>
Date:   Sun, 22 Jun 2025 23:34:41 +0300

Make text field insets work on macOS 26

Diffstat:
MCocoa/GBTerminalTextFieldCell.m20++++++++++----------
MCocoa/NSTextFieldCell+Inset.m54++++++++++++++++++++++++++++++++++++++++++++----------
2 files changed, 54 insertions(+), 20 deletions(-)

diff --git a/Cocoa/GBTerminalTextFieldCell.m b/Cocoa/GBTerminalTextFieldCell.m @@ -11,23 +11,23 @@ @implementation GBTerminalTextFieldCell { - GBTerminalTextView *field_editor; + GBTerminalTextView *_fieldEditor; } - (NSTextView *)fieldEditorForView:(NSTextField *)controlView { - if (field_editor) { - field_editor.gb = self.gb; - return field_editor; + if (_fieldEditor) { + _fieldEditor.gb = self.gb; + return _fieldEditor; } - field_editor = [[GBTerminalTextView alloc] init]; - [field_editor setFieldEditor:true]; - field_editor.gb = self.gb; - field_editor->_field = (NSTextField *)controlView; + _fieldEditor = [[GBTerminalTextView alloc] init]; + [_fieldEditor setFieldEditor:true]; + _fieldEditor.gb = self.gb; + _fieldEditor->_field = (NSTextField *)controlView; ((NSTextFieldCell *)controlView.cell).textInset = - field_editor.textContainerInset = + _fieldEditor.textContainerInset = NSMakeSize(7, 2); - return field_editor; + return _fieldEditor; } @end diff --git a/Cocoa/NSTextFieldCell+Inset.m b/Cocoa/NSTextFieldCell+Inset.m @@ -3,8 +3,8 @@ #import <objc/runtime.h> @interface NSTextFieldCell () -- (CGRect)_textLayerDrawingRectForCellFrame:(CGRect)rect; @property NSSize textInset; +- (bool)_isEditingInView:(NSView *)view; @end @implementation NSTextFieldCell (Inset) @@ -19,21 +19,55 @@ return [objc_getAssociatedObject(self, _cmd) sizeValue]; } -- (CGRect)_textLayerDrawingRectForCellFrameHook:(CGRect)rect +- (void)drawWithFrameHook:(NSRect)cellFrame inView:(NSView *)controlView { - CGRect ret = [self _textLayerDrawingRectForCellFrameHook:rect]; NSSize inset = self.textInset; - ret.origin.x += inset.width; - ret.origin.y += inset.height; - ret.size.width -= inset.width; - ret.size.height -= inset.height; - return ret; + if (self.drawsBackground) { + [self.backgroundColor setFill]; + if ([self _isEditingInView:controlView]) { + NSRectFill(cellFrame); + } + else { + NSRectFill(NSMakeRect(cellFrame.origin.x, cellFrame.origin.y, + cellFrame.size.width, inset.height)); + NSRectFill(NSMakeRect(cellFrame.origin.x, cellFrame.origin.y + cellFrame.size.height - inset.height, + cellFrame.size.width, inset.height)); + + NSRectFill(NSMakeRect(cellFrame.origin.x, cellFrame.origin.y + inset.height, + inset.width, cellFrame.size.height - inset.height * 2)); + NSRectFill(NSMakeRect(cellFrame.origin.x + cellFrame.size.width - inset.width, cellFrame.origin.y + inset.height, + inset.width, cellFrame.size.height - inset.height * 2)); + } + } + cellFrame.origin.x += inset.width; + cellFrame.origin.y += inset.height; + cellFrame.size.width -= inset.width * 2; + cellFrame.size.height -= inset.height * 2; + [self drawWithFrameHook:cellFrame inView:controlView]; } + (void)load { - method_exchangeImplementations(class_getInstanceMethod(self, @selector(_textLayerDrawingRectForCellFrame:)), - class_getInstanceMethod(self, @selector(_textLayerDrawingRectForCellFrameHook:))); + method_exchangeImplementations(class_getInstanceMethod(self, @selector(drawWithFrame:inView:)), + class_getInstanceMethod(self, @selector(drawWithFrameHook:inView:))); +} + +@end + + +@implementation NSTextField (Inset) + +- (bool)wantsUpdateLayerHook +{ + CGSize inset = ((NSTextFieldCell *)self.cell).textInset; + if (inset.width || inset.height) return false; + return [self wantsUpdateLayerHook]; +} + ++ (void)load +{ + method_exchangeImplementations(class_getInstanceMethod(self, @selector(wantsUpdateLayer)), + class_getInstanceMethod(self, @selector(wantsUpdateLayerHook))); } @end

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.