use bevy::{prelude::*, text::LineHeight};
use crate::Scrollbar;
#[derive(Component, Clone, Reflect, Debug)]
#[relationship_target(relationship = Scrollbar, linked_spawn)]
#[require(Node, ScrollSpeed)]
pub struct Scrollable {
scrollbar: Entity,
}
impl Scrollable {
pub fn scrollbar(&self) -> Entity {
self.scrollbar
}
}
#[derive(Component, Copy, Clone, Reflect, Debug)]
pub struct ScrollSpeed(pub f32);
impl Default for ScrollSpeed {
fn default() -> Self {
Self(Self::DEFAULT)
}
}
impl ScrollSpeed {
pub const DEFAULT: f32 = 1.0;
}
#[derive(Component, Copy, Clone, Reflect, Debug)]
pub struct ScrollableLineHeight {
pub font_size: f32,
pub line_height: LineHeight,
}
impl Default for ScrollableLineHeight {
fn default() -> Self {
Self {
font_size: TextFont::default().font_size,
line_height: LineHeight::default(),
}
}
}
impl ScrollableLineHeight {
pub(super) fn px(&self) -> f32 {
match self.line_height {
LineHeight::Px(px) => px,
LineHeight::RelativeToFont(scale) => scale * self.font_size,
}
}
}