0

我正在编写我的第一个 Cinnamon 小程序(在我设法编写了一个小程序之后)。

我有一个St.BoxLayout嵌入在PopupMenu.PopupBaseMenuItem一个弹出菜单中。

现在我希望它的宽度是弹出菜单宽度的 100%,但它(即1 +2 = 3屏幕截图中包含的框)看起来像这样,并且只取它的最小宽度来包含嵌入的文本,并且当你输入它时它会增长:

屏幕截图 Cinnamon calc 小程序

我试过了:

  • 一个 style_classexpression-box和 CSSwidth: 100%
  • x_align: Clutter.ActorAlign.FILL,
  • x_expand: true

但它只是没有扩大它的宽度。我还能尝试什么?

我必须承认,我仍在寻找广泛的 CJS / GJS 文档,浏览其他小程序的资源似乎是找出实际工作的最佳方式......

这是代码:

applet.js

        this.widgets.expressionItem = new PopupMenu.PopupBaseMenuItem({reactive: false, focusOnHover: true});
        this.menu.addMenuItem(this.widgets.expressionItem);
        this.widgets.expressionBox = new St.BoxLayout({
            style_class: "expression-box",
            vertical: true,
            x_align: Clutter.ActorAlign.FILL,
            x_expand: true
        })

stylesheet.css

.expression-box {
    background-color: lightslategray;
    color: black;
    border-radius: 4px;
    width: 100%;
    padding: 4px;
}

您可以在 GitHub 中找到完整的源代码

4

1 回答 1

1

在这种情况下,CSS 不会帮助您进行布局,因为这是由小部件工具包处理的。虽然像素宽度width: 100px;可能会起作用,但百分比不会(除非最近发生了一些变化)。

看起来 Cinnamon 正在使用 JavaScript 包装器围绕 Clutter 演员。当前 master 中的函数如下所示:

// adds an actor to the menu item; @params can contain %span
// (column span; defaults to 1, -1 means "all the remaining width", 0 means "no new column after this actor"),
// %expand (defaults to #false), and %align (defaults to
// #St.Align.START)
addActor(child, params) {
    params = Params.parse(params, { span: 1,
                                    expand: false,
                                    align: St.Align.START });
    params.actor = child;
    this._children.push(params);
    this._signals.connect(this.actor, 'destroy', this._removeChild.bind(this, child));
    this.actor.add_actor(child);
}

这也是 GNOME Shell 中使用的先前方法,但正如您所见,这里的分配变得相当复杂。由于我不使用 Cinnamon,因此我无法自己进行测试,但我假设您需要添加具有所需参数的子演员,例如:

this.widgets.expressionItem.addActor(this.widgets.expressionBox, {
    expand: true,
    span: -1,
});

目前尚不清楚 on 的子属性是否St.BoxLayout会在这里产生影响,但您可能需要稍微尝试一下才能获得所需的效果。

于 2021-12-11T00:47:27.093 回答