Skip to content

Commit 71bb990

Browse files
authoredMar 6, 2024
Add hover effect intensity property to boolean cell (glideapps#912)
* Parameter to tweak hover effect intensity in boolean cell * Fix lock again
1 parent cf6c69a commit 71bb990

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed
 

‎packages/core/src/cells/boolean-cell.tsx

+27-11
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@ export const booleanCellRenderer: InternalCellRenderer<BooleanCell> = {
1919
useLabel: false,
2020
needsHoverPosition: true,
2121
measure: () => 50,
22-
draw: a => drawBoolean(a, a.cell.data, booleanCellIsEditable(a.cell), a.cell.maxSize ?? defaultCellMaxSize),
22+
draw: a =>
23+
drawBoolean(
24+
a,
25+
a.cell.data,
26+
booleanCellIsEditable(a.cell),
27+
a.cell.maxSize ?? defaultCellMaxSize,
28+
a.cell.hoverEffectIntensity ?? 0.35
29+
),
2330
onDelete: c => ({
2431
...c,
2532
data: false,
@@ -70,7 +77,8 @@ function drawBoolean(
7077
args: BaseDrawArgs,
7178
data: boolean | BooleanEmpty | BooleanIndeterminate,
7279
canEdit: boolean,
73-
maxSize?: number
80+
maxSize: number,
81+
hoverEffectIntensity: number
7482
) {
7583
if (!canEdit && data === BooleanEmpty) {
7684
return;
@@ -87,18 +95,26 @@ function drawBoolean(
8795
} = args;
8896
const { x, y, width: w, height: h } = rect;
8997

90-
const hoverEffect = 0.35;
98+
// Don't set the global alpha unnecessarily
99+
let shouldRestoreAlpha = false;
100+
if (hoverEffectIntensity > 0) {
101+
let alpha = canEdit ? 1 - hoverEffectIntensity + hoverEffectIntensity * hoverAmount : 0.4;
102+
if (data === BooleanEmpty) {
103+
alpha *= hoverAmount;
104+
}
105+
if (alpha === 0) {
106+
return;
107+
}
91108

92-
let alpha = canEdit ? 1 - hoverEffect + hoverEffect * hoverAmount : 0.4;
93-
if (data === BooleanEmpty) {
94-
alpha *= hoverAmount;
95-
}
96-
if (alpha === 0) {
97-
return;
109+
if (alpha < 1) {
110+
shouldRestoreAlpha = true;
111+
ctx.globalAlpha = alpha;
112+
}
98113
}
99-
ctx.globalAlpha = alpha;
100114

101115
drawCheckbox(ctx, theme, data, x, y, w, h, highlighted, hoverX, hoverY, maxSize, contentAlign);
102116

103-
ctx.globalAlpha = 1;
117+
if (shouldRestoreAlpha) {
118+
ctx.globalAlpha = 1;
119+
}
104120
}

‎packages/core/src/internal/data-grid/data-grid-types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ export interface BooleanCell extends BaseGridCell {
443443
readonly readonly?: boolean;
444444
readonly allowOverlay: false;
445445
readonly maxSize?: number;
446+
readonly hoverEffectIntensity?: number;
446447
}
447448

448449
// Can be written more concisely, not easier to read if more concise.

0 commit comments

Comments
 (0)
Failed to load comments.