mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 21:39:11 +02:00
Cocoa: improve ComboBox with OwnerDraw (especially TColorBox in Dark)
This commit is contained in:
parent
3a9ae5b7ee
commit
9af9ef8a87
@ -47,7 +47,8 @@ const
|
|||||||
COMBOBOX_RO_SMALL_HEIGHT = 17;
|
COMBOBOX_RO_SMALL_HEIGHT = 17;
|
||||||
COMBOBOX_RO_MINI_HEIGHT = 15;
|
COMBOBOX_RO_MINI_HEIGHT = 15;
|
||||||
|
|
||||||
COMBOBOX_RO_BUTTON_WIDTH = 20;
|
COMBOBOX_RO_ROUND_SIZE = 7;
|
||||||
|
COMBOBOX_RO_BUTTON_WIDTH = 18;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -214,7 +215,7 @@ type
|
|||||||
|
|
||||||
procedure GetRowHeight(rowidx: integer; var h: Integer);
|
procedure GetRowHeight(rowidx: integer; var h: Integer);
|
||||||
procedure ComboBoxDrawItem(itemIndex: Integer; ctx: TCocoaContext;
|
procedure ComboBoxDrawItem(itemIndex: Integer; ctx: TCocoaContext;
|
||||||
const r: TRect; isSelected: Boolean);
|
const r: TRect; isSelected: Boolean; backgroundPainted: Boolean );
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaComboBoxItemCell }
|
{ TCocoaComboBoxItemCell }
|
||||||
@ -702,7 +703,7 @@ begin
|
|||||||
try
|
try
|
||||||
ctxRect:= NSRectToRect( bounds );
|
ctxRect:= NSRectToRect( bounds );
|
||||||
ctx.InitDraw( ctxRect.Width, ctxRect.Height );
|
ctx.InitDraw( ctxRect.Width, ctxRect.Height );
|
||||||
combobox.callback.ComboBoxDrawItem(itemIndex, ctx, ctxRect, isHighlighted);
|
combobox.callback.ComboBoxDrawItem(itemIndex, ctx, ctxRect, isHighlighted, false);
|
||||||
finally
|
finally
|
||||||
ctx.Free;
|
ctx.Free;
|
||||||
end;
|
end;
|
||||||
@ -1738,19 +1739,20 @@ begin
|
|||||||
// (however, one should be careful and take layout offsets into account!)
|
// (however, one should be careful and take layout offsets into account!)
|
||||||
// on the other hand, "cells" themselves are being deprecated...
|
// on the other hand, "cells" themselves are being deprecated...
|
||||||
dr := lclFrame;
|
dr := lclFrame;
|
||||||
dr.Width:= dr.Width - COMBOBOX_RO_BUTTON_WIDTH;
|
|
||||||
|
// crop the drawing rectangle according to the
|
||||||
|
// rounded corners and popup button of the ComboBox.
|
||||||
|
// the APP can get better effect by drawing in the cropped rectangle.
|
||||||
|
// the APP can also expand the rectangle if it knows what it is doing.
|
||||||
Types.OffsetRect(dr, -dr.Left, -dr.Top);
|
Types.OffsetRect(dr, -dr.Left, -dr.Top);
|
||||||
//SubLayoutFromFrame( lclGetFrameToLayoutDelta, dr);
|
inc( dr.Left, COMBOBOX_RO_ROUND_SIZE );
|
||||||
|
inc( dr.Top, 2 );
|
||||||
|
dec( dr.Right, COMBOBOX_RO_BUTTON_WIDTH );
|
||||||
|
inc( dr.Bottom, 1 );
|
||||||
|
|
||||||
ctx.InitDraw(dr.Width, dr.Height);
|
ctx.InitDraw(dr.Width, dr.Height);
|
||||||
|
|
||||||
// magic offsets are based on the macOS 10.13.6 visual style
|
callback.ComboBoxDrawItem(lastSelectedItemIndex, ctx, dr, False, True);
|
||||||
// but hard-coding is never reliable
|
|
||||||
//inc(dr.Left, 11);
|
|
||||||
//inc(dr.Top, 5);
|
|
||||||
//dec(dr.Right,18);
|
|
||||||
//dec(dr.Bottom, 2);
|
|
||||||
|
|
||||||
callback.ComboBoxDrawItem(lastSelectedItemIndex, ctx, dr, false);
|
|
||||||
finally
|
finally
|
||||||
ctx.Free;
|
ctx.Free;
|
||||||
end;
|
end;
|
||||||
|
@ -88,7 +88,7 @@ type
|
|||||||
|
|
||||||
procedure GetRowHeight(rowidx: integer; var h: Integer);
|
procedure GetRowHeight(rowidx: integer; var h: Integer);
|
||||||
procedure ComboBoxDrawItem(itemIndex: Integer; ctx: TCocoaContext;
|
procedure ComboBoxDrawItem(itemIndex: Integer; ctx: TCocoaContext;
|
||||||
const r: TRect; isSelected: Boolean);
|
const r: TRect; isSelected: Boolean; backgroundPainted: Boolean);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaWSCustomComboBox }
|
{ TCocoaWSCustomComboBox }
|
||||||
@ -860,7 +860,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLCLComboboxCallback.ComboBoxDrawItem(itemIndex: Integer;
|
procedure TLCLComboboxCallback.ComboBoxDrawItem(itemIndex: Integer;
|
||||||
ctx: TCocoaContext; const r: TRect; isSelected: Boolean);
|
ctx: TCocoaContext; const r: TRect; isSelected: Boolean; backgroundPainted: Boolean);
|
||||||
var
|
var
|
||||||
itemstruct: TDrawListItemStruct;
|
itemstruct: TDrawListItemStruct;
|
||||||
begin
|
begin
|
||||||
@ -871,6 +871,7 @@ begin
|
|||||||
if isSelected then Include(itemstruct.ItemState, odSelected);
|
if isSelected then Include(itemstruct.ItemState, odSelected);
|
||||||
// we don't distingiush at the moment
|
// we don't distingiush at the moment
|
||||||
if isSelected then Include(itemstruct.ItemState, odFocused);
|
if isSelected then Include(itemstruct.ItemState, odFocused);
|
||||||
|
if backgroundPainted then Include(itemstruct.ItemState, odBackgroundPainted);
|
||||||
|
|
||||||
LCLSendDrawListItemMsg(Target, @itemstruct);
|
LCLSendDrawListItemMsg(Target, @itemstruct);
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user