Refactor: make Rect members min/max public
This commit is contained in:
parent
e26d08851f
commit
cce048509f
10 changed files with 31 additions and 37 deletions
|
@ -201,7 +201,7 @@ impl Context {
|
||||||
rect: rect.expand(2.0),
|
rect: rect.expand(2.0),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
self.add_text(layer, rect.min(), text_style, text, Some(color::RED));
|
self.add_text(layer, rect.min, text_style, text, Some(color::RED));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn debug_text(&self, pos: Pos2, text: &str) {
|
pub fn debug_text(&self, pos: Pos2, text: &str) {
|
||||||
|
@ -231,7 +231,7 @@ impl Context {
|
||||||
let font = &self.fonts[text_style];
|
let font = &self.fonts[text_style];
|
||||||
let (text, size) = font.layout_multiline(text, f32::INFINITY);
|
let (text, size) = font.layout_multiline(text, f32::INFINITY);
|
||||||
let rect = align_rect(&Rect::from_min_size(pos, size), align);
|
let rect = align_rect(&Rect::from_min_size(pos, size), align);
|
||||||
self.add_text(layer, rect.min(), text_style, text, text_color);
|
self.add_text(layer, rect.min, text_style, text, text_color);
|
||||||
size
|
size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -121,7 +121,7 @@ impl ExampleApp {
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.rect
|
.rect
|
||||||
.min();
|
.min;
|
||||||
|
|
||||||
let mut cmds = vec![];
|
let mut cmds = vec![];
|
||||||
for i in 0..self.num_boxes {
|
for i in 0..self.num_boxes {
|
||||||
|
|
|
@ -318,8 +318,8 @@ impl std::fmt::Debug for Pos2 {
|
||||||
|
|
||||||
#[derive(Clone, Copy, Default, Eq, PartialEq, Deserialize, Serialize)]
|
#[derive(Clone, Copy, Default, Eq, PartialEq, Deserialize, Serialize)]
|
||||||
pub struct Rect {
|
pub struct Rect {
|
||||||
min: Pos2,
|
pub min: Pos2,
|
||||||
max: Pos2,
|
pub max: Pos2,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Rect {
|
impl Rect {
|
||||||
|
@ -366,7 +366,7 @@ impl Rect {
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn translate(self, amnt: Vec2) -> Self {
|
pub fn translate(self, amnt: Vec2) -> Self {
|
||||||
Rect::from_min_size(self.min() + amnt, self.size())
|
Rect::from_min_size(self.min + amnt, self.size())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
@ -405,12 +405,6 @@ impl Rect {
|
||||||
y: self.min.y + self.size().y / 2.0,
|
y: self.min.y + self.size().y / 2.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn min(&self) -> Pos2 {
|
|
||||||
self.min
|
|
||||||
}
|
|
||||||
pub fn max(&self) -> Pos2 {
|
|
||||||
self.max
|
|
||||||
}
|
|
||||||
pub fn size(&self) -> Vec2 {
|
pub fn size(&self) -> Vec2 {
|
||||||
self.max - self.min
|
self.max - self.min
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,8 +179,8 @@ impl Path {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_rectangle(&mut self, rect: &Rect) {
|
pub fn add_rectangle(&mut self, rect: &Rect) {
|
||||||
let min = rect.min();
|
let min = rect.min;
|
||||||
let max = rect.max();
|
let max = rect.max;
|
||||||
self.add_point(pos2(min.x, min.y), vec2(-1.0, -1.0));
|
self.add_point(pos2(min.x, min.y), vec2(-1.0, -1.0));
|
||||||
self.add_point(pos2(max.x, min.y), vec2(1.0, -1.0));
|
self.add_point(pos2(max.x, min.y), vec2(1.0, -1.0));
|
||||||
self.add_point(pos2(max.x, max.y), vec2(1.0, 1.0));
|
self.add_point(pos2(max.x, max.y), vec2(1.0, 1.0));
|
||||||
|
@ -188,8 +188,8 @@ impl Path {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_rounded_rectangle(&mut self, rect: &Rect, corner_radius: f32) {
|
pub fn add_rounded_rectangle(&mut self, rect: &Rect, corner_radius: f32) {
|
||||||
let min = rect.min();
|
let min = rect.min;
|
||||||
let max = rect.max();
|
let max = rect.max;
|
||||||
|
|
||||||
let cr = corner_radius
|
let cr = corner_radius
|
||||||
.min(rect.width() * 0.5)
|
.min(rect.width() * 0.5)
|
||||||
|
|
|
@ -49,7 +49,7 @@ pub struct Region {
|
||||||
|
|
||||||
/// Where the next widget will be put.
|
/// Where the next widget will be put.
|
||||||
/// Progresses along self.dir.
|
/// Progresses along self.dir.
|
||||||
/// Initially set to rect.min()
|
/// Initially set to rect.min
|
||||||
pub(crate) cursor: Pos2,
|
pub(crate) cursor: Pos2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ impl Region {
|
||||||
desired_rect: rect,
|
desired_rect: rect,
|
||||||
bounding_size: Vec2::default(),
|
bounding_size: Vec2::default(),
|
||||||
style,
|
style,
|
||||||
cursor: rect.min(),
|
cursor: rect.min,
|
||||||
dir: Direction::Vertical,
|
dir: Direction::Vertical,
|
||||||
align: Align::Min,
|
align: Align::Min,
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ impl Region {
|
||||||
id: self.id,
|
id: self.id,
|
||||||
clip_rect,
|
clip_rect,
|
||||||
desired_rect: child_rect,
|
desired_rect: child_rect,
|
||||||
cursor: child_rect.min(),
|
cursor: child_rect.min,
|
||||||
bounding_size: vec2(0.0, 0.0),
|
bounding_size: vec2(0.0, 0.0),
|
||||||
dir: self.dir,
|
dir: self.dir,
|
||||||
align: self.align,
|
align: self.align,
|
||||||
|
@ -167,7 +167,7 @@ impl Region {
|
||||||
/// This how much more space we can take up without overflowing our parent.
|
/// This how much more space we can take up without overflowing our parent.
|
||||||
/// Shrinks as cursor increments.
|
/// Shrinks as cursor increments.
|
||||||
pub fn available_space(&self) -> Vec2 {
|
pub fn available_space(&self) -> Vec2 {
|
||||||
self.desired_rect.max() - self.cursor
|
self.desired_rect.max - self.cursor
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn direction(&self) -> Direction {
|
pub fn direction(&self) -> Direction {
|
||||||
|
@ -209,7 +209,7 @@ impl Region {
|
||||||
"You can only indent vertical layouts"
|
"You can only indent vertical layouts"
|
||||||
);
|
);
|
||||||
let indent = vec2(self.style.indent, 0.0);
|
let indent = vec2(self.style.indent, 0.0);
|
||||||
let child_rect = Rect::from_min_max(self.cursor + indent, self.desired_rect.max());
|
let child_rect = Rect::from_min_max(self.cursor + indent, self.desired_rect.max);
|
||||||
let mut child_region = Region {
|
let mut child_region = Region {
|
||||||
id: self.id.with(id_source),
|
id: self.id.with(id_source),
|
||||||
align: Align::Min,
|
align: Align::Min,
|
||||||
|
@ -219,7 +219,7 @@ impl Region {
|
||||||
let size = child_region.bounding_size;
|
let size = child_region.bounding_size;
|
||||||
|
|
||||||
// draw a grey line on the left to mark the region
|
// draw a grey line on the left to mark the region
|
||||||
let line_start = child_rect.min() - indent * 0.5;
|
let line_start = child_rect.min - indent * 0.5;
|
||||||
let line_start = line_start.round(); // TODO: round to pixel instead
|
let line_start = line_start.round(); // TODO: round to pixel instead
|
||||||
let line_end = pos2(line_start.x, line_start.y + size.y - 8.0);
|
let line_end = pos2(line_start.x, line_start.y + size.y - 8.0);
|
||||||
self.add_paint_cmd(PaintCmd::Line {
|
self.add_paint_cmd(PaintCmd::Line {
|
||||||
|
@ -262,7 +262,7 @@ impl Region {
|
||||||
align: Align,
|
align: Align,
|
||||||
add_contents: impl FnOnce(&mut Region),
|
add_contents: impl FnOnce(&mut Region),
|
||||||
) {
|
) {
|
||||||
let child_rect = Rect::from_min_max(self.cursor, self.desired_rect.max());
|
let child_rect = Rect::from_min_max(self.cursor, self.desired_rect.max);
|
||||||
let mut child_region = Region {
|
let mut child_region = Region {
|
||||||
dir,
|
dir,
|
||||||
align,
|
align,
|
||||||
|
@ -443,7 +443,7 @@ impl Region {
|
||||||
let font = &self.fonts()[text_style];
|
let font = &self.fonts()[text_style];
|
||||||
let (text, size) = font.layout_multiline(text, f32::INFINITY);
|
let (text, size) = font.layout_multiline(text, f32::INFINITY);
|
||||||
let rect = align_rect(&Rect::from_min_size(pos, size), align);
|
let rect = align_rect(&Rect::from_min_size(pos, size), align);
|
||||||
self.add_text(rect.min(), text_style, text, text_color);
|
self.add_text(rect.min, text_style, text, text_color);
|
||||||
size
|
size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -109,12 +109,12 @@ impl Texture {
|
||||||
let interact = region.reserve_space(size, None);
|
let interact = region.reserve_space(size, None);
|
||||||
let rect = interact.rect;
|
let rect = interact.rect;
|
||||||
let top_left = Vertex {
|
let top_left = Vertex {
|
||||||
pos: rect.min(),
|
pos: rect.min,
|
||||||
uv: (0, 0),
|
uv: (0, 0),
|
||||||
color: WHITE,
|
color: WHITE,
|
||||||
};
|
};
|
||||||
let bottom_right = Vertex {
|
let bottom_right = Vertex {
|
||||||
pos: rect.max(),
|
pos: rect.max,
|
||||||
uv: (self.width as u16 - 1, self.height as u16 - 1),
|
uv: (self.width as u16 - 1, self.height as u16 - 1),
|
||||||
color: WHITE,
|
color: WHITE,
|
||||||
};
|
};
|
||||||
|
@ -137,12 +137,12 @@ impl Texture {
|
||||||
let v = clamp(v, texel_radius..=self.height as f32 - 1.0 - texel_radius);
|
let v = clamp(v, texel_radius..=self.height as f32 - 1.0 - texel_radius);
|
||||||
|
|
||||||
let top_left = Vertex {
|
let top_left = Vertex {
|
||||||
pos: zoom_rect.min(),
|
pos: zoom_rect.min,
|
||||||
uv: ((u - texel_radius) as u16, (v - texel_radius) as u16),
|
uv: ((u - texel_radius) as u16, (v - texel_radius) as u16),
|
||||||
color: WHITE,
|
color: WHITE,
|
||||||
};
|
};
|
||||||
let bottom_right = Vertex {
|
let bottom_right = Vertex {
|
||||||
pos: zoom_rect.max(),
|
pos: zoom_rect.max,
|
||||||
uv: ((u + texel_radius) as u16, (v + texel_radius) as u16),
|
uv: ((u + texel_radius) as u16, (v + texel_radius) as u16),
|
||||||
color: WHITE,
|
color: WHITE,
|
||||||
};
|
};
|
||||||
|
|
|
@ -54,7 +54,7 @@ impl Widget for Label {
|
||||||
let font = ®ion.fonts()[self.text_style];
|
let font = ®ion.fonts()[self.text_style];
|
||||||
let (text, text_size) = font.layout_multiline(&self.text, region.available_width());
|
let (text, text_size) = font.layout_multiline(&self.text, region.available_width());
|
||||||
let interact = region.reserve_space(text_size, None);
|
let interact = region.reserve_space(text_size, None);
|
||||||
region.add_text(interact.rect.min(), self.text_style, text, self.text_color);
|
region.add_text(interact.rect.min, self.text_style, text, self.text_color);
|
||||||
region.response(interact)
|
region.response(interact)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ impl Widget for Hyperlink {
|
||||||
if interact.hovered {
|
if interact.hovered {
|
||||||
// Underline:
|
// Underline:
|
||||||
for fragment in &text {
|
for fragment in &text {
|
||||||
let pos = interact.rect.min();
|
let pos = interact.rect.min;
|
||||||
let y = pos.y + fragment.y_offset + line_spacing;
|
let y = pos.y + fragment.y_offset + line_spacing;
|
||||||
let y = region.round_to_pixel(y);
|
let y = region.round_to_pixel(y);
|
||||||
let min_x = pos.x + fragment.min_x();
|
let min_x = pos.x + fragment.min_x();
|
||||||
|
@ -109,7 +109,7 @@ impl Widget for Hyperlink {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
region.add_text(interact.rect.min(), text_style, text, Some(color));
|
region.add_text(interact.rect.min, text_style, text, Some(color));
|
||||||
|
|
||||||
region.response(interact)
|
region.response(interact)
|
||||||
}
|
}
|
||||||
|
@ -198,7 +198,7 @@ impl<'a> Widget for Checkbox<'a> {
|
||||||
+ region.style().button_padding,
|
+ region.style().button_padding,
|
||||||
Some(id),
|
Some(id),
|
||||||
);
|
);
|
||||||
let text_cursor = interact.rect.min()
|
let text_cursor = interact.rect.min
|
||||||
+ region.style().button_padding
|
+ region.style().button_padding
|
||||||
+ vec2(region.style().start_icon_width, 0.0);
|
+ vec2(region.style().start_icon_width, 0.0);
|
||||||
if interact.clicked {
|
if interact.clicked {
|
||||||
|
@ -273,7 +273,7 @@ impl Widget for RadioButton {
|
||||||
+ region.style().button_padding,
|
+ region.style().button_padding,
|
||||||
Some(id),
|
Some(id),
|
||||||
);
|
);
|
||||||
let text_cursor = interact.rect.min()
|
let text_cursor = interact.rect.min
|
||||||
+ region.style().button_padding
|
+ region.style().button_padding
|
||||||
+ vec2(region.style().start_icon_width, 0.0);
|
+ vec2(region.style().start_icon_width, 0.0);
|
||||||
|
|
||||||
|
|
|
@ -198,7 +198,7 @@ impl Window {
|
||||||
|
|
||||||
let corner_interact = if self.resizeable {
|
let corner_interact = if self.resizeable {
|
||||||
// Resize-corner:
|
// Resize-corner:
|
||||||
let corner_center = outer_rect.max() - Vec2::splat(corner_radius);
|
let corner_center = outer_rect.max - Vec2::splat(corner_radius);
|
||||||
let corner_rect = Rect::from_min_size(corner_center, Vec2::splat(corner_radius));
|
let corner_rect = Rect::from_min_size(corner_center, Vec2::splat(corner_radius));
|
||||||
|
|
||||||
let corner_interact = ctx.interact(layer, &corner_rect, Some(id.with("corner")));
|
let corner_interact = ctx.interact(layer, &corner_rect, Some(id.with("corner")));
|
||||||
|
|
|
@ -267,7 +267,7 @@ impl Painter {
|
||||||
let height_points = height_pixels as f32 / pixels_per_point;
|
let height_points = height_pixels as f32 / pixels_per_point;
|
||||||
|
|
||||||
let uniforms = uniform! {
|
let uniforms = uniform! {
|
||||||
u_clip_rect: [clip_rect.min().x, clip_rect.min().y, clip_rect.max().x, clip_rect.max().y],
|
u_clip_rect: [clip_rect.min.x, clip_rect.min.y, clip_rect.max.x, clip_rect.max.y],
|
||||||
u_screen_size: [width_points, height_points],
|
u_screen_size: [width_points, height_points],
|
||||||
u_tex_size: [texture.width as f32, texture.height as f32],
|
u_tex_size: [texture.width as f32, texture.height as f32],
|
||||||
u_sampler: &self.texture,
|
u_sampler: &self.texture,
|
||||||
|
|
|
@ -214,8 +214,8 @@ impl Painter {
|
||||||
|
|
||||||
for (clip_rect, mesh) in batches {
|
for (clip_rect, mesh) in batches {
|
||||||
// Avoid infinities in shader:
|
// Avoid infinities in shader:
|
||||||
let clip_min = clip_rect.min().max(Pos2::default());
|
let clip_min = clip_rect.min.max(Pos2::default());
|
||||||
let clip_max = clip_rect.max().min(Pos2::default() + screen_size_points);
|
let clip_max = clip_rect.max.min(Pos2::default() + screen_size_points);
|
||||||
|
|
||||||
gl.uniform4f(
|
gl.uniform4f(
|
||||||
Some(&u_clip_rect_loc),
|
Some(&u_clip_rect_loc),
|
||||||
|
|
Loading…
Reference in a new issue