NSBox: (re-)implement isOpaque (#254)

This (re-)implements logic where a box is marked
as opaque if it is a custom box which is not
transparent, but moves the logic to `GSTheme`,
allowing themes to override this loggic.

This fixes the rendering of custom boxes with a
custom fill color; the current implementation
would mark them as non-opaque and hence the fill
color would not be rendered.

- The original implementation (from 1999) always
  returned `YES`
  (53bcb50240)
- A more complete implementation was backported
  from the Testplant branch in 2012
  (e85b16bc05, by
  @fredkiefer, upstream commit
  36e77b95f7)
- More recently, the a return value of `NO` was
  hardcoded
  (02bc49e2d5, by
  @ericwa)
This commit is contained in:
Frederik Carlier 2024-04-04 22:23:14 +02:00 committed by GitHub
parent 95f302442c
commit 892ed4877e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 12 deletions

View file

@ -1339,6 +1339,8 @@ APPKIT_EXPORT_CLASS
clipRect: (NSRect)clipRect
inView: (NSView *)view;
- (BOOL) isBoxOpaque: (NSBox *)box;
- (void) drawBoxInClipRect: (NSRect)clipRect
boxType: (NSBoxType)boxType
borderType: (NSBorderType)borderType

View file

@ -3475,6 +3475,18 @@ static NSDictionary *titleTextAttributes[3] = {nil, nil, nil};
}
}
- (BOOL) isBoxOpaque: (NSBox *)box
{
if ([box boxType] == NSBoxCustom)
{
return ![box isTransparent];
}
else
{
return YES;
}
}
- (void) drawBoxInClipRect: (NSRect)clipRect
boxType: (NSBoxType)boxType
borderType: (NSBorderType)borderType

View file

@ -464,18 +464,7 @@
- (BOOL) isOpaque
{
// FIXME: Depends on theme; if always returning NO is a performance hit
// we can check if GSTheme is going to draw an old-style opaque box
// or not.
return NO;
// if (_box_type == NSBoxCustom)
// {
// return !_transparent;
// }
// else
// {
// return YES;
// }
return [[GSTheme theme] isBoxOpaque: self];
}
- (NSColor*) fillColor