keyboard: Simplify KeyContainer
We no longer have any guesswork during layout creation, we can attach key actors directly to the grid without a second step. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3162>
This commit is contained in:
parent
6e80f858c8
commit
9a340c6d66
@ -94,55 +94,29 @@ class KeyContainer extends St.Widget {
|
|||||||
y_expand: true,
|
y_expand: true,
|
||||||
});
|
});
|
||||||
this._gridLayout = gridLayout;
|
this._gridLayout = gridLayout;
|
||||||
this._currentRow = 0;
|
this._nRows = 0;
|
||||||
this._currentCol = 0;
|
this._currentCol = 0;
|
||||||
this._maxCols = 0;
|
this._maxCols = 0;
|
||||||
|
|
||||||
this._currentRow = null;
|
|
||||||
this._rows = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
appendRow() {
|
appendRow() {
|
||||||
this._currentRow++;
|
this._nRows++;
|
||||||
this._currentCol = 0;
|
this._currentCol = 0;
|
||||||
|
|
||||||
let row = {
|
|
||||||
keys: [],
|
|
||||||
width: 0,
|
|
||||||
};
|
|
||||||
this._rows.push(row);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
appendKey(key, width = 1, height = 1, leftOffset = 0) {
|
appendKey(key, width = 1, height = 1, leftOffset = 0) {
|
||||||
const keyInfo = {
|
const left = this._currentCol + leftOffset;
|
||||||
key,
|
const top = this._nRows;
|
||||||
left: this._currentCol + leftOffset,
|
this._gridLayout.attach(key,
|
||||||
top: this._currentRow,
|
left * KEY_SIZE, top * KEY_SIZE,
|
||||||
width,
|
width * KEY_SIZE, height * KEY_SIZE);
|
||||||
height,
|
|
||||||
};
|
|
||||||
|
|
||||||
let row = this._rows[this._rows.length - 1];
|
|
||||||
row.keys.push(keyInfo);
|
|
||||||
row.width += width;
|
|
||||||
|
|
||||||
this._currentCol += leftOffset + width;
|
this._currentCol += leftOffset + width;
|
||||||
this._maxCols = Math.max(this._currentCol, this._maxCols);
|
this._maxCols = Math.max(this._currentCol, this._maxCols);
|
||||||
}
|
}
|
||||||
|
|
||||||
layoutButtons() {
|
|
||||||
this._rows.forEach(row => {
|
|
||||||
row.keys.forEach(keyInfo => {
|
|
||||||
const {left, top, width, height} = keyInfo;
|
|
||||||
this._gridLayout.attach(keyInfo.key,
|
|
||||||
left * KEY_SIZE, top * KEY_SIZE,
|
|
||||||
width * KEY_SIZE, height * KEY_SIZE);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
getRatio() {
|
getRatio() {
|
||||||
return [this._maxCols, this._rows.length];
|
return [this._maxCols, this._nRows];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1056,7 +1030,6 @@ const EmojiSelection = GObject.registerClass({
|
|||||||
this.emit('close-request');
|
this.emit('close-request');
|
||||||
});
|
});
|
||||||
row.appendKey(key);
|
row.appendKey(key);
|
||||||
row.layoutButtons();
|
|
||||||
|
|
||||||
const actor = new AspectContainer({
|
const actor = new AspectContainer({
|
||||||
layout_manager: new Clutter.BinLayout(),
|
layout_manager: new Clutter.BinLayout(),
|
||||||
@ -1430,7 +1403,6 @@ export const Keyboard = GObject.registerClass({
|
|||||||
|
|
||||||
layers[currentLevel.level] = levelLayout;
|
layers[currentLevel.level] = levelLayout;
|
||||||
layout.add_child(levelLayout);
|
layout.add_child(levelLayout);
|
||||||
levelLayout.layoutButtons();
|
|
||||||
levelLayout.hide();
|
levelLayout.hide();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user