From 0a0f7a09a48f5afe39276f2c618e7e11b63b794b Mon Sep 17 00:00:00 2001 From: Dorota Czaplejewicz Date: Wed, 28 Aug 2019 10:40:16 +0000 Subject: [PATCH] Check for button position more in Rust The check against fitting inside the Layout was removed: as an optimization it is unneeded, as the actual search must be optimized to be quick. In addition, the view bounds don't correspond to anything physical as long as negative offsets are allowed. --- eek/eek-renderer.c | 14 ++------------ src/layout.rs | 11 +++++++++-- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/eek/eek-renderer.c b/eek/eek-renderer.c index 3e341318..a8a46dca 100644 --- a/eek/eek-renderer.c +++ b/eek/eek-renderer.c @@ -978,20 +978,10 @@ eek_renderer_find_button_by_position (EekRenderer *renderer, g_return_val_if_fail (EEK_IS_RENDERER(renderer), NULL); EekRendererPrivate *priv = eek_renderer_get_instance_private (renderer); - EekBounds bounds = squeek_view_get_bounds (view); - /* Transform from widget coordinates to keyboard coordinates */ - x = (x - priv->origin_x)/priv->scale - bounds.x; - y = (y - priv->origin_y)/priv->scale - bounds.y; - - if (x < 0 || - y < 0 || - x > bounds.width || - y > bounds.height) - return NULL; EekPoint point = { - .x = x, - .y = y, + .x = (x - priv->origin_x)/priv->scale, + .y = (y - priv->origin_y)/priv->scale, }; return squeek_view_find_button_by_position(view, point); } diff --git a/src/layout.rs b/src/layout.rs index bd70272c..b21d5d23 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -568,7 +568,7 @@ pub struct Button { pub state: Rc>, } - +// FIXME: derive from the style/margin/padding const BUTTON_SPACING: f64 = 4.0; const ROW_SPACING: f64 = 7.0; @@ -710,10 +710,17 @@ impl View { } /// Finds the first button that covers the specified point - /// relative to view's origin + /// relative to view's position's origin fn find_button_by_position(&mut self, point: c::Point) -> Option<&mut Box