use crate::align::{AlignX, AlignY};
use crate::id::Id;
use crate::{color::Color, Vector2, engine};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[repr(u8)]
pub enum PointerCaptureMode {
#[default]
Capture,
Passthrough,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[repr(u8)]
pub enum FloatingAttachToElement {
#[default]
None,
Parent,
ElementWithId,
Root,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[repr(u8)]
pub enum FloatingClipToElement {
#[default]
None,
AttachedParent,
}
pub struct FloatingBuilder {
pub(crate) config: engine::FloatingConfig,
}
impl FloatingBuilder {
#[inline]
pub fn offset(&mut self, x: f32, y: f32) -> &mut Self {
self.config.offset = Vector2::new(x, y);
self
}
#[inline]
pub fn z_index(&mut self, z_index: i16) -> &mut Self {
self.config.z_index = z_index;
self
}
#[inline]
pub fn anchor(
&mut self,
element: (AlignX, AlignY),
parent: (AlignX, AlignY),
) -> &mut Self {
self.config.attach_points.element_x = element.0;
self.config.attach_points.element_y = element.1;
self.config.attach_points.parent_x = parent.0;
self.config.attach_points.parent_y = parent.1;
self
}
#[inline]
pub fn attach_parent(&mut self) -> &mut Self {
self.config.attach_to = FloatingAttachToElement::Parent;
self
}
#[inline]
pub fn attach_root(&mut self) -> &mut Self {
self.config.attach_to = FloatingAttachToElement::Root;
self
}
#[inline]
pub fn attach_id(&mut self, id: impl Into<Id>) -> &mut Self {
self.config.attach_to = FloatingAttachToElement::ElementWithId;
self.config.parent_id = id.into().id;
self
}
#[inline]
pub fn clip_by_parent(&mut self) -> &mut Self {
self.config.clip_to = FloatingClipToElement::AttachedParent;
self
}
#[inline]
pub fn passthrough(&mut self) -> &mut Self {
self.config.pointer_capture_mode = PointerCaptureMode::Passthrough;
self
}
}
pub struct OverflowBuilder {
pub(crate) config: engine::ClipConfig,
}
impl OverflowBuilder {
#[inline]
pub fn clip_x(&mut self) -> &mut Self {
self.config.horizontal = true;
self
}
#[inline]
pub fn clip_y(&mut self) -> &mut Self {
self.config.vertical = true;
self
}
#[inline]
pub fn clip(&mut self) -> &mut Self {
self.config.horizontal = true;
self.config.vertical = true;
self
}
#[inline]
pub fn scroll_x(&mut self) -> &mut Self {
self.config.horizontal = true;
self.config.scroll_x = true;
self
}
#[inline]
pub fn scroll_y(&mut self) -> &mut Self {
self.config.vertical = true;
self.config.scroll_y = true;
self
}
#[inline]
pub fn scroll(&mut self) -> &mut Self {
self.config.horizontal = true;
self.config.vertical = true;
self.config.scroll_x = true;
self.config.scroll_y = true;
self
}
}
pub struct BorderBuilder {
pub(crate) config: engine::BorderConfig,
}
#[derive(Debug, Clone, Copy, Default)]
pub enum BorderPosition {
#[default]
Outside,
Middle,
Inside,
}
impl BorderBuilder {
#[inline]
pub fn color(&mut self, color: impl Into<Color>) -> &mut Self {
self.config.color = color.into();
self
}
#[inline]
pub fn all(&mut self, width: u16) -> &mut Self {
self.config.width.left = width;
self.config.width.right = width;
self.config.width.top = width;
self.config.width.bottom = width;
self
}
#[inline]
pub fn left(&mut self, width: u16) -> &mut Self {
self.config.width.left = width;
self
}
#[inline]
pub fn right(&mut self, width: u16) -> &mut Self {
self.config.width.right = width;
self
}
#[inline]
pub fn top(&mut self, width: u16) -> &mut Self {
self.config.width.top = width;
self
}
#[inline]
pub fn bottom(&mut self, width: u16) -> &mut Self {
self.config.width.bottom = width;
self
}
#[inline]
pub fn between_children(&mut self, width: u16) -> &mut Self {
self.config.width.between_children = width;
self
}
#[inline]
pub fn position(&mut self, position: BorderPosition) -> &mut Self {
self.config.position = position;
self
}
}
pub struct VisualRotationBuilder {
pub(crate) config: engine::VisualRotationConfig,
}
impl VisualRotationBuilder {
#[inline]
pub fn degrees(&mut self, degrees: f32) -> &mut Self {
self.config.rotation_radians = degrees.to_radians();
self
}
#[inline]
pub fn radians(&mut self, radians: f32) -> &mut Self {
self.config.rotation_radians = radians;
self
}
#[inline]
pub fn pivot(&mut self, x: f32, y: f32) -> &mut Self {
self.config.pivot_x = x;
self.config.pivot_y = y;
self
}
#[inline]
pub fn flip_x(&mut self) -> &mut Self {
self.config.flip_x = true;
self
}
#[inline]
pub fn flip_y(&mut self) -> &mut Self {
self.config.flip_y = true;
self
}
}
pub struct ShapeRotationBuilder {
pub(crate) config: engine::ShapeRotationConfig,
}
impl ShapeRotationBuilder {
#[inline]
pub fn degrees(&mut self, degrees: f32) -> &mut Self {
self.config.rotation_radians = degrees.to_radians();
self
}
#[inline]
pub fn radians(&mut self, radians: f32) -> &mut Self {
self.config.rotation_radians = radians;
self
}
#[inline]
pub fn flip_x(&mut self) -> &mut Self {
self.config.flip_x = true;
self
}
#[inline]
pub fn flip_y(&mut self) -> &mut Self {
self.config.flip_y = true;
self
}
}