mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-11 15:56:08 +02:00
Cocoa/ListView: in vsReport, turn Magic Numbers into configurable named variables
This commit is contained in:
parent
d9ab162b23
commit
9c2c0a7ec7
@ -9,6 +9,50 @@ uses
|
||||
CocoaAll, Cocoa_Extra, CocoaConst;
|
||||
|
||||
type
|
||||
TCocoaConfigVSReportRow = record
|
||||
defaultHeight: Integer;
|
||||
imageLineSpacing: Integer;
|
||||
end;
|
||||
|
||||
TCocoaConfigVSReportColumn = record
|
||||
controlSpacing: Integer;
|
||||
textFieldMinWidth: Integer;
|
||||
end;
|
||||
|
||||
TCocoaConfigVSReportColumnAutoFit = record
|
||||
// for performance, when the column divider is double-clicked to automatically
|
||||
// calculate the column width, the maximum number of rows calculated
|
||||
maxCalcRows: Integer;
|
||||
// min Column Width when the column divider is double-clicked
|
||||
minWidth: Double;
|
||||
// additional width for header
|
||||
headerAdditionalWidth: Double;
|
||||
end;
|
||||
|
||||
TCocoaConfigVSReport = record
|
||||
// default NSTableViewStyle
|
||||
tableViewStyle: NSTableViewStyle;
|
||||
row: TCocoaConfigVSReportRow;
|
||||
column: TCocoaConfigVSReportColumn;
|
||||
columnAutoFit: TCocoaConfigVSReportColumnAutoFit;
|
||||
end;
|
||||
|
||||
TCocoaConfigListView = record
|
||||
vsReport: TCocoaConfigVSReport;
|
||||
end;
|
||||
|
||||
var
|
||||
CocoaConfigListView: TCocoaConfigListView = (
|
||||
vsReport: (
|
||||
tableViewStyle: NSTableViewStyleAutomatic;
|
||||
row: ( defaultHeight: 16; imageLineSpacing: 4*2 );
|
||||
column: ( controlSpacing: 4; textFieldMinWidth: 16 );
|
||||
columnAutoFit: ( maxCalcRows: 100; minWidth: 20; headerAdditionalWidth: 4 );
|
||||
)
|
||||
);
|
||||
|
||||
type
|
||||
|
||||
// on macOS, the FocusRing takes up extra space, which may cause strange
|
||||
// display in some cases. it may block other controls, or be partially cut off.
|
||||
// for example, in the Lazarus IDE - About dialog, the FocusRing of the
|
||||
@ -116,16 +160,6 @@ var
|
||||
CocoaAlwaysPresentNotification : Boolean = True;
|
||||
|
||||
|
||||
// default NSTableViewStyle
|
||||
CocoaTableViewStyle : NSTableViewStyle = NSTableViewStyleAutomatic;
|
||||
|
||||
// for performance, when the column divider is double-clicked to automatically
|
||||
// calculate the column width, the maximum number of rows calculated
|
||||
CocoaTableColumnAutoFitWidthCalcRows : Integer = 100;
|
||||
|
||||
// min Column Width when the column divider is double-clicked
|
||||
CocoaTableColumnAutoFitWidthMin: Double = 20;
|
||||
|
||||
// for compatiblity with LCL 1.8 release. The macOS base is 72ppi
|
||||
CocoaBasePPI : Integer = 96;
|
||||
|
||||
|
@ -249,9 +249,6 @@ function LCLCoordToRow(tbl: NSTableView; X,Y: Integer): Integer;
|
||||
function LCLGetItemRect(tbl: NSTableView; row, col: Integer; var r: TRect): Boolean;
|
||||
function LCLGetTopRow(tbl: NSTableView): Integer;
|
||||
|
||||
const
|
||||
DefaultRowHeight = 16; // per "rowHeight" property docs
|
||||
|
||||
implementation
|
||||
|
||||
type
|
||||
@ -683,7 +680,7 @@ function TCocoaTableListView.initWithFrame(frameRect: NSRect): id;
|
||||
begin
|
||||
Result:=inherited initWithFrame(frameRect);
|
||||
if NSAppkitVersionNumber >= NSAppKitVersionNumber11_0 then
|
||||
setStyle( CocoaConfig.CocoaTableViewStyle );
|
||||
setStyle( CocoaConfigListView.vsReport.tableViewStyle );
|
||||
end;
|
||||
|
||||
procedure TCocoaTableListView.mouseDown(event: NSEvent);
|
||||
@ -784,17 +781,18 @@ end;
|
||||
function TCocoaTableListView.tableView_heightOfRow(tableView: NSTableView;
|
||||
row: NSInteger): CGFloat;
|
||||
var
|
||||
h : integer;
|
||||
h: Integer;
|
||||
begin
|
||||
h := CustomRowHeight;
|
||||
if h = 0 then h := DefaultRowHeight;
|
||||
h:= self.CustomRowHeight;
|
||||
if h = 0 then
|
||||
h:= CocoaConfigListView.vsReport.row.defaultHeight;
|
||||
|
||||
if isDynamicRowHeight and Assigned(self.callback) then
|
||||
begin
|
||||
self.callback.GetRowHeight(Integer(row), h);
|
||||
if isDynamicRowHeight and Assigned(self.callback) then begin
|
||||
self.callback.GetRowHeight( row, h );
|
||||
if h<=0 then h:=1; // must be positive (non-zero)
|
||||
end;
|
||||
Result := h;
|
||||
|
||||
Result:= h;
|
||||
end;
|
||||
|
||||
function TCocoaTableListView.tableView_sizeToFitWidthOfColumn(
|
||||
@ -809,10 +807,11 @@ var
|
||||
tableColumn: NSTableColumn;
|
||||
currentWidth: CGFloat;
|
||||
begin
|
||||
Result:= CocoaConfig.CocoaTableColumnAutoFitWidthMin;
|
||||
Result:= CocoaConfigListView.vsReport.columnAutoFit.minWidth;
|
||||
tableColumn:= NSTableColumn( self.tableColumns.objectAtIndex(column) );
|
||||
tableColumn.sizeToFit;
|
||||
currentWidth:= tableColumn.width + 4;
|
||||
currentWidth:= tableColumn.width +
|
||||
CocoaConfigListView.vsReport.columnAutoFit.headerAdditionalWidth;
|
||||
if currentWidth > Result then
|
||||
Result:= currentWidth;
|
||||
|
||||
@ -820,18 +819,18 @@ begin
|
||||
if totalCount = 0 then
|
||||
Exit;
|
||||
|
||||
if totalCount <= CocoaConfig.CocoaTableColumnAutoFitWidthCalcRows then begin
|
||||
if totalCount <= CocoaConfigListView.vsReport.columnAutoFit.maxCalcRows then begin
|
||||
startIndex:= 0;
|
||||
endIndex:= totalCount - 1;
|
||||
end else begin
|
||||
startIndex:= self.rowsInRect(self.visibleRect).location;
|
||||
endIndex:= startIndex + CocoaConfig.CocoaTableColumnAutoFitWidthCalcRows div 2;
|
||||
endIndex:= startIndex + CocoaConfigListView.vsReport.columnAutoFit.maxCalcRows div 2;
|
||||
if endIndex > totalCount - 1 then
|
||||
endIndex:= totalCount - 1;
|
||||
startIndex:= endIndex - CocoaConfig.CocoaTableColumnAutoFitWidthCalcRows + 1;
|
||||
startIndex:= endIndex - CocoaConfigListView.vsReport.columnAutoFit.maxCalcRows + 1;
|
||||
if startIndex < 0 then
|
||||
startIndex:= 0;
|
||||
endIndex:= startIndex + CocoaConfig.CocoaTableColumnAutoFitWidthCalcRows - 1;
|
||||
endIndex:= startIndex + CocoaConfigListView.vsReport.columnAutoFit.maxCalcRows - 1;
|
||||
end;
|
||||
|
||||
for row:=startIndex to endIndex do begin
|
||||
@ -1117,9 +1116,11 @@ var
|
||||
begin
|
||||
width:= self.textField.fittingSize.width;
|
||||
if Assigned(_checkBox) then
|
||||
width:= width + _checkBox.frame.size.width + 4;
|
||||
width:= width + _checkBox.frame.size.width +
|
||||
CocoaConfigListView.vsReport.column.controlSpacing;
|
||||
if Assigned(self.imageView) then
|
||||
width:= width + self.imageView.frame.size.width + 4;
|
||||
width:= width + self.imageView.frame.size.width +
|
||||
CocoaConfigListView.vsReport.column.controlSpacing;
|
||||
Result.width:= width;
|
||||
Result.height:= self.frame.size.height;
|
||||
end;
|
||||
@ -1277,7 +1278,7 @@ begin
|
||||
aFrame.origin.y:= round( (rowHeight - aFrame.size.height ) / 2 );
|
||||
_checkBox.setFrameOrigin( aFrame.origin );
|
||||
|
||||
aFrame.origin.x:= 4;
|
||||
aFrame.origin.x:= CocoaConfigListView.vsReport.column.controlSpacing;
|
||||
end;
|
||||
|
||||
if Assigned(self.imageView) then begin
|
||||
@ -1286,7 +1287,7 @@ begin
|
||||
aFrame.size:= tv.iconSize;
|
||||
self.imageView.setFrame( aFrame );
|
||||
|
||||
aFrame.origin.x:= aFrame.origin.x + 4;
|
||||
aFrame.origin.x:= aFrame.origin.x + CocoaConfigListView.vsReport.column.controlSpacing;
|
||||
end;
|
||||
|
||||
if Assigned(self.textField) then begin
|
||||
@ -1295,8 +1296,8 @@ begin
|
||||
aFrame.origin.y:= round( (rowHeight - self.textField.frame.size.height) / 2 );
|
||||
aFrame.size.width:= _column.width - aFrame.origin.x;
|
||||
aFrame.size.height:= self.textField.frame.size.height;
|
||||
if aFrame.size.width < 16 then
|
||||
aFrame.size.width:= 16;
|
||||
if aFrame.size.width < CocoaConfigListView.vsReport.column.textFieldMinWidth then
|
||||
aFrame.size.width:= CocoaConfigListView.vsReport.column.textFieldMinWidth;
|
||||
self.textField.setFrame( aFrame );
|
||||
end;
|
||||
end;
|
||||
@ -1852,7 +1853,8 @@ begin
|
||||
|
||||
_tableView.iconSize.Width:= AValue.Width;
|
||||
_tableView.iconSize.Height:= AValue.Height;
|
||||
_tableView.CustomRowHeight:= AValue.Height + 8;
|
||||
_tableView.CustomRowHeight:= AValue.Height +
|
||||
CocoaConfigListView.vsReport.row.imageLineSpacing;
|
||||
|
||||
_tableView.reloadData;
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user