channelwidget: ensure that all channel labels have the same width

pavucontrol.glade previously set the channel label width to 15
characters, with the goal of making all channel labels have the same
width. However, with some translations and font settings the configured
width wasn't enough, so sometimes a label was wider than others, and
that made the volume slider widths different too. If the volume sliders
have different widths, it's very hard to visually compare the volumes of
the channels.

This patch removes the fixed width in pavucontrol.glade and solves the
problem by finding the widest label and using that label's width with
all labels.

Fixes: https://gitlab.freedesktop.org/pulseaudio/pavucontrol/issues/51
This commit is contained in:
Tanu Kaskinen 2018-12-12 11:41:16 +02:00
parent f200a10d98
commit 5f664bc63b
2 changed files with 18 additions and 2 deletions

View File

@ -67,10 +67,27 @@ ChannelWidget* ChannelWidget::createOne(MinimalStreamWidget *owner, int channelI
}
void ChannelWidget::create(MinimalStreamWidget *owner, const pa_channel_map &m, bool can_decibel, ChannelWidget *widgets[PA_CHANNELS_MAX]) {
for (int i = 0; i < m.channels; i++)
int maxLabelWidth = 0;
for (int i = 0; i < m.channels; i++) {
widgets[i] = ChannelWidget::createOne(owner, i, m.map[i], can_decibel);
Gtk::Requisition minimumSize;
Gtk::Requisition naturalSize;
widgets[i]->channelLabel->get_preferred_size(minimumSize, naturalSize);
if (naturalSize.width > maxLabelWidth)
maxLabelWidth = naturalSize.width;
}
widgets[m.channels - 1]->last = true;
/* The channel labels have different widths by default, which makes the
* volume slider widths different too. The volume sliders must have the
* same width, otherwise it's very hard to see how the volumes of different
* channels relate to each other, so we have to change all channel labels
* to have the same width. */
for (int i = 0; i < m.channels; i++)
widgets[i]->channelLabel->set_size_request(maxLabelWidth, -1);
}
void ChannelWidget::setVolume(pa_volume_t volume) {

View File

@ -24,7 +24,6 @@
<property name="can_focus">False</property>
<property name="label" translatable="yes">&lt;b&gt;left-front&lt;/b&gt;</property>
<property name="use_markup">True</property>
<property name="width_chars">15</property>
<property name="xalign">1</property>
<property name="yalign">0</property>
</object>