Made more Region members private
This commit is contained in:
parent
45016ebf53
commit
2d7131d713
5 changed files with 34 additions and 27 deletions
|
@ -39,7 +39,7 @@ impl CollapsingHeader {
|
||||||
impl CollapsingHeader {
|
impl CollapsingHeader {
|
||||||
pub fn show(self, region: &mut Region, add_contents: impl FnOnce(&mut Region)) -> GuiResponse {
|
pub fn show(self, region: &mut Region, add_contents: impl FnOnce(&mut Region)) -> GuiResponse {
|
||||||
assert!(
|
assert!(
|
||||||
region.dir == Direction::Vertical,
|
region.direction() == Direction::Vertical,
|
||||||
"Horizontal collapsing is unimplemented"
|
"Horizontal collapsing is unimplemented"
|
||||||
);
|
);
|
||||||
let Self {
|
let Self {
|
||||||
|
@ -55,27 +55,27 @@ impl CollapsingHeader {
|
||||||
let interact = region.reserve_space(
|
let interact = region.reserve_space(
|
||||||
vec2(
|
vec2(
|
||||||
region.available_width(),
|
region.available_width(),
|
||||||
text_size.y + 2.0 * region.style.button_padding.y,
|
text_size.y + 2.0 * region.style().button_padding.y,
|
||||||
),
|
),
|
||||||
Some(id),
|
Some(id),
|
||||||
);
|
);
|
||||||
|
|
||||||
let state = {
|
let state = {
|
||||||
let mut memory = region.ctx.memory();
|
let mut memory = region.memory();
|
||||||
let mut state = memory.collapsing_headers.entry(id).or_insert(State {
|
let mut state = memory.collapsing_headers.entry(id).or_insert(State {
|
||||||
open: default_open,
|
open: default_open,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
if interact.clicked {
|
if interact.clicked {
|
||||||
state.open = !state.open;
|
state.open = !state.open;
|
||||||
state.toggle_time = region.ctx.input().time;
|
state.toggle_time = region.input().time;
|
||||||
}
|
}
|
||||||
*state
|
*state
|
||||||
};
|
};
|
||||||
|
|
||||||
region.add_paint_cmd(PaintCmd::Rect {
|
region.add_paint_cmd(PaintCmd::Rect {
|
||||||
corner_radius: region.style.interact_corner_radius(&interact),
|
corner_radius: region.style().interact_corner_radius(&interact),
|
||||||
fill_color: region.style.interact_fill_color(&interact),
|
fill_color: region.style().interact_fill_color(&interact),
|
||||||
outline: region.style().interact_outline(&interact),
|
outline: region.style().interact_outline(&interact),
|
||||||
rect: interact.rect,
|
rect: interact.rect,
|
||||||
});
|
});
|
||||||
|
@ -84,16 +84,16 @@ impl CollapsingHeader {
|
||||||
|
|
||||||
region.add_text(
|
region.add_text(
|
||||||
pos2(
|
pos2(
|
||||||
interact.rect.left() + region.style.indent,
|
interact.rect.left() + region.style().indent,
|
||||||
interact.rect.center().y - text_size.y / 2.0,
|
interact.rect.center().y - text_size.y / 2.0,
|
||||||
),
|
),
|
||||||
text_style,
|
text_style,
|
||||||
title,
|
title,
|
||||||
Some(region.style.interact_stroke_color(&interact)),
|
Some(region.style().interact_stroke_color(&interact)),
|
||||||
);
|
);
|
||||||
|
|
||||||
let animation_time = region.style().animation_time;
|
let animation_time = region.style().animation_time;
|
||||||
let time_since_toggle = (region.ctx.input().time - state.toggle_time) as f32;
|
let time_since_toggle = (region.input().time - state.toggle_time) as f32;
|
||||||
let animate = time_since_toggle < animation_time;
|
let animate = time_since_toggle < animation_time;
|
||||||
if animate {
|
if animate {
|
||||||
region.indent(id, |region| {
|
region.indent(id, |region| {
|
||||||
|
@ -113,12 +113,15 @@ impl CollapsingHeader {
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
region.clip_rect.max.y = region.clip_rect.max.y.min(region.cursor.y + max_height);
|
region.clip_rect.max.y = region.clip_rect.max.y.min(region.cursor().y + max_height);
|
||||||
|
|
||||||
add_contents(region);
|
add_contents(region);
|
||||||
|
|
||||||
region.child_bounds.max.y =
|
region.child_bounds.max.y = region
|
||||||
region.child_bounds.max.y.min(region.cursor.y + max_height);
|
.child_bounds
|
||||||
|
.max
|
||||||
|
.y
|
||||||
|
.min(region.cursor().y + max_height);
|
||||||
});
|
});
|
||||||
} else if state.open {
|
} else if state.open {
|
||||||
region.indent(id, add_contents);
|
region.indent(id, add_contents);
|
||||||
|
@ -129,12 +132,12 @@ impl CollapsingHeader {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn paint_icon(region: &mut Region, state: &State, interact: &InteractInfo) {
|
fn paint_icon(region: &mut Region, state: &State, interact: &InteractInfo) {
|
||||||
let stroke_color = region.style.interact_stroke_color(&interact);
|
let stroke_color = region.style().interact_stroke_color(&interact);
|
||||||
let stroke_width = region.style.interact_stroke_width(&interact);
|
let stroke_width = region.style().interact_stroke_width(&interact);
|
||||||
|
|
||||||
let (mut small_icon_rect, _) = region.style.icon_rectangles(&interact.rect);
|
let (mut small_icon_rect, _) = region.style().icon_rectangles(&interact.rect);
|
||||||
small_icon_rect.set_center(pos2(
|
small_icon_rect.set_center(pos2(
|
||||||
interact.rect.left() + region.style.indent / 2.0,
|
interact.rect.left() + region.style().indent / 2.0,
|
||||||
interact.rect.center().y,
|
interact.rect.center().y,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ impl ScrollArea {
|
||||||
pub fn show(self, outer_region: &mut Region, add_contents: impl FnOnce(&mut Region)) {
|
pub fn show(self, outer_region: &mut Region, add_contents: impl FnOnce(&mut Region)) {
|
||||||
let ctx = outer_region.ctx().clone();
|
let ctx = outer_region.ctx().clone();
|
||||||
|
|
||||||
let scroll_area_id = outer_region.id.with("scroll_area");
|
let scroll_area_id = outer_region.make_child_id("scroll_area");
|
||||||
let mut state = ctx
|
let mut state = ctx
|
||||||
.memory()
|
.memory()
|
||||||
.scroll_areas
|
.scroll_areas
|
||||||
|
@ -74,7 +74,7 @@ impl ScrollArea {
|
||||||
);
|
);
|
||||||
|
|
||||||
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(outer_region.cursor, inner_size);
|
let inner_rect = Rect::from_min_size(outer_region.cursor(), inner_size);
|
||||||
|
|
||||||
let mut content_region = outer_region.child_region(Rect::from_min_size(
|
let mut content_region = outer_region.child_region(Rect::from_min_size(
|
||||||
outer_region.cursor() - state.offset,
|
outer_region.cursor() - state.offset,
|
||||||
|
|
|
@ -215,7 +215,7 @@ impl Painting {
|
||||||
|
|
||||||
region.add_custom_contents(vec2(f32::INFINITY, 200.0), |region| {
|
region.add_custom_contents(vec2(f32::INFINITY, 200.0), |region| {
|
||||||
let canvas_corner = region.cursor();
|
let canvas_corner = region.cursor();
|
||||||
let interact = region.reserve_space(region.available_space(), Some(region.id));
|
let interact = region.reserve_space(region.available_space(), Some(region.id()));
|
||||||
region.clip_rect = region.clip_rect.intersect(&interact.rect); // Make sure we don't paint out of bounds
|
region.clip_rect = region.clip_rect.intersect(&interact.rect); // Make sure we don't paint out of bounds
|
||||||
|
|
||||||
if self.lines.is_empty() {
|
if self.lines.is_empty() {
|
||||||
|
|
|
@ -8,17 +8,17 @@ use crate::{color::*, containers::*, font::TextFragment, layout::*, widgets::*,
|
||||||
pub struct Region {
|
pub struct Region {
|
||||||
// TODO: remove pub(crate) from all members.
|
// TODO: remove pub(crate) from all members.
|
||||||
/// How we access input, output and memory
|
/// How we access input, output and memory
|
||||||
pub(crate) ctx: Arc<Context>,
|
ctx: Arc<Context>,
|
||||||
|
|
||||||
/// ID of this region.
|
/// ID of this region.
|
||||||
/// Generated based on id of parent region together with
|
/// Generated based on id of parent region together with
|
||||||
/// another source of child identity (e.g. window title).
|
/// another source of child identity (e.g. window title).
|
||||||
/// Acts like a namespace for child regions.
|
/// Acts like a namespace for child regions.
|
||||||
/// Hopefully unique.
|
/// Hopefully unique.
|
||||||
pub(crate) id: Id,
|
id: Id,
|
||||||
|
|
||||||
/// Where to put the graphics output of this Region
|
/// Where to put the graphics output of this Region
|
||||||
pub(crate) layer: Layer,
|
layer: Layer,
|
||||||
|
|
||||||
/// Everything painte in this rect will be clipped against this.
|
/// Everything painte in this rect will be clipped against this.
|
||||||
/// This means nothing outside of this rectangle will be visible on screen.
|
/// This means nothing outside of this rectangle will be visible on screen.
|
||||||
|
@ -36,20 +36,20 @@ pub struct Region {
|
||||||
pub(crate) child_bounds: Rect,
|
pub(crate) child_bounds: Rect,
|
||||||
|
|
||||||
/// Overide default style in this region
|
/// Overide default style in this region
|
||||||
pub(crate) style: Style,
|
style: Style,
|
||||||
|
|
||||||
// Layout stuff follows. TODO: move to own type and abstract.
|
// Layout stuff follows. TODO: move to own type and abstract.
|
||||||
/// Doesn't change.
|
/// Doesn't change.
|
||||||
pub(crate) dir: Direction,
|
dir: Direction,
|
||||||
|
|
||||||
pub(crate) align: Align,
|
align: Align,
|
||||||
|
|
||||||
/// 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
|
||||||
/// If something has already been added, this will point ot style.item_spacing beyond the latest child.
|
/// If something has already been added, this will point ot style.item_spacing beyond the latest child.
|
||||||
/// The cursor can thus be style.item_spacing pixels outside of the child_bounds.
|
/// The cursor can thus be style.item_spacing pixels outside of the child_bounds.
|
||||||
pub(crate) cursor: Pos2,
|
cursor: Pos2,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Region {
|
impl Region {
|
||||||
|
@ -105,6 +105,10 @@ impl Region {
|
||||||
self.ctx.round_pos_to_pixels(pos)
|
self.ctx.round_pos_to_pixels(pos)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn id(&self) -> Id {
|
||||||
|
self.id
|
||||||
|
}
|
||||||
|
|
||||||
/// Options for this region, and any child regions we may spawn.
|
/// Options for this region, and any child regions we may spawn.
|
||||||
pub fn style(&self) -> &Style {
|
pub fn style(&self) -> &Style {
|
||||||
&self.style
|
&self.style
|
||||||
|
|
|
@ -131,7 +131,7 @@ impl<'a> Widget for Slider<'a> {
|
||||||
.desired_rect
|
.desired_rect
|
||||||
.set_height(slider_response.rect.height());
|
.set_height(slider_response.rect.height());
|
||||||
columns[1].horizontal(|region| {
|
columns[1].horizontal(|region| {
|
||||||
region.align = Align::Center;
|
region.set_align(Align::Center);
|
||||||
region.add(Label::new(full_text).multiline(false));
|
region.add(Label::new(full_text).multiline(false));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue