#![allow(deprecated)]
use waft_embedder::Color;
use waft_foundation::App;
use waft_painting::EdgeInsetsGeometry;
use waft_widgets::{BuildContext, WidgetState, WidgetStateProperty};
use crate::ink_well::InteractiveInkFeatureFactoryRef;
use crate::tab_bar_theme::{TabBarThemeData, TabBarThemeDataGetters};
use crate::tabs::{TabAlignment, TabBarIndicatorSize};
use crate::theme_data_getters::DefaultsContext;
use waft_painting::AnyColor;
use waft_painting::TextStyle;
use waft_widgets::WidgetStatePropertyRef;
pub(crate) struct TabsPrimaryDefaultsM3 {
tab_bar_theme_data: TabBarThemeData,
context: DefaultsContext,
is_scrollable: bool,
}
impl TabsPrimaryDefaultsM3 {
pub(crate) fn new(context: BuildContext, is_scrollable: bool) -> TabsPrimaryDefaultsM3 {
TabsPrimaryDefaultsM3 {
tab_bar_theme_data: TabBarThemeData::new().indicator_size(TabBarIndicatorSize::Label),
context: DefaultsContext::new(context),
is_scrollable,
}
}
pub(crate) fn indicator_weight(indicator_size: TabBarIndicatorSize) -> f64 {
match indicator_size {
TabBarIndicatorSize::Label => 3.0,
TabBarIndicatorSize::Tab => 2.0,
}
}
pub(crate) const ICON_MARGIN: EdgeInsetsGeometry = EdgeInsetsGeometry::only(0.0, 0.0, 0.0, 2.0);
}
impl TabBarThemeDataGetters for TabsPrimaryDefaultsM3 {
fn tab_bar_theme_data(&self) -> &TabBarThemeData {
&self.tab_bar_theme_data
}
fn divider_color(&self, app: &mut App) -> Option<Color> {
let theme = self.context.theme(app);
let colors = theme.color_scheme.clone();
Some(colors.outline_variant())
}
fn divider_height(&self, _app: &mut App) -> Option<f64> {
Some(1.0)
}
fn indicator_color(&self, app: &mut App) -> Option<Color> {
let theme = self.context.theme(app);
let colors = theme.color_scheme.clone();
Some(colors.primary)
}
fn label_color(&self, app: &mut App) -> Option<AnyColor> {
let theme = self.context.theme(app);
let colors = theme.color_scheme.clone();
Some(colors.primary.into())
}
fn unselected_label_color(&self, app: &mut App) -> Option<Color> {
let theme = self.context.theme(app);
let colors = theme.color_scheme.clone();
Some(colors.on_surface_variant())
}
fn overlay_color(&self, app: &mut App) -> Option<WidgetStatePropertyRef<Option<Color>>> {
let theme = self.context.theme(app);
let colors = theme.color_scheme.clone();
let overlay_colors = colors.clone();
Some(<dyn WidgetStateProperty<Option<Color>>>::resolve_with(
move |states| {
let colors = &overlay_colors;
if states.contains(&WidgetState::Selected) {
if states.contains(&WidgetState::Pressed) {
return Some(colors.primary.with_opacity(0.1));
}
if states.contains(&WidgetState::Hovered) {
return Some(colors.primary.with_opacity(0.08));
}
if states.contains(&WidgetState::Focused) {
return Some(colors.primary.with_opacity(0.1));
}
return None;
}
if states.contains(&WidgetState::Pressed) {
return Some(colors.primary.with_opacity(0.1));
}
if states.contains(&WidgetState::Hovered) {
return Some(colors.on_surface.with_opacity(0.08));
}
if states.contains(&WidgetState::Focused) {
return Some(colors.on_surface.with_opacity(0.1));
}
None
},
))
}
fn splash_factory(&self, app: &mut App) -> Option<InteractiveInkFeatureFactoryRef> {
let theme = self.context.theme(app);
Some(theme.splash_factory.clone())
}
fn tab_alignment(&self, _app: &mut App) -> Option<TabAlignment> {
Some(if self.is_scrollable {
TabAlignment::StartOffset
} else {
TabAlignment::Fill
})
}
fn label_style(&self, app: &mut App) -> Option<TextStyle> {
self.context.text_theme(app).title_small.clone()
}
fn unselected_label_style(&self, app: &mut App) -> Option<TextStyle> {
self.context.text_theme(app).title_small.clone()
}
}
pub(crate) struct TabsSecondaryDefaultsM3 {
tab_bar_theme_data: TabBarThemeData,
context: DefaultsContext,
is_scrollable: bool,
}
impl TabsSecondaryDefaultsM3 {
pub(crate) fn new(context: BuildContext, is_scrollable: bool) -> TabsSecondaryDefaultsM3 {
TabsSecondaryDefaultsM3 {
tab_bar_theme_data: TabBarThemeData::new().indicator_size(TabBarIndicatorSize::Tab),
context: DefaultsContext::new(context),
is_scrollable,
}
}
pub(crate) const INDICATOR_WEIGHT: f64 = 2.0;
}
impl TabBarThemeDataGetters for TabsSecondaryDefaultsM3 {
fn tab_bar_theme_data(&self) -> &TabBarThemeData {
&self.tab_bar_theme_data
}
fn divider_color(&self, app: &mut App) -> Option<Color> {
let theme = self.context.theme(app);
let colors = theme.color_scheme.clone();
Some(colors.outline_variant())
}
fn divider_height(&self, _app: &mut App) -> Option<f64> {
Some(1.0)
}
fn indicator_color(&self, app: &mut App) -> Option<Color> {
let theme = self.context.theme(app);
let colors = theme.color_scheme.clone();
Some(colors.primary)
}
fn label_color(&self, app: &mut App) -> Option<AnyColor> {
let theme = self.context.theme(app);
let colors = theme.color_scheme.clone();
Some(colors.on_surface.into())
}
fn unselected_label_color(&self, app: &mut App) -> Option<Color> {
let theme = self.context.theme(app);
let colors = theme.color_scheme.clone();
Some(colors.on_surface_variant())
}
fn overlay_color(&self, app: &mut App) -> Option<WidgetStatePropertyRef<Option<Color>>> {
let theme = self.context.theme(app);
let colors = theme.color_scheme.clone();
let overlay_colors = colors.clone();
Some(<dyn WidgetStateProperty<Option<Color>>>::resolve_with(
move |states| {
let colors = &overlay_colors;
if states.contains(&WidgetState::Selected) {
if states.contains(&WidgetState::Pressed) {
return Some(colors.on_surface.with_opacity(0.1));
}
if states.contains(&WidgetState::Hovered) {
return Some(colors.on_surface.with_opacity(0.08));
}
if states.contains(&WidgetState::Focused) {
return Some(colors.on_surface.with_opacity(0.1));
}
return None;
}
if states.contains(&WidgetState::Pressed) {
return Some(colors.on_surface.with_opacity(0.1));
}
if states.contains(&WidgetState::Hovered) {
return Some(colors.on_surface.with_opacity(0.08));
}
if states.contains(&WidgetState::Focused) {
return Some(colors.on_surface.with_opacity(0.1));
}
None
},
))
}
fn splash_factory(&self, app: &mut App) -> Option<InteractiveInkFeatureFactoryRef> {
let theme = self.context.theme(app);
Some(theme.splash_factory.clone())
}
fn tab_alignment(&self, _app: &mut App) -> Option<TabAlignment> {
Some(if self.is_scrollable {
TabAlignment::StartOffset
} else {
TabAlignment::Fill
})
}
fn label_style(&self, app: &mut App) -> Option<TextStyle> {
self.context.text_theme(app).title_small.clone()
}
fn unselected_label_style(&self, app: &mut App) -> Option<TextStyle> {
self.context.text_theme(app).title_small.clone()
}
}