forge
Explore
Log in

Don't you dare go Hollow

layout: Use saturating_add() in several places

Browse files at this commit

097c415036ed63c0736a6434ab9be25fbac042e1Ivan MolodetskikhParent: 2d16c04
Apparently VSCode sends i32::MAX worth of max_size?
src/layout/tile.rsmodified+9 -6
@@ -130,7 +130,8 @@ impl<W: LayoutElement> Tile<W> {
130130 }
131131
132132 if let Some(width) = self.effective_border_width() {
133- size += (width * 2, width * 2).into();
133+ size.w = size.w.saturating_add(width * 2);
134+ size.h = size.h.saturating_add(width * 2);
134135 }
135136
136137 size
@@ -172,7 +173,7 @@ impl<W: LayoutElement> Tile<W> {
172173 if self.border.is_off() {
173174 size
174175 } else {
175- size + self.border.width() * 2
176+ size.saturating_add(self.border.width() * 2)
176177 }
177178 }
178179
@@ -180,7 +181,7 @@ impl<W: LayoutElement> Tile<W> {
180181 if self.border.is_off() {
181182 size
182183 } else {
183- size + self.border.width() * 2
184+ size.saturating_add(self.border.width() * 2)
184185 }
185186 }
186187
@@ -204,7 +205,9 @@ impl<W: LayoutElement> Tile<W> {
204205 if let Some(width) = self.effective_border_width() {
205206 size.w = max(1, size.w);
206207 size.h = max(1, size.h);
207- size += (width * 2, width * 2).into();
208+
209+ size.w = size.w.saturating_add(width * 2);
210+ size.h = size.h.saturating_add(width * 2);
208211 }
209212
210213 size
@@ -215,10 +218,10 @@ impl<W: LayoutElement> Tile<W> {
215218
216219 if let Some(width) = self.effective_border_width() {
217220 if size.w > 0 {
218- size.w += width * 2;
221+ size.w = size.w.saturating_add(width * 2);
219222 }
220223 if size.h > 0 {
221- size.h += width * 2;
224+ size.h = size.h.saturating_add(width * 2);
222225 }
223226 }
224227