use std::ops::Deref;
use super::{Feature, FrameStyle, MarginStyle, TextClass};
use crate::autoimpl;
use crate::dir::Directional;
use crate::geom::{Rect, Size};
use crate::layout::{AlignPair, AxisInfo, FrameRules, Margins, SizeRules};
use crate::text::TextApi;
#[allow(unused)] use crate::text::TextApiExt;
#[allow(unused)]
use crate::{event::ConfigMgr, layout::Stretch, theme::DrawMgr};
pub struct SizeMgr<'a>(&'a dyn ThemeSize);
impl<'a> SizeMgr<'a> {
#[cfg_attr(not(feature = "internal_doc"), doc(hidden))]
#[cfg_attr(doc_cfg, doc(cfg(internal_doc)))]
pub fn new(h: &'a dyn ThemeSize) -> Self {
SizeMgr(h)
}
#[inline(always)]
pub fn re<'b>(&'b self) -> SizeMgr<'b>
where
'a: 'b,
{
SizeMgr(self.0)
}
pub fn scale_factor(&self) -> f32 {
self.0.scale_factor()
}
pub fn dpem(&self) -> f32 {
self.0.dpem()
}
pub fn min_scroll_size(&self, axis: impl Directional) -> i32 {
self.0.min_scroll_size(axis.is_vertical())
}
pub fn handle_len(&self) -> i32 {
self.0.handle_len()
}
pub fn scroll_bar_width(&self) -> i32 {
self.0.scroll_bar_width()
}
pub fn margins(&self, style: MarginStyle) -> Margins {
self.0.margins(style)
}
pub fn inner_margins(&self) -> Margins {
self.0.margins(MarginStyle::Inner)
}
pub fn tiny_margins(&self) -> Margins {
self.0.margins(MarginStyle::Tiny)
}
pub fn small_margins(&self) -> Margins {
self.0.margins(MarginStyle::Small)
}
pub fn large_margins(&self) -> Margins {
self.0.margins(MarginStyle::Large)
}
pub fn text_margins(&self) -> Margins {
self.0.margins(MarginStyle::Text)
}
pub fn feature(&self, feature: Feature, axis: impl Directional) -> SizeRules {
self.0.feature(feature, axis.is_vertical())
}
pub fn frame(&self, style: FrameStyle, axis: impl Directional) -> FrameRules {
self.0.frame(style, axis.is_vertical())
}
pub fn line_height(&self, class: TextClass) -> i32 {
self.0.line_height(class)
}
pub fn text_rules(
&self,
text: &mut dyn TextApi,
class: TextClass,
axis: AxisInfo,
) -> SizeRules {
self.0.text_rules(text, class, axis)
}
}
#[cfg_attr(not(feature = "internal_doc"), doc(hidden))]
#[cfg_attr(doc_cfg, doc(cfg(internal_doc)))]
#[autoimpl(for<S: trait + ?Sized, R: Deref<Target = S>> R)]
pub trait ThemeSize {
fn scale_factor(&self) -> f32;
fn dpem(&self) -> f32;
fn min_scroll_size(&self, axis_is_vertical: bool) -> i32;
fn handle_len(&self) -> i32;
fn scroll_bar_width(&self) -> i32;
fn margins(&self, style: MarginStyle) -> Margins;
fn feature(&self, feature: Feature, axis_is_vertical: bool) -> SizeRules;
fn align_feature(&self, feature: Feature, rect: Rect, align: AlignPair) -> Rect;
fn frame(&self, style: FrameStyle, axis_is_vertical: bool) -> FrameRules;
fn line_height(&self, class: TextClass) -> i32;
fn text_rules(&self, text: &mut dyn TextApi, class: TextClass, axis: AxisInfo) -> SizeRules;
fn text_set_size(
&self,
text: &mut dyn TextApi,
class: TextClass,
size: Size,
align: Option<AlignPair>,
);
}