padOsd: Move button/ring/strip label creation to PadDiagram

It's the natural container of those. We can create all those labels
internally, and only expose the updateLabels() method to update them
wholesome.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1290
This commit is contained in:
Carlos Garnacho 2020-05-28 14:03:13 +02:00 committed by Florian Müllner
parent 963f96292d
commit c90e7ce258

View File

@ -329,6 +329,7 @@ var PadDiagram = GObject.registerClass({
this._imagePath = imagePath;
this._handle = this._composeStyledDiagram();
this._initLabels();
}
// eslint-disable-next-line camelcase
@ -343,6 +344,33 @@ var PadDiagram = GObject.registerClass({
this.add_actor(actor);
}
_initLabels() {
// FIXME: Fix num buttons.
let i = 0;
for (i = 0; i < 50; i++) {
let [found] = this.getButtonLabelCoords(i);
if (!found)
break;
this._addLabel(Meta.PadActionType.BUTTON, i);
}
for (i = 0; i < 2; i++) {
let [found] = this.getRingLabelCoords(i, CW);
if (!found)
break;
this._addLabel(Meta.PadActionType.RING, i, CW);
this._addLabel(Meta.PadActionType.RING, i, CCW);
}
for (i = 0; i < 2; i++) {
let [found] = this.getStripLabelCoords(i, UP);
if (!found)
break;
this._addLabel(Meta.PadActionType.STRIP, i, UP);
this._addLabel(Meta.PadActionType.STRIP, i, DOWN);
}
}
_wrappingSvgHeader() {
return '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' +
'<svg version="1.1" xmlns="http://www.w3.org/2000/svg" ' +
@ -557,7 +585,8 @@ var PadDiagram = GObject.registerClass({
this._invalidateSvg();
}
addLabel(label, type, idx, dir) {
_addLabel(type, idx, dir) {
let label = new St.Label();
this._labels.push([label, type, idx, dir]);
this.add_actor(label);
}
@ -711,31 +740,7 @@ var PadOsd = GObject.registerClass({
x_expand: true,
y_expand: true });
this.add_actor(this._padDiagram);
// FIXME: Fix num buttons.
let i = 0;
for (i = 0; i < 50; i++) {
let [found] = this._padDiagram.getButtonLabelCoords(i);
if (!found)
break;
this._createLabel(Meta.PadActionType.BUTTON, i);
}
for (i = 0; i < padDevice.get_n_rings(); i++) {
let [found] = this._padDiagram.getRingLabelCoords(i, CW);
if (!found)
break;
this._createLabel(Meta.PadActionType.RING, i, CW);
this._createLabel(Meta.PadActionType.RING, i, CCW);
}
for (i = 0; i < padDevice.get_n_strips(); i++) {
let [found] = this._padDiagram.getStripLabelCoords(i, UP);
if (!found)
break;
this._createLabel(Meta.PadActionType.STRIP, i, UP);
this._createLabel(Meta.PadActionType.STRIP, i, DOWN);
}
this._updateActionLabels();
let buttonBox = new St.Widget({ layout_manager: new Clutter.BinLayout(),
x_expand: true,
@ -788,11 +793,6 @@ var PadOsd = GObject.registerClass({
return str ? str : _("None");
}
_createLabel(type, number, dir) {
let label = new St.Label({ text: this._getActionText(type, number) });
this._padDiagram.addLabel(label, type, number, dir);
}
_updateActionLabels() {
this._padDiagram.updateLabels(this._getActionText.bind(this));
}