Fix dumb flooring error in window sizing/positioning calculations (fixes #30)

This commit is contained in:
elkowar 2020-10-20 22:09:39 +02:00
parent 89c006e040
commit 7f39205c92
2 changed files with 5 additions and 4 deletions

View file

@ -217,19 +217,19 @@ fn on_screen_changed(window: &gtk::Window, _old_screen: Option<&gdk::Screen>) {
fn get_window_rectangle_in_screen(screen_rect: gdk::Rectangle, pos: Coords, size: Coords) -> gdk::Rectangle {
gdk::Rectangle {
x: match pos.x {
NumWithUnit::Percent(n) => (screen_rect.width as f64 / 100.0).floor() as i32 * n,
NumWithUnit::Percent(n) => ((screen_rect.width as f64 / 100.0) * n as f64) as i32,
NumWithUnit::Pixels(n) => screen_rect.x + n,
},
y: match pos.y {
NumWithUnit::Percent(n) => (screen_rect.height as f64 / 100.0).floor() as i32 * n,
NumWithUnit::Percent(n) => ((screen_rect.height as f64 / 100.0) * n as f64) as i32,
NumWithUnit::Pixels(n) => screen_rect.y + n,
},
width: match size.x {
NumWithUnit::Percent(n) => (screen_rect.width as f64 / 100.0).floor() as i32 * n,
NumWithUnit::Percent(n) => ((screen_rect.width as f64 / 100.0) * n as f64) as i32,
NumWithUnit::Pixels(n) => n,
},
height: match size.y {
NumWithUnit::Percent(n) => (screen_rect.height as f64 / 100.0).floor() as i32 * n,
NumWithUnit::Percent(n) => ((screen_rect.height as f64 / 100.0) * n as f64) as i32,
NumWithUnit::Pixels(n) => n,
},
}

View file

@ -270,6 +270,7 @@ fn build_gtk_label(bargs: &mut BuilderArgs) -> Result<gtk::Label> {
let gtk_widget = gtk::Label::new(None);
resolve_block!(bargs, gtk_widget, {
// @prop - the text to display
// @prop limit-width - maximum count of characters to display
prop(text: as_string, limit_width: as_i32 = i32::MAX) {
gtk_widget.set_text(&text.chars().take(limit_width as usize).collect::<String>())
},