问题描述
所以我正在制作一个 gnome shell 扩展,但我不知道如何使我的扩展的一部分具有正常的字体粗细。这是我的 extension.js 文件:
'use strict';
const { St,clutter } = imports.gi;
const Main = imports.ui.main;
let _myText;
class Extension {
enable() {
_myText = new St.Label({ text: 'This should be normal font weight.',y_align: clutter.ActorAlign.CENTER,style_class: 'panel-button',track_hover: false,reactive: false});
Main.panel._leftBox.insert_child_at_index(_myText,10)
}
disable() {
_myText.destroy();
}
}
function init() {
return new Extension();
}
这是我的 stylesheet.css 文件:
StLabel._myText {
font-weight: normal;
}
我做错了什么?
解决方法
你不能只在 CSS 中使用任意的 JavaScript 变量;你需要告诉一个小部件它应该使用什么 CSS 名称和类:
.my-class {
font-weight: normal;
}
const myLabel = new St.Label({
text: 'My Label',style_class: 'panel-button my-class',});
另见:
- Anatomy of an Extension 在 gjs.guide
-
St
Documentation 在 gjs-docs.gnome.org