我有一个Desklet
由Button
. 有Button
一个Label
(带有一些文字)和一个Tooltip
:
const Desklet = imports.ui.desklet;
const St = imports.gi.St;
const Tooltips = imports.ui.tooltips;
function MyDesklet(metadata, desklet_id) {
this._init(metadata, desklet_id);
}
MyDesklet.prototype = {
__proto__: Desklet.Desklet.prototype,
_init: function(metadata, desklet_id) {
Desklet.Desklet.prototype._init.call(this, metadata, desklet_id);
this.setupUI();
},
setupUI: function() {
// main container for the desklet
this.boxLayout = new St.BoxLayout({
vertical: true,
width: 100,
height: 40
});
let label = new St.Label({text: "Label text"});
// style does not work
let button = new St.Button({child: label, style: "text-align: left;"});
let tooltip = new Tooltips.Tooltip(button,
_("Tooltip\ntext"));
// Does not work
tooltip.style = "text-align: left;";
this.boxLayout.add_actor(button);
this.setContent(this.boxLayout);
}
}
function main(metadata, desklet_id) {
return new MyDesklet(metadata, desklet_id);
}
上面的代码生成了这个 Desklet:
Label
内部的文本Button
和文本如何Tooltip
左对齐而不是居中?