forge
Explore
Log in

Don't you dare go Hollow

tab indicator: Extract tab_rects()

Browse files at this commit

a21196ec54a0e2bb59e0f52308c38eabe841b923Ivan MolodetskikhParent: 0b83d99
src/layout/tab_indicator.rsmodified+56 -38
@@ -51,50 +51,26 @@ impl TabIndicator {
51 }51 }
52 }52 }
53 53
54- #[allow(clippy::too_many_arguments)]54+ fn tab_rects(
55- pub fn update_render_elements(55+ &self,
56- &mut self,
57- enabled: bool,
58- // Geometry of the tabs area.
59 area: Rectangle<f64, Logical>,56 area: Rectangle<f64, Logical>,
60- // View rect relative to the tabs area.57+ count: usize,
61- area_view_rect: Rectangle<f64, Logical>,
62- // Tab count, should match the tabs iterator length.
63- tab_count: usize,
64- tabs: impl Iterator<Item = TabInfo>,
65- // TODO: do we indicate inactive-but-selected somehow?
66- _is_active: bool,
67 scale: f64,58 scale: f64,
68- ) {59+ ) -> impl Iterator<Item = Rectangle<f64, Logical>> {
69- if !enabled || self.config.off {
70- self.shader_locs.clear();
71- self.shaders.clear();
72- return;
73- }
74-
75- let count = tab_count;
76- if self.config.hide_when_single_tab && count == 1 {
77- self.shader_locs.clear();
78- self.shaders.clear();
79- return;
80- }
81-
82 let round = |logical: f64| round_logical_in_physical(scale, logical);60 let round = |logical: f64| round_logical_in_physical(scale, logical);
83 61
84 let width = round(self.config.width.0);62 let width = round(self.config.width.0);
85 let gap = round(self.config.gap.0);63 let gap = round(self.config.gap.0);
86 let gaps_between = round(self.config.gaps_between_tabs.0);64 let gaps_between = round(self.config.gaps_between_tabs.0);
87 65
88- let side = match self.config.position {66+ let position = self.config.position;
67+ let side = match position {
89 TabIndicatorPosition::Left | TabIndicatorPosition::Right => area.size.h,68 TabIndicatorPosition::Left | TabIndicatorPosition::Right => area.size.h,
90 TabIndicatorPosition::Top | TabIndicatorPosition::Bottom => area.size.w,69 TabIndicatorPosition::Top | TabIndicatorPosition::Bottom => area.size.w,
91 };70 };
92 let total_prop = self.config.length.total_proportion.unwrap_or(0.5);71 let total_prop = self.config.length.total_proportion.unwrap_or(0.5);
93 let min_length = round(side * total_prop.clamp(0., 2.));72 let min_length = round(side * total_prop.clamp(0., 2.));
94 73
95- self.shaders.resize_with(count, Default::default);
96- self.shader_locs.resize_with(count, Default::default);
97-
98 let pixel = 1. / scale;74 let pixel = 1. / scale;
99 let shortest_length = count as f64 * (pixel + gaps_between) - gaps_between;75 let shortest_length = count as f64 * (pixel + gaps_between) - gaps_between;
100 let length = f64::max(min_length, shortest_length);76 let length = f64::max(min_length, shortest_length);
@@ -104,7 +80,7 @@ impl TabIndicator {
104 let mut ones_left = ((length - floored_length) / pixel).max(0.).round() as usize;80 let mut ones_left = ((length - floored_length) / pixel).max(0.).round() as usize;
105 81
106 let mut shader_loc = Point::from((-gap - width, round((side - length) / 2.)));82 let mut shader_loc = Point::from((-gap - width, round((side - length) / 2.)));
107- match self.config.position {83+ match position {
108 TabIndicatorPosition::Left => (),84 TabIndicatorPosition::Left => (),
109 TabIndicatorPosition::Right => shader_loc.x = area.size.w + gap,85 TabIndicatorPosition::Right => shader_loc.x = area.size.w + gap,
110 TabIndicatorPosition::Top => mem::swap(&mut shader_loc.x, &mut shader_loc.y),86 TabIndicatorPosition::Top => mem::swap(&mut shader_loc.x, &mut shader_loc.y),
@@ -115,16 +91,16 @@ impl TabIndicator {
115 }91 }
116 shader_loc += area.loc;92 shader_loc += area.loc;
117 93
118- for ((shader, loc), tab) in zip(&mut self.shaders, &mut self.shader_locs).zip(tabs) {94+ (0..count).map(move |_| {
119- *loc = shader_loc;
120-
121 let mut px_per_tab = px_per_tab;95 let mut px_per_tab = px_per_tab;
122 if ones_left > 0 {96 if ones_left > 0 {
123 ones_left -= 1;97 ones_left -= 1;
124 px_per_tab += pixel;98 px_per_tab += pixel;
125 }99 }
126 100
127- match self.config.position {101+ let loc = shader_loc;
102+
103+ match position {
128 TabIndicatorPosition::Left | TabIndicatorPosition::Right => {104 TabIndicatorPosition::Left | TabIndicatorPosition::Right => {
129 shader_loc.y += px_per_tab + gaps_between105 shader_loc.y += px_per_tab + gaps_between
130 }106 }
@@ -133,7 +109,7 @@ impl TabIndicator {
133 }109 }
134 }110 }
135 111
136- let shader_size = match self.config.position {112+ let size = match position {
137 TabIndicatorPosition::Left | TabIndicatorPosition::Right => {113 TabIndicatorPosition::Left | TabIndicatorPosition::Right => {
138 Size::from((width, px_per_tab))114 Size::from((width, px_per_tab))
139 }115 }
@@ -142,6 +118,48 @@ impl TabIndicator {
142 }118 }
143 };119 };
144 120
121+ Rectangle::new(loc, size)
122+ })
123+ }
124+
125+ #[allow(clippy::too_many_arguments)]
126+ pub fn update_render_elements(
127+ &mut self,
128+ enabled: bool,
129+ // Geometry of the tabs area.
130+ area: Rectangle<f64, Logical>,
131+ // View rect relative to the tabs area.
132+ area_view_rect: Rectangle<f64, Logical>,
133+ // Tab count, should match the tabs iterator length.
134+ tab_count: usize,
135+ tabs: impl Iterator<Item = TabInfo>,
136+ // TODO: do we indicate inactive-but-selected somehow?
137+ _is_active: bool,
138+ scale: f64,
139+ ) {
140+ if !enabled || self.config.off {
141+ self.shader_locs.clear();
142+ self.shaders.clear();
143+ return;
144+ }
145+
146+ let count = tab_count;
147+ if self.config.hide_when_single_tab && count == 1 {
148+ self.shader_locs.clear();
149+ self.shaders.clear();
150+ return;
151+ }
152+
153+ self.shaders.resize_with(count, Default::default);
154+ self.shader_locs.resize_with(count, Default::default);
155+
156+ let rects = self.tab_rects(area, count, scale);
157+ for ((shader, loc), (tab, rect)) in zip(
158+ zip(&mut self.shaders, &mut self.shader_locs),
159+ zip(tabs, rects),
160+ ) {
161+ *loc = rect.loc;
162+
145 let mut gradient_area = match tab.gradient.relative_to {163 let mut gradient_area = match tab.gradient.relative_to {
146 GradientRelativeTo::Window => tab.geometry,164 GradientRelativeTo::Window => tab.geometry,
147 GradientRelativeTo::WorkspaceView => area_view_rect,165 GradientRelativeTo::WorkspaceView => area_view_rect,
@@ -149,13 +167,13 @@ impl TabIndicator {
149 gradient_area.loc -= *loc;167 gradient_area.loc -= *loc;
150 168
151 shader.update(169 shader.update(
152- shader_size,170+ rect.size,
153 gradient_area,171 gradient_area,
154 tab.gradient.in_,172 tab.gradient.in_,
155 tab.gradient.from,173 tab.gradient.from,
156 tab.gradient.to,174 tab.gradient.to,
157 ((tab.gradient.angle as f32) - 90.).to_radians(),175 ((tab.gradient.angle as f32) - 90.).to_radians(),
158- Rectangle::from_size(shader_size),176+ Rectangle::from_size(rect.size),
159 0.,177 0.,
160 CornerRadius::default(),178 CornerRadius::default(),
161 scale as f32,179 scale as f32,