#[doc(inline)]
#[allow(unused_imports)]
use super::cellgrid::CellGrid;
#[doc(inline)]
#[allow(unused_imports)]
use iced_widget::TextEditor;
#[doc(inline)]
#[allow(unused_imports)]
use iced_widget::TextInput;
use super::types::PropertyMinimal;
use crate::core::{Border, Color, Theme, border::Radius};
use iced_widget::{text_editor, text_input};
pub trait TextInputCatalog: text_input::Catalog {
fn no_border<'a>() -> <Self as text_input::Catalog>::Class<'a>;
}
impl TextInputCatalog for Theme {
fn no_border<'a>() -> <Self as text_input::Catalog>::Class<'a> {
Box::new(text_input_no_border)
}
}
pub fn text_input_no_border(theme: &Theme, status: text_input::Status) -> text_input::Style {
let base = text_input::default(theme, status);
text_input::Style {
border: Border {
color: Color::TRANSPARENT,
width: 0.0,
radius: Radius::new(0.0),
},
..base
}
}
pub trait TextEditorCatalog: text_editor::Catalog {
fn no_border<'a>() -> <Self as text_editor::Catalog>::Class<'a>;
}
impl TextEditorCatalog for Theme {
fn no_border<'a>() -> <Self as text_editor::Catalog>::Class<'a> {
Box::new(text_editor_no_border)
}
}
pub fn text_editor_no_border(theme: &Theme, status: text_editor::Status) -> text_editor::Style {
let base = text_editor::default(theme, status);
text_editor::Style {
border: Border {
color: Color::TRANSPARENT,
width: 0.0,
radius: Radius::new(0.0),
},
..base
}
}
pub fn page_breaks_simple(page: f32, visible_size: f32) -> Vec<f32> {
page_breaks_simple_with_header(page, visible_size, 0.0)
}
pub fn page_breaks_shift(page: f32, properties: &Vec<PropertyMinimal>) -> Vec<f32> {
page_breaks_shift_with_header(page, properties, 0.0)
}
pub fn page_breaks_simple_with_header(page: f32, visible_size: f32, header: f32) -> Vec<f32> {
let actual = page - header.min(page);
let mut breaks = Vec::new();
let count = (visible_size / actual).floor();
let mut i = 1.0;
while i <= count {
breaks.push(i * actual);
i += 1.0;
}
breaks.shrink_to(breaks.len());
breaks
}
pub fn page_breaks_shift_with_header(
page: f32,
properties: &Vec<PropertyMinimal>,
header: f32,
) -> Vec<f32> {
let actual = page - header.min(page);
let mut breaks = Vec::new();
let mut current = 0.0;
let mut last = 0.0;
for property in properties {
if !property.hidden {
let old = current;
current += property.size;
if current > actual {
last += old;
breaks.push(last);
current -= old;
while current > actual {
last += actual;
breaks.push(last);
current -= actual;
}
}
}
}
breaks.shrink_to(breaks.len());
breaks
}