mirror of
https://github.com/zoriya/ags.git
synced 2026-06-09 04:46:08 +00:00
add label truncate property
This commit is contained in:
+22
-1
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user