diff --git a/src/widgets/label.ts b/src/widgets/label.ts index 0d485ae..f6c530c 100644 --- a/src/widgets/label.ts +++ b/src/widgets/label.ts @@ -1,7 +1,9 @@ import GObject from 'gi://GObject'; import Gtk from 'gi://Gtk?version=3.0'; +import Pango from 'gi://Pango'; const justification = ['left', 'center', 'right', 'fill']; +const truncate = ['none', 'start', 'middle', 'end']; export default class AgsLabel extends Gtk.Label { static { @@ -13,6 +15,11 @@ export default class AgsLabel extends Gtk.Label { GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT, '', ), + 'truncate': GObject.ParamSpec.string( + 'truncate', 'Truncate', 'Truncate', + GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT, + '', + ), }, }, this); } @@ -21,8 +28,22 @@ export default class AgsLabel extends Gtk.Label { super(typeof params === 'string' ? { label: params } : params); } + get truncate() { return truncate[this.ellipsize]; } + set truncate(truncate: string) { + if (!truncate) + return; + + if (!truncate.includes(truncate)) { + console.error('wrong truncate value for Label'); + return; + } + + // @ts-ignore + this.ellipsize = Pango.EllipsizeMode[truncate.toUpperCase()]; + } + get justification() { return justification[this.justify]; } - set justification(justify) { + set justification(justify: string) { if (!justify) return;