Compare commits
1 Commits
9febd03067
...
db248de8f4
| Author | SHA1 | Date | |
|---|---|---|---|
| db248de8f4 |
@@ -34,9 +34,8 @@ impl Widget for Span {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn desired_size(&mut self, ctx: &mut SizeCtx) -> Size {
|
fn desired_size(&mut self, ctx: &mut SizeCtx) -> Size {
|
||||||
let mut sums = self.len_sum(ctx);
|
let sums = self.len_sum(ctx);
|
||||||
let dir_len = if sums.rest == 0.0 && sums.rel == 0.0 {
|
let dir_len = if sums.rest == 0.0 && sums.rel == 0.0 {
|
||||||
sums.abs += self.gap * self.children.len().saturating_sub(1) as f32;
|
|
||||||
sums
|
sums
|
||||||
} else {
|
} else {
|
||||||
Len::default()
|
Len::default()
|
||||||
@@ -71,7 +70,8 @@ impl Span {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn len_sum(&mut self, ctx: &mut SizeCtx) -> Len {
|
fn len_sum(&mut self, ctx: &mut SizeCtx) -> Len {
|
||||||
self.children.iter_mut().fold(Len::ZERO, |mut s, id| {
|
let gap = self.gap * self.children.len().saturating_sub(1) as f32;
|
||||||
|
self.children.iter_mut().fold(Len::abs(gap), |mut s, id| {
|
||||||
s += ctx.size(id).axis(self.dir.axis);
|
s += ctx.size(id).axis(self.dir.axis);
|
||||||
s
|
s
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ impl<Ctx: UiCtx + 'static> CursorModule<Ctx> {
|
|||||||
let mut sensed = false;
|
let mut sensed = false;
|
||||||
for (id, shape) in list.iter() {
|
for (id, shape) in list.iter() {
|
||||||
let group = module.map.get_mut(id).unwrap();
|
let group = module.map.get_mut(id).unwrap();
|
||||||
let region = shape.to_screen(window_size);
|
let region = shape.to_px(window_size);
|
||||||
let in_shape = cursor.exists && region.contains(cursor.pos);
|
let in_shape = cursor.exists && region.contains(cursor.pos);
|
||||||
group.hover.update(in_shape);
|
group.hover.update(in_shape);
|
||||||
if group.hover == ActivationState::Off {
|
if group.hover == ActivationState::Off {
|
||||||
|
|||||||
@@ -387,6 +387,10 @@ impl<'a, 'c> Painter<'a, 'c> {
|
|||||||
pub fn next_layer(&mut self) {
|
pub fn next_layer(&mut self) {
|
||||||
self.layer = self.ctx.layers.next(self.layer);
|
self.layer = self.ctx.layers.next(self.layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn label(&self) -> &str {
|
||||||
|
&self.ctx.widgets.data(&self.id).unwrap().label
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct SizeCtx<'a> {
|
pub struct SizeCtx<'a> {
|
||||||
@@ -411,9 +415,9 @@ impl SizeCtx<'_> {
|
|||||||
size
|
size
|
||||||
}
|
}
|
||||||
pub fn size<W>(&mut self, id: &WidgetId<W>) -> Size {
|
pub fn size<W>(&mut self, id: &WidgetId<W>) -> Size {
|
||||||
if let Some(&size) = self.checked.get(&id.id) {
|
// if let Some(&size) = self.checked.get(&id.id) {
|
||||||
return size;
|
// return size;
|
||||||
}
|
// }
|
||||||
self.size_inner(id.id, self.size)
|
self.size_inner(id.id, self.size)
|
||||||
}
|
}
|
||||||
fn size_raw(&mut self, id: Id) -> Size {
|
fn size_raw(&mut self, id: Id) -> Size {
|
||||||
|
|||||||
@@ -168,6 +168,7 @@ impl_op!(UiScalar Sub sub; rel abs);
|
|||||||
|
|
||||||
impl UiScalar {
|
impl UiScalar {
|
||||||
pub const ZERO: Self = Self { rel: 0.0, abs: 0.0 };
|
pub const ZERO: Self = Self { rel: 0.0, abs: 0.0 };
|
||||||
|
pub const FULL: Self = Self { rel: 1.0, abs: 0.0 };
|
||||||
|
|
||||||
pub fn new(rel: f32, abs: f32) -> Self {
|
pub fn new(rel: f32, abs: f32) -> Self {
|
||||||
Self { rel, abs }
|
Self { rel, abs }
|
||||||
@@ -272,7 +273,7 @@ impl UiRegion {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_screen(&self, size: Vec2) -> PixelRegion {
|
pub fn to_px(&self, size: Vec2) -> PixelRegion {
|
||||||
PixelRegion {
|
PixelRegion {
|
||||||
top_left: self.top_left.rel * size + self.top_left.abs,
|
top_left: self.top_left.rel * size + self.top_left.abs,
|
||||||
bot_right: self.bot_right.rel * size + self.bot_right.abs,
|
bot_right: self.bot_right.rel * size + self.bot_right.abs,
|
||||||
@@ -347,6 +348,12 @@ impl PixelRegion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Display for PixelRegion {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "{} -> {}", self.top_left, self.bot_right)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct UIRegionAxisView<'a> {
|
pub struct UIRegionAxisView<'a> {
|
||||||
pub top_left: UiScalarView<'a>,
|
pub top_left: UiScalarView<'a>,
|
||||||
pub bot_right: UiScalarView<'a>,
|
pub bot_right: UiScalarView<'a>,
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ impl Ui {
|
|||||||
|
|
||||||
pub fn window_region<W>(&self, id: &impl IdLike<W>) -> Option<PixelRegion> {
|
pub fn window_region<W>(&self, id: &impl IdLike<W>) -> Option<PixelRegion> {
|
||||||
let region = self.data.active.get(&id.id())?.region;
|
let region = self.data.active.get(&id.id())?.region;
|
||||||
Some(region.to_screen(self.data.output_size))
|
Some(region.to_px(self.data.output_size))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn debug(&self, label: &str) {
|
pub fn debug(&self, label: &str) {
|
||||||
@@ -192,6 +192,10 @@ impl Ui {
|
|||||||
}
|
}
|
||||||
println!("\"{label}\" {{");
|
println!("\"{label}\" {{");
|
||||||
println!(" region: {}", inst.region);
|
println!(" region: {}", inst.region);
|
||||||
|
println!(
|
||||||
|
" pixel region: {}",
|
||||||
|
inst.region.to_px(self.data.output_size)
|
||||||
|
);
|
||||||
println!(" desired_size: {}", inst.desired_size);
|
println!(" desired_size: {}", inst.desired_size);
|
||||||
println!("}}");
|
println!("}}");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user