layout: Store location in FocusRing
Browse files at this commitb283f546aafd767aeb065c14ff891c9d8f4a09abParent: 15b6c841 changed file +19 -12
- src/layout.rs +19 -12
src/layout.rsmodified+19 -12
| @@ -189,6 +189,7 @@ pub struct Workspace<W: LayoutElement> { | |||
| 189 | #[derive(Debug)] | 189 | #[derive(Debug)] |
| 190 | struct FocusRing { | 190 | struct FocusRing { |
| 191 | buffer: SolidColorBuffer, | 191 | buffer: SolidColorBuffer, |
| 192 | + location: Point<i32, Logical>, | ||
| 192 | is_off: bool, | 193 | is_off: bool, |
| 193 | width: i32, | 194 | width: i32, |
| 194 | active_color: Color, | 195 | active_color: Color, |
| @@ -335,6 +336,11 @@ impl FocusRing { | |||
| 335 | self.buffer.resize(size); | 336 | self.buffer.resize(size); |
| 336 | } | 337 | } |
| 337 | 338 | ||
| 339 | + fn reposition(&mut self, win_pos: Point<i32, Logical>) { | ||
| 340 | + let offset = Point::from((self.width, self.width)); | ||
| 341 | + self.location = win_pos - offset; | ||
| 342 | + } | ||
| 343 | + | ||
| 338 | fn set_active(&mut self, is_active: bool) { | 344 | fn set_active(&mut self, is_active: bool) { |
| 339 | self.buffer.set_color(if is_active { | 345 | self.buffer.set_color(if is_active { |
| 340 | self.active_color.into() | 346 | self.active_color.into() |
| @@ -343,19 +349,14 @@ impl FocusRing { | |||
| 343 | }); | 349 | }); |
| 344 | } | 350 | } |
| 345 | 351 | ||
| 346 | - fn render( | 352 | + fn render(&self, scale: Scale<f64>) -> Option<SolidColorRenderElement> { |
| 347 | - &self, | ||
| 348 | - loc: Point<i32, Logical>, | ||
| 349 | - scale: Scale<f64>, | ||
| 350 | - ) -> Option<SolidColorRenderElement> { | ||
| 351 | if self.is_off { | 353 | if self.is_off { |
| 352 | return None; | 354 | return None; |
| 353 | } | 355 | } |
| 354 | 356 | ||
| 355 | - let offset = Point::from((self.width, self.width)); | ||
| 356 | Some(SolidColorRenderElement::from_buffer( | 357 | Some(SolidColorRenderElement::from_buffer( |
| 357 | &self.buffer, | 358 | &self.buffer, |
| 358 | - (loc - offset).to_physical_precise_round(scale), | 359 | + self.location.to_physical_precise_round(scale), |
| 359 | scale, | 360 | scale, |
| 360 | 1., | 361 | 1., |
| 361 | Kind::Unspecified, | 362 | Kind::Unspecified, |
| @@ -367,6 +368,7 @@ impl FocusRing { | |||
| 367 | fn new(config: config::FocusRing) -> Self { | 368 | fn new(config: config::FocusRing) -> Self { |
| 368 | Self { | 369 | Self { |
| 369 | buffer: SolidColorBuffer::new((0, 0), [0., 0., 0., 0.]), | 370 | buffer: SolidColorBuffer::new((0, 0), [0., 0., 0., 0.]), |
| 371 | + location: Point::from((0, 0)), | ||
| 370 | is_off: config.off, | 372 | is_off: config.off, |
| 371 | width: config.width.into(), | 373 | width: config.width.into(), |
| 372 | active_color: config.active_color, | 374 | active_color: config.active_color, |
| @@ -1670,11 +1672,20 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1670 | None => (), | 1672 | None => (), |
| 1671 | } | 1673 | } |
| 1672 | 1674 | ||
| 1675 | + let view_pos = self.view_pos(); | ||
| 1676 | + | ||
| 1673 | // This shall one day become a proper animation. | 1677 | // This shall one day become a proper animation. |
| 1674 | if !self.columns.is_empty() { | 1678 | if !self.columns.is_empty() { |
| 1675 | let col = &self.columns[self.active_column_idx]; | 1679 | let col = &self.columns[self.active_column_idx]; |
| 1676 | let active_win = &col.windows[col.active_window_idx]; | 1680 | let active_win = &col.windows[col.active_window_idx]; |
| 1677 | let geom = active_win.geometry(); | 1681 | let geom = active_win.geometry(); |
| 1682 | + | ||
| 1683 | + let win_pos = Point::from(( | ||
| 1684 | + self.column_x(self.active_column_idx) - view_pos, | ||
| 1685 | + col.window_y(col.active_window_idx), | ||
| 1686 | + )); | ||
| 1687 | + | ||
| 1688 | + self.focus_ring.reposition(win_pos); | ||
| 1678 | self.focus_ring.resize(geom.size); | 1689 | self.focus_ring.resize(geom.size); |
| 1679 | self.focus_ring.set_active(is_active); | 1690 | self.focus_ring.set_active(is_active); |
| 1680 | } | 1691 | } |
| @@ -2276,11 +2287,7 @@ impl Workspace<Window> { | |||
| 2276 | )); | 2287 | )); |
| 2277 | 2288 | ||
| 2278 | // Draw the focus ring. | 2289 | // Draw the focus ring. |
| 2279 | - rv.extend( | 2290 | + rv.extend(self.focus_ring.render(output_scale).map(Into::into)); |
| 2280 | - self.focus_ring | ||
| 2281 | - .render(win_pos, output_scale) | ||
| 2282 | - .map(Into::into), | ||
| 2283 | - ); | ||
| 2284 | 2291 | ||
| 2285 | let mut x = -view_pos; | 2292 | let mut x = -view_pos; |
| 2286 | for col in &self.columns { | 2293 | for col in &self.columns { |