aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2025-02-10 13:10:05 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2025-02-10 07:29:33 -0800
commita21196ec54a0e2bb59e0f52308c38eabe841b923 (patch)
treeed34806f854bbfef7073b650e6fb891a0ecf9f20 /src
parent0b83d9932b5b8b93837d9c0683b19e5de5587a43 (diff)
downloadniri-a21196ec54a0e2bb59e0f52308c38eabe841b923.tar.gz
niri-a21196ec54a0e2bb59e0f52308c38eabe841b923.tar.bz2
niri-a21196ec54a0e2bb59e0f52308c38eabe841b923.zip
tab indicator: Extract tab_rects()
Diffstat (limited to 'src')
-rw-r--r--src/layout/tab_indicator.rs94
1 files changed, 56 insertions, 38 deletions
diff --git a/src/layout/tab_indicator.rs b/src/layout/tab_indicator.rs
index 952e2ef6..451f2224 100644
--- a/src/layout/tab_indicator.rs
+++ b/src/layout/tab_indicator.rs
@@ -51,50 +51,26 @@ impl TabIndicator {
}
}
- #[allow(clippy::too_many_arguments)]
- pub fn update_render_elements(
- &mut self,
- enabled: bool,
- // Geometry of the tabs area.
+ fn tab_rects(
+ &self,
area: Rectangle<f64, Logical>,
- // View rect relative to the tabs area.
- area_view_rect: Rectangle<f64, Logical>,
- // Tab count, should match the tabs iterator length.
- tab_count: usize,
- tabs: impl Iterator<Item = TabInfo>,
- // TODO: do we indicate inactive-but-selected somehow?
- _is_active: bool,
+ count: usize,
scale: f64,
- ) {
- if !enabled || self.config.off {
- self.shader_locs.clear();
- self.shaders.clear();
- return;
- }
-
- let count = tab_count;
- if self.config.hide_when_single_tab && count == 1 {
- self.shader_locs.clear();
- self.shaders.clear();
- return;
- }
-
+ ) -> impl Iterator<Item = Rectangle<f64, Logical>> {
let round = |logical: f64| round_logical_in_physical(scale, logical);
let width = round(self.config.width.0);
let gap = round(self.config.gap.0);
let gaps_between = round(self.config.gaps_between_tabs.0);
- let side = match self.config.position {
+ let position = self.config.position;
+ let side = match position {
TabIndicatorPosition::Left | TabIndicatorPosition::Right => area.size.h,
TabIndicatorPosition::Top | TabIndicatorPosition::Bottom => area.size.w,
};
let total_prop = self.config.length.total_proportion.unwrap_or(0.5);
let min_length = round(side * total_prop.clamp(0., 2.));
- self.shaders.resize_with(count, Default::default);
- self.shader_locs.resize_with(count, Default::default);
-
let pixel = 1. / scale;
let shortest_length = count as f64 * (pixel + gaps_between) - gaps_between;
let length = f64::max(min_length, shortest_length);
@@ -104,7 +80,7 @@ impl TabIndicator {
let mut ones_left = ((length - floored_length) / pixel).max(0.).round() as usize;
let mut shader_loc = Point::from((-gap - width, round((side - length) / 2.)));
- match self.config.position {
+ match position {
TabIndicatorPosition::Left => (),
TabIndicatorPosition::Right => shader_loc.x = area.size.w + gap,
TabIndicatorPosition::Top => mem::swap(&mut shader_loc.x, &mut shader_loc.y),
@@ -115,16 +91,16 @@ impl TabIndicator {
}
shader_loc += area.loc;
- for ((shader, loc), tab) in zip(&mut self.shaders, &mut self.shader_locs).zip(tabs) {
- *loc = shader_loc;
-
+ (0..count).map(move |_| {
let mut px_per_tab = px_per_tab;
if ones_left > 0 {
ones_left -= 1;
px_per_tab += pixel;
}
- match self.config.position {
+ let loc = shader_loc;
+
+ match position {
TabIndicatorPosition::Left | TabIndicatorPosition::Right => {
shader_loc.y += px_per_tab + gaps_between
}
@@ -133,7 +109,7 @@ impl TabIndicator {
}
}
- let shader_size = match self.config.position {
+ let size = match position {
TabIndicatorPosition::Left | TabIndicatorPosition::Right => {
Size::from((width, px_per_tab))
}
@@ -142,6 +118,48 @@ impl TabIndicator {
}
};
+ Rectangle::new(loc, size)
+ })
+ }
+
+ #[allow(clippy::too_many_arguments)]
+ pub fn update_render_elements(
+ &mut self,
+ enabled: bool,
+ // Geometry of the tabs area.
+ area: Rectangle<f64, Logical>,
+ // View rect relative to the tabs area.
+ area_view_rect: Rectangle<f64, Logical>,
+ // Tab count, should match the tabs iterator length.
+ tab_count: usize,
+ tabs: impl Iterator<Item = TabInfo>,
+ // TODO: do we indicate inactive-but-selected somehow?
+ _is_active: bool,
+ scale: f64,
+ ) {
+ if !enabled || self.config.off {
+ self.shader_locs.clear();
+ self.shaders.clear();
+ return;
+ }
+
+ let count = tab_count;
+ if self.config.hide_when_single_tab && count == 1 {
+ self.shader_locs.clear();
+ self.shaders.clear();
+ return;
+ }
+
+ self.shaders.resize_with(count, Default::default);
+ self.shader_locs.resize_with(count, Default::default);
+
+ let rects = self.tab_rects(area, count, scale);
+ for ((shader, loc), (tab, rect)) in zip(
+ zip(&mut self.shaders, &mut self.shader_locs),
+ zip(tabs, rects),
+ ) {
+ *loc = rect.loc;
+
let mut gradient_area = match tab.gradient.relative_to {
GradientRelativeTo::Window => tab.geometry,
GradientRelativeTo::WorkspaceView => area_view_rect,
@@ -149,13 +167,13 @@ impl TabIndicator {
gradient_area.loc -= *loc;
shader.update(
- shader_size,
+ rect.size,
gradient_area,
tab.gradient.in_,
tab.gradient.from,
tab.gradient.to,
((tab.gradient.angle as f32) - 90.).to_radians(),
- Rectangle::from_size(shader_size),
+ Rectangle::from_size(rect.size),
0.,
CornerRadius::default(),
scale as f32,