core: layout: omit bottom row when explicitly disabled by main layout
The main layout (e.g. latn_bone.xml and latn_neo2.xml) may disable the bottom row by adding a property to the XML keyboard tag. Omit the bottom row when this is the case.
This commit is contained in:
parent
1391589ce0
commit
57265544ab
1 changed files with 30 additions and 17 deletions
|
|
@ -519,6 +519,7 @@ const KEYSYMS: [(&str, Keysym, &str); 21] = [
|
||||||
|
|
||||||
struct LayoutFile {
|
struct LayoutFile {
|
||||||
rows: Vec<Vec<Key>>,
|
rows: Vec<Vec<Key>>,
|
||||||
|
has_bottom_row: bool,
|
||||||
width: f64,
|
width: f64,
|
||||||
height: f64,
|
height: f64,
|
||||||
row_width: f64,
|
row_width: f64,
|
||||||
|
|
@ -581,12 +582,21 @@ impl LayoutFile {
|
||||||
self.row_width = 0.0;
|
self.row_width = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn start_keyboard(&mut self, attrs: &HashMap<&str, &str>)
|
||||||
|
{
|
||||||
|
if *attrs.get("bottom_row").unwrap_or(&"") == "false" {
|
||||||
|
self.has_bottom_row = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn start_elem(&mut self, name: &str, attrs: &HashMap<&str, &str>)
|
fn start_elem(&mut self, name: &str, attrs: &HashMap<&str, &str>)
|
||||||
{
|
{
|
||||||
if name == "key" {
|
if name == "key" {
|
||||||
self.start_key(attrs);
|
self.start_key(attrs);
|
||||||
} else if name == "row" {
|
} else if name == "row" {
|
||||||
self.start_row();
|
self.start_row();
|
||||||
|
} else if name == "keyboard" {
|
||||||
|
self.start_keyboard(attrs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -612,6 +622,7 @@ impl LayoutFile {
|
||||||
{
|
{
|
||||||
let mut layout = LayoutFile {
|
let mut layout = LayoutFile {
|
||||||
rows: Vec::new(),
|
rows: Vec::new(),
|
||||||
|
has_bottom_row: true,
|
||||||
width: 0.0,
|
width: 0.0,
|
||||||
height: 0.0,
|
height: 0.0,
|
||||||
row_width: 0.0,
|
row_width: 0.0,
|
||||||
|
|
@ -707,27 +718,29 @@ impl Layout {
|
||||||
text_supp: false,
|
text_supp: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
let path = dir.join("bottom_row.xml");
|
if main_layout.has_bottom_row {
|
||||||
let bottom_row = LayoutFile::load(path)?;
|
let path = dir.join("bottom_row.xml");
|
||||||
|
let bottom_row = LayoutFile::load(path)?;
|
||||||
|
|
||||||
let old_height = layout.height;
|
let old_height = layout.height;
|
||||||
layout.height += bottom_row.height;
|
layout.height += bottom_row.height;
|
||||||
|
|
||||||
layout.rows.reserve(bottom_row.rows.len());
|
layout.rows.reserve(bottom_row.rows.len());
|
||||||
for row in bottom_row.rows {
|
for row in bottom_row.rows {
|
||||||
let mut new_row = Vec::with_capacity(row.len());
|
let mut new_row = Vec::with_capacity(row.len());
|
||||||
|
|
||||||
for key in row {
|
for key in row {
|
||||||
new_row.push(Key {
|
new_row.push(Key {
|
||||||
parts: key.parts,
|
parts: key.parts,
|
||||||
x1: key.x1 * layout.width / bottom_row.width,
|
x1: key.x1 * layout.width / bottom_row.width,
|
||||||
y1: old_height + key.y1,
|
y1: old_height + key.y1,
|
||||||
x2: key.x2 * layout.width / bottom_row.width,
|
x2: key.x2 * layout.width / bottom_row.width,
|
||||||
y2: old_height + key.y2,
|
y2: old_height + key.y2,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
layout.rows.push(new_row);
|
||||||
}
|
}
|
||||||
|
|
||||||
layout.rows.push(new_row);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(layout)
|
Ok(layout)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue