Skip to content
Advertisement

Make status trimbar contribution grow when its content changes

I’m trying to add an Eclipse status trimbar contribution where the contents of the contribution (i.e., child elements’ text) dynamically change. Note that I’m not trying to add "line, column" information into the status bar.

Ideally, the contribution’s width should adapt to the width of its contents, a bit like what happens in VSCode:

enter image description here enter image description here

However, if that isn’t easily feasible, an acceptable alternative would be to have a “fixed” width for the status trimbar, or even a fixed width for each individual child (since I don’t intend to have children appearing and disappearing).

Below is what I’ve tried. How do you think I should do this if nothing I’ve tried for the past 2 days worked?

In case you think the problem might actually be an Eclipse bug, note that I’m using Eclipse version 2021-06 (4.20.0) on Linux.


What I have tried

I have this in plugin.xml:

JavaScript

I’ve tried doing this in at least 4 different ways. As a reference, here is the class StatusTrimBarContribution:

JavaScript

Attempt #1

In this attempt we add an intermediary Composite between the labels and parent, we use a GridLayout on the intermediary, and we add a GridData into m_lbl.

JavaScript

The result is that the labels are too tall and get truncated. Note that I’ve also tried setting the margin height to 0, and, while it’s better than below, the labels would still get truncated.

enter image description here

Attempt #2

Compared to #1, we remove the intermediary Composite, and instead use the layout directly on parent. Also, we remove the GridData, because, at this point, why not.

JavaScript

The result is the same as before, except, additionally, that m_lbl is not large enough to hold the text:

enter image description here

Attempt #3

Compared to #2, we additionally remove the layout.

JavaScript

The labels are no longer too tall, however, the width of the labels is still to small for the text:

enter image description here

Attempt #4

Compared to #3, we initially assign a very long string into m_lbl.

JavaScript

The result is that both labels are completely visible, but now m_lbl2 has the same width as m_lbl, which is far more than I want. Plus, if the user’s font is different from mine, the width of the labels might become too large or too small due to the initial string.

enter image description here

Advertisement

Answer

Using the minimum width setting of GridData works for me:

JavaScript

Note: Changing the layout of parent is against the rules, it could damage the layout of other components.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement