Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable text eliding by default #451

Merged
merged 5 commits into from
Nov 2, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions packages/datagrid/src/textrenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class TextRenderer extends CellRenderer {
this.verticalAlignment = options.verticalAlignment || 'center';
this.horizontalAlignment = options.horizontalAlignment || 'left';
this.format = options.format || TextRenderer.formatGeneric();
this.elideDirection = options.elideDirection || 'right';
this.elideDirection = options.elideDirection || 'none';
this.wrapText = options.wrapText || false;
}

Expand Down Expand Up @@ -63,7 +63,7 @@ export class TextRenderer extends CellRenderer {
readonly format: TextRenderer.FormatFunc;

/**
* Which side to draw the ellipsis.
* Which side to draw the ellipsis. Set to 'none' to disable ellipsis.
*/
readonly elideDirection: CellRenderer.ConfigOption<TextRenderer.ElideDirection>;

Expand Down Expand Up @@ -213,6 +213,12 @@ export class TextRenderer extends CellRenderer {
gc.textAlign = hAlign;
gc.textBaseline = 'bottom';

// Terminate call here if we're not eliding or wrapping text
if (elideDirection === 'none' && !wrapText) {
gc.fillText(text, textX, textY);
return;
}

// The current text width in pixels.
let textWidth = gc.measureText(text).width;

Expand Down Expand Up @@ -345,7 +351,7 @@ export namespace TextRenderer {
/**
* A type alias for the supported ellipsis sides.
*/
export type ElideDirection = 'left' | 'right';
export type ElideDirection = 'left' | 'right' | 'none';

/**
* An options object for initializing a text renderer.
Expand Down Expand Up @@ -396,7 +402,7 @@ export namespace TextRenderer {
/**
* The ellipsis direction for the cell text.
*
* The default is `'right'`.
* The default is `'none'`.
*/
elideDirection?: CellRenderer.ConfigOption<ElideDirection>;

Expand Down