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 {
|
||||
pub fn show(self, region: &mut Region, add_contents: impl FnOnce(&mut Region)) -> GuiResponse {
|
||||
assert!(
|
||||
region.dir == Direction::Vertical,
|
||||
region.direction() == Direction::Vertical,
|
||||
"Horizontal collapsing is unimplemented"
|
||||
);
|
||||
let Self {
|
||||
|
@ -55,27 +55,27 @@ impl CollapsingHeader {
|
|||
let interact = region.reserve_space(
|
||||
vec2(
|
||||
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),
|
||||
);
|
||||
|
||||
let state = {
|
||||
let mut memory = region.ctx.memory();
|
||||
let mut memory = region.memory();
|
||||
let mut state = memory.collapsing_headers.entry(id).or_insert(State {
|
||||
open: default_open,
|
||||
..Default::default()
|
||||
});
|
||||
if interact.clicked {
|
||||
state.open = !state.open;
|
||||
state.toggle_time = region.ctx.input().time;
|
||||
state.toggle_time = region.input().time;
|
||||
}
|
||||
*state
|
||||
};
|
||||
|
||||
region.add_paint_cmd(PaintCmd::Rect {
|
||||
corner_radius: region.style.interact_corner_radius(&interact),
|
||||
fill_color: region.style.interact_fill_color(&interact),
|
||||
corner_radius: region.style().interact_corner_radius(&interact),
|
||||
fill_color: region.style().interact_fill_color(&interact),
|
||||
outline: region.style().interact_outline(&interact),
|
||||
rect: interact.rect,
|
||||
});
|
||||
|
@ -84,16 +84,16 @@ impl CollapsingHeader {
|
|||
|
||||
region.add_text(
|
||||
pos2(
|
||||
interact.rect.left() + region.style.indent,
|
||||
interact.rect.left() + region.style().indent,
|
||||
interact.rect.center().y - text_size.y / 2.0,
|
||||
),
|
||||
text_style,
|
||||
title,
|
||||
Some(region.style.interact_stroke_color(&interact)),
|
||||
Some(region.style().interact_stroke_color(&interact)),
|
||||
);
|
||||
|
||||
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;
|
||||
if animate {
|
||||
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);
|
||||
|
||||
region.child_bounds.max.y =
|
||||
region.child_bounds.max.y.min(region.cursor.y + max_height);
|
||||
region.child_bounds.max.y = region
|
||||
.child_bounds
|
||||
.max
|
||||
.y
|
||||
.min(region.cursor().y + max_height);
|
||||
});
|
||||
} else if state.open {
|
||||
region.indent(id, add_contents);
|
||||
|
@ -129,12 +132,12 @@ impl CollapsingHeader {
|
|||
}
|
||||
|
||||
fn paint_icon(region: &mut Region, state: &State, interact: &InteractInfo) {
|
||||
let stroke_color = region.style.interact_stroke_color(&interact);
|
||||
let stroke_width = region.style.interact_stroke_width(&interact);
|
||||
let stroke_color = region.style().interact_stroke_color(&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(
|
||||
interact.rect.left() + region.style.indent / 2.0,
|
||||
interact.rect.left() + region.style().indent / 2.0,
|
||||
interact.rect.center().y,
|
||||
));
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ impl ScrollArea {
|
|||
pub fn show(self, outer_region: &mut Region, add_contents: impl FnOnce(&mut Region)) {
|
||||
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
|
||||
.memory()
|
||||
.scroll_areas
|
||||
|
@ -74,7 +74,7 @@ impl ScrollArea {
|
|||
);
|
||||
|
||||
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(
|
||||
outer_region.cursor() - state.offset,
|
||||
|
|
|
@ -215,7 +215,7 @@ impl Painting {
|
|||
|
||||
region.add_custom_contents(vec2(f32::INFINITY, 200.0), |region| {
|
||||
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
|
||||
|
||||
if self.lines.is_empty() {
|
||||
|
|
|
@ -8,17 +8,17 @@ use crate::{color::*, containers::*, font::TextFragment, layout::*, widgets::*,
|
|||
pub struct Region {
|
||||
// TODO: remove pub(crate) from all members.
|
||||
/// How we access input, output and memory
|
||||
pub(crate) ctx: Arc<Context>,
|
||||
ctx: Arc<Context>,
|
||||
|
||||
/// ID of this region.
|
||||
/// Generated based on id of parent region together with
|
||||
/// another source of child identity (e.g. window title).
|
||||
/// Acts like a namespace for child regions.
|
||||
/// Hopefully unique.
|
||||
pub(crate) id: Id,
|
||||
id: Id,
|
||||
|
||||
/// 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.
|
||||
/// This means nothing outside of this rectangle will be visible on screen.
|
||||
|
@ -36,20 +36,20 @@ pub struct Region {
|
|||
pub(crate) child_bounds: Rect,
|
||||
|
||||
/// Overide default style in this region
|
||||
pub(crate) style: Style,
|
||||
style: Style,
|
||||
|
||||
// Layout stuff follows. TODO: move to own type and abstract.
|
||||
/// Doesn't change.
|
||||
pub(crate) dir: Direction,
|
||||
dir: Direction,
|
||||
|
||||
pub(crate) align: Align,
|
||||
align: Align,
|
||||
|
||||
/// Where the next widget will be put.
|
||||
/// Progresses along self.dir.
|
||||
/// Initially set to rect.min
|
||||
/// 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.
|
||||
pub(crate) cursor: Pos2,
|
||||
cursor: Pos2,
|
||||
}
|
||||
|
||||
impl Region {
|
||||
|
@ -105,6 +105,10 @@ impl Region {
|
|||
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.
|
||||
pub fn style(&self) -> &Style {
|
||||
&self.style
|
||||
|
|
|
@ -131,7 +131,7 @@ impl<'a> Widget for Slider<'a> {
|
|||
.desired_rect
|
||||
.set_height(slider_response.rect.height());
|
||||
columns[1].horizontal(|region| {
|
||||
region.align = Align::Center;
|
||||
region.set_align(Align::Center);
|
||||
region.add(Label::new(full_text).multiline(false));
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue