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
Show file tree
Hide file tree
Changes from all 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
8 changes: 7 additions & 1 deletion packages/datagrid/src/hyperlinkrenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ export class HyperlinkRenderer extends TextRenderer {
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 @@ -291,7 +297,7 @@ export namespace HyperlinkRenderer {
/**
* 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
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
4 changes: 2 additions & 2 deletions review/api/datagrid.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ export class HyperlinkRenderer extends TextRenderer {

// @public (undocumented)
export namespace HyperlinkRenderer {
export type ElideDirection = 'left' | 'right';
export type ElideDirection = 'left' | 'right' | 'none';
export type HorizontalAlignment = 'left' | 'center' | 'right';
export interface IOptions extends TextRenderer.IOptions {
url?: CellRenderer.ConfigOption<string> | undefined;
Expand Down Expand Up @@ -907,7 +907,7 @@ export class TextRenderer extends CellRenderer {

// @public
export namespace TextRenderer {
export type ElideDirection = 'left' | 'right';
export type ElideDirection = 'left' | 'right' | 'none';
export function formatDate(options?: formatDate.IOptions): FormatFunc;
export namespace formatDate {
export interface IOptions {
Expand Down