Implement `BitOr` and `BitOrAssign` for `Rect` (#7319)
This commit is contained in:
parent
207e71c2ae
commit
9fd0ad36e0
|
|
@ -705,7 +705,7 @@ fn automatic_area_position(ctx: &Context, layer_id: LayerId) -> Pos2 {
|
|||
let current_column_bb = column_bbs.last_mut().unwrap();
|
||||
if rect.left() < current_column_bb.right() {
|
||||
// same column
|
||||
*current_column_bb = current_column_bb.union(rect);
|
||||
*current_column_bb |= rect;
|
||||
} else {
|
||||
// new column
|
||||
column_bbs.push(rect);
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ impl Sides {
|
|||
wrap_mode,
|
||||
);
|
||||
|
||||
ui.advance_cursor_after_rect(left_rect.union(right_rect));
|
||||
ui.advance_cursor_after_rect(left_rect | right_rect);
|
||||
(result_left, result_right)
|
||||
}
|
||||
SidesKind::ShrinkRight => {
|
||||
|
|
@ -205,7 +205,7 @@ impl Sides {
|
|||
wrap_mode,
|
||||
);
|
||||
|
||||
ui.advance_cursor_after_rect(left_rect.union(right_rect));
|
||||
ui.advance_cursor_after_rect(left_rect | right_rect);
|
||||
(result_left, result_right)
|
||||
}
|
||||
SidesKind::Extend => {
|
||||
|
|
@ -225,7 +225,7 @@ impl Sides {
|
|||
None,
|
||||
);
|
||||
|
||||
let mut final_rect = left_rect.union(right_rect);
|
||||
let mut final_rect = left_rect | right_rect;
|
||||
let min_width = left_rect.width() + spacing + right_rect.width();
|
||||
|
||||
if ui.is_sizing_pass() {
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ impl Tooltip<'_> {
|
|||
// The popup might not be shown on at_pointer if there is no pointer.
|
||||
if let Some(response) = &response {
|
||||
state.tooltip_count += 1;
|
||||
state.bounding_rect = state.bounding_rect.union(response.response.rect);
|
||||
state.bounding_rect |= response.response.rect;
|
||||
response
|
||||
.response
|
||||
.ctx
|
||||
|
|
|
|||
|
|
@ -2689,7 +2689,7 @@ impl Context {
|
|||
self.write(|ctx| {
|
||||
let mut used = ctx.viewport().this_pass.used_by_panels;
|
||||
for (_id, window) in ctx.memory.areas().visible_windows() {
|
||||
used = used.union(window.rect());
|
||||
used |= window.rect();
|
||||
}
|
||||
used.round_ui()
|
||||
})
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ impl State {
|
|||
let location_rect =
|
||||
Align2::RIGHT_TOP.anchor_size(pos - 4.0 * Vec2::X, location_galley.size());
|
||||
painter.galley(location_rect.min, location_galley, color);
|
||||
bounding_rect = bounding_rect.union(location_rect);
|
||||
bounding_rect |= location_rect;
|
||||
}
|
||||
|
||||
{
|
||||
|
|
@ -117,7 +117,7 @@ impl State {
|
|||
);
|
||||
let rect = Align2::LEFT_TOP.anchor_size(pos, galley.size());
|
||||
painter.galley(rect.min, galley, color);
|
||||
bounding_rect = bounding_rect.union(rect);
|
||||
bounding_rect |= rect;
|
||||
}
|
||||
|
||||
pos.y = bounding_rect.max.y + 4.0;
|
||||
|
|
|
|||
|
|
@ -50,8 +50,8 @@ pub(crate) struct Region {
|
|||
impl Region {
|
||||
/// Expand the `min_rect` and `max_rect` of this ui to include a child at the given rect.
|
||||
pub fn expand_to_include_rect(&mut self, rect: Rect) {
|
||||
self.min_rect = self.min_rect.union(rect);
|
||||
self.max_rect = self.max_rect.union(rect);
|
||||
self.min_rect |= rect;
|
||||
self.max_rect |= rect;
|
||||
}
|
||||
|
||||
/// Ensure we are big enough to contain the given X-coordinate.
|
||||
|
|
@ -725,7 +725,7 @@ impl Layout {
|
|||
if self.main_wrap {
|
||||
if cursor.intersects(frame_rect.shrink(1.0)) {
|
||||
// make row/column larger if necessary
|
||||
*cursor = cursor.union(frame_rect);
|
||||
*cursor |= frame_rect;
|
||||
} else {
|
||||
// this is a new row or column. We temporarily use NAN for what will be filled in later.
|
||||
match self.main_dir {
|
||||
|
|
|
|||
|
|
@ -318,7 +318,7 @@ impl PassState {
|
|||
);
|
||||
self.available_rect.min.x = panel_rect.max.x;
|
||||
self.unused_rect.min.x = panel_rect.max.x;
|
||||
self.used_by_panels = self.used_by_panels.union(panel_rect);
|
||||
self.used_by_panels |= panel_rect;
|
||||
}
|
||||
|
||||
/// Shrink `available_rect`.
|
||||
|
|
@ -329,7 +329,7 @@ impl PassState {
|
|||
);
|
||||
self.available_rect.max.x = panel_rect.min.x;
|
||||
self.unused_rect.max.x = panel_rect.min.x;
|
||||
self.used_by_panels = self.used_by_panels.union(panel_rect);
|
||||
self.used_by_panels |= panel_rect;
|
||||
}
|
||||
|
||||
/// Shrink `available_rect`.
|
||||
|
|
@ -340,7 +340,7 @@ impl PassState {
|
|||
);
|
||||
self.available_rect.min.y = panel_rect.max.y;
|
||||
self.unused_rect.min.y = panel_rect.max.y;
|
||||
self.used_by_panels = self.used_by_panels.union(panel_rect);
|
||||
self.used_by_panels |= panel_rect;
|
||||
}
|
||||
|
||||
/// Shrink `available_rect`.
|
||||
|
|
@ -351,13 +351,13 @@ impl PassState {
|
|||
);
|
||||
self.available_rect.max.y = panel_rect.min.y;
|
||||
self.unused_rect.max.y = panel_rect.min.y;
|
||||
self.used_by_panels = self.used_by_panels.union(panel_rect);
|
||||
self.used_by_panels |= panel_rect;
|
||||
}
|
||||
|
||||
pub(crate) fn allocate_central_panel(&mut self, panel_rect: Rect) {
|
||||
// Note: we do not shrink `available_rect`, because
|
||||
// we allow windows to cover the CentralPanel.
|
||||
self.unused_rect = Rect::NOTHING; // Nothing left unused after this
|
||||
self.used_by_panels = self.used_by_panels.union(panel_rect);
|
||||
self.used_by_panels |= panel_rect;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -231,7 +231,7 @@ impl Placer {
|
|||
let region = &mut self.region;
|
||||
region.max_rect.min.x = rect.min.x;
|
||||
region.max_rect.max.x = rect.max.x;
|
||||
region.max_rect = region.max_rect.union(region.min_rect); // make sure we didn't shrink too much
|
||||
region.max_rect |= region.min_rect; // make sure we didn't shrink too much
|
||||
|
||||
region.cursor.min.x = region.max_rect.min.x;
|
||||
region.cursor.max.x = region.max_rect.max.x;
|
||||
|
|
@ -246,7 +246,7 @@ impl Placer {
|
|||
let region = &mut self.region;
|
||||
region.max_rect.min.y = rect.min.y;
|
||||
region.max_rect.max.y = rect.max.y;
|
||||
region.max_rect = region.max_rect.union(region.min_rect); // make sure we didn't shrink too much
|
||||
region.max_rect |= region.min_rect; // make sure we didn't shrink too much
|
||||
|
||||
region.cursor.min.y = region.max_rect.min.y;
|
||||
region.cursor.max.y = region.max_rect.max.y;
|
||||
|
|
|
|||
|
|
@ -546,7 +546,7 @@ impl LabelSelectionState {
|
|||
|
||||
if let Some(mut cursor_range) = cursor_state.range(galley) {
|
||||
let galley_rect = global_from_galley * Rect::from_min_size(Pos2::ZERO, galley.size());
|
||||
self.selection_bbox_this_frame = self.selection_bbox_this_frame.union(galley_rect);
|
||||
self.selection_bbox_this_frame |= galley_rect;
|
||||
|
||||
if let Some(selection) = &self.selection {
|
||||
if selection.primary.widget_id == response.id {
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ impl Label {
|
|||
};
|
||||
select_sense -= Sense::FOCUSABLE; // Don't move focus to labels with TAB key.
|
||||
|
||||
sense = sense.union(select_sense);
|
||||
sense |= select_sense;
|
||||
}
|
||||
|
||||
if let WidgetText::Galley(galley) = self.text {
|
||||
|
|
|
|||
|
|
@ -222,7 +222,7 @@ fn huge_content_painter(ui: &mut egui::Ui) {
|
|||
font_id.clone(),
|
||||
ui.visuals().text_color(),
|
||||
);
|
||||
used_rect = used_rect.union(text_rect);
|
||||
used_rect |= text_rect;
|
||||
}
|
||||
|
||||
ui.allocate_rect(used_rect, Sense::hover()); // make sure it is visible!
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@ impl<'l> StripLayout<'l> {
|
|||
} else if flags.clip {
|
||||
max_rect
|
||||
} else {
|
||||
max_rect.union(used_rect)
|
||||
max_rect | used_rect
|
||||
};
|
||||
|
||||
self.set_pos(allocation_rect);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use std::fmt;
|
||||
|
||||
use crate::{Div, Mul, NumExt as _, Pos2, Rangef, Rot2, Vec2, lerp, pos2, vec2};
|
||||
use std::ops::{BitOr, BitOrAssign};
|
||||
|
||||
/// A rectangular region of space.
|
||||
///
|
||||
|
|
@ -776,6 +777,22 @@ impl Div<f32> for Rect {
|
|||
}
|
||||
}
|
||||
|
||||
impl BitOr for Rect {
|
||||
type Output = Self;
|
||||
|
||||
#[inline]
|
||||
fn bitor(self, other: Self) -> Self {
|
||||
self.union(other)
|
||||
}
|
||||
}
|
||||
|
||||
impl BitOrAssign for Rect {
|
||||
#[inline]
|
||||
fn bitor_assign(&mut self, other: Self) {
|
||||
*self = self.union(other);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
|||
|
|
@ -363,7 +363,7 @@ impl Shape {
|
|||
Self::Vec(shapes) => {
|
||||
let mut rect = Rect::NOTHING;
|
||||
for shape in shapes {
|
||||
rect = rect.union(shape.visual_bounding_rect());
|
||||
rect |= shape.visual_bounding_rect();
|
||||
}
|
||||
rect
|
||||
}
|
||||
|
|
|
|||
|
|
@ -691,13 +691,12 @@ fn galley_from_rows(
|
|||
let mut num_indices = 0;
|
||||
|
||||
for placed_row in &mut rows {
|
||||
rect = rect.union(placed_row.rect());
|
||||
rect |= placed_row.rect();
|
||||
|
||||
let row = Arc::make_mut(&mut placed_row.row);
|
||||
row.visuals = tessellate_row(point_scale, &job, &format_summary, row);
|
||||
|
||||
mesh_bounds =
|
||||
mesh_bounds.union(row.visuals.mesh_bounds.translate(placed_row.pos.to_vec2()));
|
||||
mesh_bounds |= row.visuals.mesh_bounds.translate(placed_row.pos.to_vec2());
|
||||
num_vertices += row.visuals.mesh.vertices.len();
|
||||
num_indices += row.visuals.mesh.indices.len();
|
||||
|
||||
|
|
|
|||
|
|
@ -865,12 +865,9 @@ impl Galley {
|
|||
.extend(galley.rows.iter().enumerate().map(|(row_idx, placed_row)| {
|
||||
let new_pos = placed_row.pos + current_y_offset * Vec2::Y;
|
||||
let new_pos = new_pos.round_to_pixels(pixels_per_point);
|
||||
merged_galley.mesh_bounds = merged_galley
|
||||
.mesh_bounds
|
||||
.union(placed_row.visuals.mesh_bounds.translate(new_pos.to_vec2()));
|
||||
merged_galley.rect = merged_galley
|
||||
.rect
|
||||
.union(Rect::from_min_size(new_pos, placed_row.size));
|
||||
merged_galley.mesh_bounds |=
|
||||
placed_row.visuals.mesh_bounds.translate(new_pos.to_vec2());
|
||||
merged_galley.rect |= Rect::from_min_size(new_pos, placed_row.size);
|
||||
|
||||
let mut row = placed_row.row.clone();
|
||||
let is_last_row_in_galley = row_idx + 1 == galley.rows.len();
|
||||
|
|
|
|||
Loading…
Reference in New Issue