Use extremely explicit names like available_rect_before_wrap
This commit is contained in:
parent
042125c8e4
commit
2bb99213c8
12 changed files with 67 additions and 49 deletions
|
@ -180,7 +180,7 @@ impl CollapsingHeader {
|
||||||
|
|
||||||
let id = ui.make_persistent_id(id_source);
|
let id = ui.make_persistent_id(id_source);
|
||||||
|
|
||||||
let available = ui.available_finite();
|
let available = ui.available_rect_before_wrap_finite();
|
||||||
let text_pos = available.min + vec2(ui.style().spacing.indent, 0.0);
|
let text_pos = available.min + vec2(ui.style().spacing.indent, 0.0);
|
||||||
let galley = label.layout_width(ui, available.right() - text_pos.x);
|
let galley = label.layout_width(ui, available.right() - text_pos.x);
|
||||||
let text_max_x = text_pos.x + galley.size.x;
|
let text_max_x = text_pos.x + galley.size.x;
|
||||||
|
|
|
@ -87,7 +87,7 @@ fn button_frame(
|
||||||
add_contents: impl FnOnce(&mut Ui),
|
add_contents: impl FnOnce(&mut Ui),
|
||||||
) -> Response {
|
) -> Response {
|
||||||
let margin = ui.style().spacing.button_padding;
|
let margin = ui.style().spacing.button_padding;
|
||||||
let outer_rect_bounds = ui.available();
|
let outer_rect_bounds = ui.available_rect_before_wrap();
|
||||||
let inner_rect = outer_rect_bounds.shrink2(margin);
|
let inner_rect = outer_rect_bounds.shrink2(margin);
|
||||||
let where_to_put_background = ui.painter().add(PaintCmd::Noop);
|
let where_to_put_background = ui.painter().add(PaintCmd::Noop);
|
||||||
let mut content_ui = ui.child_ui(inner_rect, *ui.layout());
|
let mut content_ui = ui.child_ui(inner_rect, *ui.layout());
|
||||||
|
|
|
@ -99,7 +99,7 @@ pub struct Prepared {
|
||||||
impl Frame {
|
impl Frame {
|
||||||
pub fn begin(self, ui: &mut Ui) -> Prepared {
|
pub fn begin(self, ui: &mut Ui) -> Prepared {
|
||||||
let where_to_put_background = ui.painter().add(PaintCmd::Noop);
|
let where_to_put_background = ui.painter().add(PaintCmd::Noop);
|
||||||
let outer_rect_bounds = ui.available();
|
let outer_rect_bounds = ui.available_rect_before_wrap();
|
||||||
let inner_rect = outer_rect_bounds.shrink2(self.margin);
|
let inner_rect = outer_rect_bounds.shrink2(self.margin);
|
||||||
let content_ui = ui.child_ui(inner_rect, *ui.layout());
|
let content_ui = ui.child_ui(inner_rect, *ui.layout());
|
||||||
|
|
||||||
|
|
|
@ -153,7 +153,7 @@ struct Prepared {
|
||||||
|
|
||||||
impl Resize {
|
impl Resize {
|
||||||
fn begin(&mut self, ui: &mut Ui) -> Prepared {
|
fn begin(&mut self, ui: &mut Ui) -> Prepared {
|
||||||
let position = ui.available().min;
|
let position = ui.available_rect_before_wrap().min;
|
||||||
let id = self.id.unwrap_or_else(|| {
|
let id = self.id.unwrap_or_else(|| {
|
||||||
let id_source = self.id_source.unwrap_or_else(|| Id::new("resize"));
|
let id_source = self.id_source.unwrap_or_else(|| Id::new("resize"));
|
||||||
ui.make_persistent_id(id_source)
|
ui.make_persistent_id(id_source)
|
||||||
|
|
|
@ -104,11 +104,11 @@ impl ScrollArea {
|
||||||
|
|
||||||
let outer_size = vec2(
|
let outer_size = vec2(
|
||||||
ui.available_width(),
|
ui.available_width(),
|
||||||
ui.available().height().at_most(max_height),
|
ui.available_size_before_wrap().y.at_most(max_height),
|
||||||
);
|
);
|
||||||
|
|
||||||
let inner_size = outer_size - vec2(current_scroll_bar_width, 0.0);
|
let inner_size = outer_size - vec2(current_scroll_bar_width, 0.0);
|
||||||
let inner_rect = Rect::from_min_size(ui.available().min, inner_size);
|
let inner_rect = Rect::from_min_size(ui.available_rect_before_wrap().min, inner_size);
|
||||||
|
|
||||||
let mut content_ui = ui.child_ui(
|
let mut content_ui = ui.child_ui(
|
||||||
Rect::from_min_size(
|
Rect::from_min_size(
|
||||||
|
|
|
@ -106,7 +106,7 @@ impl FrameHistory {
|
||||||
|
|
||||||
// TODO: we should not use `slider_width` as default graph width.
|
// TODO: we should not use `slider_width` as default graph width.
|
||||||
let height = ui.style().spacing.slider_width;
|
let height = ui.style().spacing.slider_width;
|
||||||
let rect = ui.allocate_space(vec2(ui.available_finite().width(), height));
|
let rect = ui.allocate_space(vec2(ui.available_size_before_wrap_finite().x, height));
|
||||||
let style = ui.style().noninteractive();
|
let style = ui.style().noninteractive();
|
||||||
|
|
||||||
let mut cmds = vec![PaintCmd::Rect {
|
let mut cmds = vec![PaintCmd::Rect {
|
||||||
|
|
|
@ -265,7 +265,7 @@ impl Painting {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn content(&mut self, ui: &mut Ui) {
|
fn content(&mut self, ui: &mut Ui) {
|
||||||
let rect = ui.allocate_space(ui.available_finite().size());
|
let rect = ui.allocate_space(ui.available_size_before_wrap_finite());
|
||||||
let response = ui.interact(rect, ui.id(), Sense::drag());
|
let response = ui.interact(rect, ui.id(), Sense::drag());
|
||||||
let rect = response.rect;
|
let rect = response.rect;
|
||||||
let clip_rect = ui.clip_rect().intersect(rect); // Make sure we don't paint out of bounds
|
let clip_rect = ui.clip_rect().intersect(rect); // Make sure we don't paint out of bounds
|
||||||
|
@ -343,12 +343,18 @@ impl LayoutDemo {
|
||||||
if self.main_wrap {
|
if self.main_wrap {
|
||||||
if self.main_dir.is_horizontal() {
|
if self.main_dir.is_horizontal() {
|
||||||
ui.allocate_ui(
|
ui.allocate_ui(
|
||||||
vec2(ui.available_finite().width(), self.wrap_row_height),
|
vec2(
|
||||||
|
ui.available_size_before_wrap_finite().x,
|
||||||
|
self.wrap_row_height,
|
||||||
|
),
|
||||||
|ui| ui.with_layout(self.layout(), |ui| self.demo_ui(ui)),
|
|ui| ui.with_layout(self.layout(), |ui| self.demo_ui(ui)),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
ui.allocate_ui(
|
ui.allocate_ui(
|
||||||
vec2(self.wrap_column_width, ui.available_finite().height()),
|
vec2(
|
||||||
|
self.wrap_column_width,
|
||||||
|
ui.available_size_before_wrap_finite().y,
|
||||||
|
),
|
||||||
|ui| ui.with_layout(self.layout(), |ui| self.demo_ui(ui)),
|
|ui| ui.with_layout(self.layout(), |ui| self.demo_ui(ui)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ pub fn drop_target<R>(
|
||||||
|
|
||||||
let margin = Vec2::splat(4.0);
|
let margin = Vec2::splat(4.0);
|
||||||
|
|
||||||
let outer_rect_bounds = ui.available();
|
let outer_rect_bounds = ui.available_rect_before_wrap();
|
||||||
let inner_rect = outer_rect_bounds.shrink2(margin);
|
let inner_rect = outer_rect_bounds.shrink2(margin);
|
||||||
let where_to_put_background = ui.painter().add(PaintCmd::Noop);
|
let where_to_put_background = ui.painter().add(PaintCmd::Noop);
|
||||||
let mut content_ui = ui.child_ui(inner_rect, *ui.layout());
|
let mut content_ui = ui.child_ui(inner_rect, *ui.layout());
|
||||||
|
|
|
@ -52,8 +52,12 @@ impl FractalClock {
|
||||||
ui.ctx().request_repaint();
|
ui.ctx().request_repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
let painter = Painter::new(ui.ctx().clone(), ui.layer_id(), ui.available_finite());
|
let painter = Painter::new(
|
||||||
self.fractal_ui(&painter);
|
ui.ctx().clone(),
|
||||||
|
ui.layer_id(),
|
||||||
|
ui.available_rect_before_wrap_finite(),
|
||||||
|
);
|
||||||
|
self.paint(&painter);
|
||||||
|
|
||||||
Frame::popup(ui.style())
|
Frame::popup(ui.style())
|
||||||
.fill(Rgba::luminance_alpha(0.02, 0.5).into())
|
.fill(Rgba::luminance_alpha(0.02, 0.5).into())
|
||||||
|
@ -97,7 +101,7 @@ impl FractalClock {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fractal_ui(&mut self, painter: &Painter) {
|
fn paint(&mut self, painter: &Painter) {
|
||||||
let rect = painter.clip_rect();
|
let rect = painter.clip_rect();
|
||||||
|
|
||||||
struct Hand {
|
struct Hand {
|
||||||
|
|
|
@ -290,11 +290,22 @@ impl Layout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: clarify if it is before or after wrap
|
pub(crate) fn available_rect_before_wrap(&self, region: &Region) -> Rect {
|
||||||
pub(crate) fn available(&self, region: &Region) -> Rect {
|
|
||||||
self.available_from_cursor_max_rect(region.cursor, region.max_rect)
|
self.available_from_cursor_max_rect(region.cursor, region.max_rect)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn available_size_before_wrap(&self, region: &Region) -> Vec2 {
|
||||||
|
self.available_rect_before_wrap(region).size()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn available_rect_before_wrap_finite(&self, region: &Region) -> Rect {
|
||||||
|
self.available_from_cursor_max_rect(region.cursor, region.max_rect_finite())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn available_size_before_wrap_finite(&self, region: &Region) -> Vec2 {
|
||||||
|
self.available_rect_before_wrap_finite(region).size()
|
||||||
|
}
|
||||||
|
|
||||||
/// Amount of space available for a widget.
|
/// Amount of space available for a widget.
|
||||||
/// Wor wrapping layouts, this is the maximum (after wrap)
|
/// Wor wrapping layouts, this is the maximum (after wrap)
|
||||||
pub fn available_size(&self, r: &Region) -> Vec2 {
|
pub fn available_size(&self, r: &Region) -> Vec2 {
|
||||||
|
@ -310,17 +321,6 @@ impl Layout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// In case of a wrapping layout, how much space is left on this row/column?
|
|
||||||
pub fn available_size_before_wrap(&self, region: &Region) -> Vec2 {
|
|
||||||
self.available_from_cursor_max_rect(region.cursor, region.max_rect)
|
|
||||||
.size()
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
pub fn available_finite(&self, region: &Region) -> Rect {
|
|
||||||
self.available_from_cursor_max_rect(region.cursor, region.max_rect_finite())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Given the cursor in the region, how much space is available
|
/// Given the cursor in the region, how much space is available
|
||||||
/// for the next widget?
|
/// for the next widget?
|
||||||
fn available_from_cursor_max_rect(self, cursor: Pos2, max_rect: Rect) -> Rect {
|
fn available_from_cursor_max_rect(self, cursor: Pos2, max_rect: Rect) -> Rect {
|
||||||
|
@ -398,7 +398,7 @@ impl Layout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let available_size = self.available_finite(region).size();
|
let available_size = self.available_size_before_wrap_finite(region);
|
||||||
if self.main_dir.is_horizontal() {
|
if self.main_dir.is_horizontal() {
|
||||||
// Fill full height
|
// Fill full height
|
||||||
child_size.y = child_size.y.max(available_size.y);
|
child_size.y = child_size.y.max(available_size.y);
|
||||||
|
|
|
@ -324,20 +324,28 @@ impl Ui {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// In case of a wrapping layout, how much space is left on this row/column?
|
/// In case of a wrapping layout, how much space is left on this row/column?
|
||||||
pub fn available_width_before_wrap(&self) -> f32 {
|
pub fn available_size_before_wrap(&self) -> Vec2 {
|
||||||
self.layout.available_size_before_wrap(&self.region).x
|
self.layout.available_size_before_wrap(&self.region)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: clarify if this is before or after wrap
|
/// This is like `available_size_before_wrap()`, but will never be infinite.
|
||||||
pub fn available(&self) -> Rect {
|
|
||||||
self.layout.available(&self.region)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// This is like `available()`, but will never be infinite.
|
|
||||||
/// Use this for components that want to grow without bounds (but shouldn't).
|
/// Use this for components that want to grow without bounds (but shouldn't).
|
||||||
/// In most layouts the next widget will be put in the top left corner of this `Rect`.
|
/// In most layouts the next widget will be put in the top left corner of this `Rect`.
|
||||||
pub fn available_finite(&self) -> Rect {
|
pub fn available_size_before_wrap_finite(&self) -> Vec2 {
|
||||||
self.layout.available_finite(&self.region)
|
self.layout
|
||||||
|
.available_rect_before_wrap_finite(&self.region)
|
||||||
|
.size()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn available_rect_before_wrap(&self) -> Rect {
|
||||||
|
self.layout.available_rect_before_wrap(&self.region)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// This is like `available_rect_before_wrap()`, but will never be infinite.
|
||||||
|
/// Use this for components that want to grow without bounds (but shouldn't).
|
||||||
|
/// In most layouts the next widget will be put in the top left corner of this `Rect`.
|
||||||
|
pub fn available_rect_before_wrap_finite(&self) -> Rect {
|
||||||
|
self.layout.available_rect_before_wrap_finite(&self.region)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -411,9 +419,9 @@ impl Ui {
|
||||||
/// You may get LESS space than you asked for if the current layout won't fit what you asked for.
|
/// You may get LESS space than you asked for if the current layout won't fit what you asked for.
|
||||||
pub fn allocate_space(&mut self, desired_size: Vec2) -> Rect {
|
pub fn allocate_space(&mut self, desired_size: Vec2) -> Rect {
|
||||||
// For debug rendering
|
// For debug rendering
|
||||||
let original_size = self.available().size();
|
let original_available = self.available_size_before_wrap();
|
||||||
let too_wide = desired_size.x > original_size.x;
|
let too_wide = desired_size.x > original_available.x;
|
||||||
let too_high = desired_size.y > original_size.y;
|
let too_high = desired_size.y > original_available.y;
|
||||||
|
|
||||||
let rect = self.allocate_space_impl(desired_size);
|
let rect = self.allocate_space_impl(desired_size);
|
||||||
|
|
||||||
|
@ -432,8 +440,8 @@ impl Ui {
|
||||||
paint_line_seg(rect.left_top(), rect.left_bottom());
|
paint_line_seg(rect.left_top(), rect.left_bottom());
|
||||||
paint_line_seg(rect.left_center(), rect.right_center());
|
paint_line_seg(rect.left_center(), rect.right_center());
|
||||||
paint_line_seg(
|
paint_line_seg(
|
||||||
pos2(rect.left() + original_size.x, rect.top()),
|
pos2(rect.left() + original_available.x, rect.top()),
|
||||||
pos2(rect.left() + original_size.x, rect.bottom()),
|
pos2(rect.left() + original_available.x, rect.bottom()),
|
||||||
);
|
);
|
||||||
paint_line_seg(rect.right_top(), rect.right_bottom());
|
paint_line_seg(rect.right_top(), rect.right_bottom());
|
||||||
}
|
}
|
||||||
|
@ -714,7 +722,7 @@ impl Ui {
|
||||||
impl Ui {
|
impl Ui {
|
||||||
/// Create a child ui. You can use this to temporarily change the Style of a sub-region, for instance.
|
/// Create a child ui. You can use this to temporarily change the Style of a sub-region, for instance.
|
||||||
pub fn wrap<R>(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> (R, Response) {
|
pub fn wrap<R>(&mut self, add_contents: impl FnOnce(&mut Ui) -> R) -> (R, Response) {
|
||||||
let child_rect = self.available();
|
let child_rect = self.available_rect_before_wrap();
|
||||||
let mut child_ui = self.child_ui(child_rect, self.layout);
|
let mut child_ui = self.child_ui(child_rect, self.layout);
|
||||||
let ret = add_contents(&mut child_ui);
|
let ret = add_contents(&mut child_ui);
|
||||||
let size = child_ui.min_size();
|
let size = child_ui.min_size();
|
||||||
|
@ -808,7 +816,7 @@ impl Ui {
|
||||||
self.child_ui(
|
self.child_ui(
|
||||||
Rect::from_min_size(
|
Rect::from_min_size(
|
||||||
self.region.cursor + vec2(x, 0.0),
|
self.region.cursor + vec2(x, 0.0),
|
||||||
vec2(width, self.available().height()),
|
vec2(width, self.available_size_before_wrap().y),
|
||||||
),
|
),
|
||||||
self.layout,
|
self.layout,
|
||||||
)
|
)
|
||||||
|
@ -880,7 +888,7 @@ impl Ui {
|
||||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||||
) -> (R, Response) {
|
) -> (R, Response) {
|
||||||
let initial_size = vec2(
|
let initial_size = vec2(
|
||||||
self.available_finite().width(),
|
self.available_size_before_wrap_finite().x,
|
||||||
self.style().spacing.interact_size.y, // Assume there will be something interactive on the horizontal layout
|
self.style().spacing.interact_size.y, // Assume there will be something interactive on the horizontal layout
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -905,7 +913,7 @@ impl Ui {
|
||||||
layout: Layout,
|
layout: Layout,
|
||||||
add_contents: impl FnOnce(&mut Self) -> R,
|
add_contents: impl FnOnce(&mut Self) -> R,
|
||||||
) -> (R, Response) {
|
) -> (R, Response) {
|
||||||
let mut child_ui = self.child_ui(self.available(), layout);
|
let mut child_ui = self.child_ui(self.available_rect_before_wrap(), layout);
|
||||||
let ret = add_contents(&mut child_ui);
|
let ret = add_contents(&mut child_ui);
|
||||||
let rect = child_ui.min_rect();
|
let rect = child_ui.min_rect();
|
||||||
let item_spacing = self.style().spacing.item_spacing;
|
let item_spacing = self.style().spacing.item_spacing;
|
||||||
|
|
|
@ -130,7 +130,7 @@ impl Widget for Label {
|
||||||
// then continue on the line below! This will take some extra work:
|
// then continue on the line below! This will take some extra work:
|
||||||
|
|
||||||
let max_width = ui.available_width();
|
let max_width = ui.available_width();
|
||||||
let first_row_indentation = max_width - ui.available_width_before_wrap();
|
let first_row_indentation = max_width - ui.available_size_before_wrap().x;
|
||||||
|
|
||||||
let text_style = self.text_style_or_default(ui.style());
|
let text_style = self.text_style_or_default(ui.style());
|
||||||
let font = &ui.fonts()[text_style];
|
let font = &ui.fonts()[text_style];
|
||||||
|
@ -664,7 +664,7 @@ impl Widget for Separator {
|
||||||
fn ui(self, ui: &mut Ui) -> Response {
|
fn ui(self, ui: &mut Ui) -> Response {
|
||||||
let Separator { spacing } = self;
|
let Separator { spacing } = self;
|
||||||
|
|
||||||
let available_space = ui.available_finite().size();
|
let available_space = ui.available_size_before_wrap_finite();
|
||||||
|
|
||||||
let (points, rect) = if ui.layout().main_dir().is_horizontal() {
|
let (points, rect) = if ui.layout().main_dir().is_horizontal() {
|
||||||
let rect = ui.allocate_space(vec2(spacing, available_space.y));
|
let rect = ui.allocate_space(vec2(spacing, available_space.y));
|
||||||
|
|
Loading…
Reference in a new issue