ing prefix gives off bad vibes

This commit is contained in:
2025-09-29 14:01:34 -04:00
parent 337af3e18c
commit db0d11cacb
8 changed files with 2 additions and 2 deletions

63
src/core/position/pad.rs Normal file
View File

@@ -0,0 +1,63 @@
use crate::prelude::*;
pub struct Padded {
pub padding: Padding,
pub inner: WidgetId,
}
impl Widget for Padded {
fn draw(&mut self, painter: &mut Painter) {
painter.widget_within(&self.inner, self.padding.region());
}
fn desired_size(&mut self, ctx: &mut SizeCtx) -> UiVec2 {
let mut size = ctx.size(&self.inner);
// TODO: this is currently a hack
// the correct solution is that the position is not linear
// becauase if you have 0.5 rel + 100 abs, it's linear
// until you fill up parent rel (in abs units) and then 1.0 rel (piecewise linear)
// so I guess yet another detection system is needed
// to determine when abs translated to rel + rel > 1.0
// hopefully find a way to get working on gpu so no cpu changing needed
// eg by sending size to calculate above and then doing... something?
if size.rel.x != 1.0 {
size.abs.x += self.padding.left + self.padding.right;
}
if size.rel.y != 1.0 {
size.abs.y += self.padding.top + self.padding.bottom;
}
size
}
}
pub struct Padding {
pub left: f32,
pub right: f32,
pub top: f32,
pub bottom: f32,
}
impl Padding {
pub fn uniform(amt: f32) -> Self {
Self {
left: amt,
right: amt,
top: amt,
bottom: amt,
}
}
pub fn region(&self) -> UiRegion {
let mut region = UiRegion::full();
region.top_left.abs.x += self.left;
region.top_left.abs.y += self.top;
region.bot_right.abs.x -= self.right;
region.bot_right.abs.y -= self.bottom;
region
}
}
impl<T: UiNum> From<T> for Padding {
fn from(amt: T) -> Self {
Self::uniform(amt.to_f32())
}
}