-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Picker style details; numpad layout in picker; shift+click text
- Loading branch information
Showing
12 changed files
with
170 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use super::variable_width::{PickerVariableWidthGroup, KEY_SIZE, KEY_SPACE}; | ||
|
||
static KEY_WIDTHS: &[(f64, &[&str])] = &[(2.0 * KEY_SIZE + KEY_SPACE, &["NUM_0"])]; | ||
|
||
static KEY_HEIGHTS: &[(f64, &[&str])] = &[(2.0 * KEY_SIZE + KEY_SPACE, &["NUM_PLUS", "NUM_ENTER"])]; | ||
|
||
static ROWS: &[&[&str]] = &[ | ||
&["NUM_LOCK", "NUM_SLASH", "NUM_ASTERISK", "NUM_MINUS"], | ||
&["NUM_7", "NUM_8", "NUM_9", "NUM_PLUS"], | ||
&["NUM_4", "NUM_5", "NUM_6"], | ||
&["NUM_1", "NUM_2", "NUM_3", "NUM_ENTER"], | ||
&["NUM_0", "NUM_PERIOD"], | ||
]; | ||
|
||
pub fn picker_numpad_group() -> PickerVariableWidthGroup { | ||
PickerVariableWidthGroup::new(ROWS, KEY_WIDTHS, KEY_HEIGHTS, Some("Numpad"), None) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
use cascade::cascade; | ||
use gtk::{pango, prelude::*}; | ||
|
||
use super::{PickerGroup, PickerKey}; | ||
|
||
pub const KEY_SIZE: f64 = 48.0; | ||
pub const KEY_SPACE: f64 = 4.0; | ||
|
||
pub struct PickerVariableWidthGroup { | ||
keys: Vec<PickerKey>, | ||
widget: gtk::Box, | ||
} | ||
|
||
impl PickerVariableWidthGroup { | ||
pub fn new( | ||
rows: &[&[&str]], | ||
widths: &[(f64, &[&str])], | ||
heights: &[(f64, &[&str])], | ||
label: Option<&str>, | ||
desc: Option<&str>, | ||
) -> Self { | ||
let mut keys = Vec::new(); | ||
|
||
let vbox = cascade! { | ||
gtk::Box::new(gtk::Orientation::Vertical, 4); | ||
..show(); | ||
}; | ||
|
||
if let Some(label) = label { | ||
let label = cascade! { | ||
gtk::Label::new(Some(&label)); | ||
..set_attributes(Some(&cascade! { | ||
pango::AttrList::new(); | ||
..insert(pango::AttrInt::new_weight(pango::Weight::Bold)); | ||
} )); | ||
..set_halign(gtk::Align::Start); | ||
..set_margin_bottom(8); | ||
..show(); | ||
}; | ||
vbox.add(&label); | ||
} | ||
|
||
let fixed = gtk::Fixed::new(); | ||
vbox.add(&fixed); | ||
|
||
let mut y = 0; | ||
for row in rows { | ||
let mut x = 0; | ||
for name in *row { | ||
let width = widths | ||
.iter() | ||
.find_map(|(width, keys)| { | ||
if keys.contains(name) { | ||
Some(*width) | ||
} else { | ||
None | ||
} | ||
}) | ||
.unwrap_or(KEY_SIZE); | ||
let height = heights | ||
.iter() | ||
.find_map(|(height, keys)| { | ||
if keys.contains(name) { | ||
Some(*height) | ||
} else { | ||
None | ||
} | ||
}) | ||
.unwrap_or(KEY_SIZE); | ||
let key = PickerKey::new(name, width / KEY_SIZE, height / KEY_SIZE); | ||
fixed.put(&key, x, y); | ||
keys.push(key); | ||
x += width as i32 + 4 | ||
} | ||
y += KEY_SIZE as i32 + 4; | ||
} | ||
|
||
if let Some(desc) = desc { | ||
let label = cascade! { | ||
gtk::Label::new(Some(&desc)); | ||
..set_halign(gtk::Align::Start); | ||
..show(); | ||
}; | ||
vbox.add(&label); | ||
} | ||
|
||
Self { keys, widget: vbox } | ||
} | ||
} | ||
|
||
impl PickerGroup for PickerVariableWidthGroup { | ||
fn keys(&self) -> &[PickerKey] { | ||
&self.keys | ||
} | ||
|
||
fn widget(&self) -> >k::Widget { | ||
self.widget.upcast_ref() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.