panels
This commit is contained in:
31
ui/types.sx
31
ui/types.sx
@@ -47,6 +47,8 @@ Frame :: struct {
|
||||
|
||||
max_x :: (self: Frame) -> f32 { self.origin.x + self.size.width; }
|
||||
max_y :: (self: Frame) -> f32 { self.origin.y + self.size.height; }
|
||||
mid_x :: (self: Frame) -> f32 { self.origin.x + self.size.width * 0.5; }
|
||||
mid_y :: (self: Frame) -> f32 { self.origin.y + self.size.height * 0.5; }
|
||||
|
||||
contains :: (self: Frame, point: Point) -> bool {
|
||||
point.x >= self.origin.x and point.x <= self.max_x()
|
||||
@@ -71,6 +73,15 @@ Frame :: struct {
|
||||
self.size.height - insets.top - insets.bottom
|
||||
);
|
||||
}
|
||||
|
||||
expand :: (self: Frame, amount: f32) -> Frame {
|
||||
Frame.make(
|
||||
self.origin.x - amount,
|
||||
self.origin.y - amount,
|
||||
self.size.width + amount * 2.0,
|
||||
self.size.height + amount * 2.0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
EdgeInsets :: struct {
|
||||
@@ -170,7 +181,9 @@ ALIGN_TOP :: Alignment.{ h = .center, v = .top };
|
||||
ALIGN_TOP_TRAILING :: Alignment.{ h = .trailing, v = .top };
|
||||
ALIGN_LEADING :: Alignment.{ h = .leading, v = .center };
|
||||
ALIGN_TRAILING :: Alignment.{ h = .trailing, v = .center };
|
||||
ALIGN_BOTTOM :: Alignment.{ h = .center, v = .bottom };
|
||||
ALIGN_BOTTOM :: Alignment.{ h = .center, v = .bottom };
|
||||
ALIGN_BOTTOM_LEADING :: Alignment.{ h = .leading, v = .bottom };
|
||||
ALIGN_BOTTOM_TRAILING :: Alignment.{ h = .trailing, v = .bottom };
|
||||
|
||||
// Compute x offset for a child of child_width inside container_width
|
||||
align_h :: (alignment: HAlignment, child_width: f32, container_width: f32) -> f32 {
|
||||
@@ -189,3 +202,19 @@ align_v :: (alignment: VAlignment, child_height: f32, container_height: f32) ->
|
||||
case .bottom: container_height - child_height;
|
||||
}
|
||||
}
|
||||
|
||||
// --- Lerpable implementations ---
|
||||
|
||||
#import "ui/animation.sx";
|
||||
|
||||
impl Lerpable for Point {
|
||||
lerp :: (self: Point, b: Point, t: f32) -> Point {
|
||||
Point.{ x = self.x + (b.x - self.x) * t, y = self.y + (b.y - self.y) * t };
|
||||
}
|
||||
}
|
||||
|
||||
impl Lerpable for Size {
|
||||
lerp :: (self: Size, b: Size, t: f32) -> Size {
|
||||
Size.{ width = self.width + (b.width - self.width) * t, height = self.height + (b.height - self.height) * t };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user