Draft Editor API and TextEditor widget

This commit is contained in:
Héctor Ramón Jiménez 2023-09-12 14:51:00 +02:00
parent 346af3f8b0
commit 6448429103
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
25 changed files with 1384 additions and 92 deletions

View file

@ -17,6 +17,7 @@ use crate::rule;
use crate::scrollable;
use crate::slider;
use crate::svg;
use crate::text_editor;
use crate::text_input;
use crate::toggler;
@ -1174,3 +1175,115 @@ impl text_input::StyleSheet for Theme {
self.placeholder_color(style)
}
}
/// The style of a text input.
#[derive(Default)]
pub enum TextEditor {
/// The default style.
#[default]
Default,
/// A custom style.
Custom(Box<dyn text_editor::StyleSheet<Style = Theme>>),
}
impl text_editor::StyleSheet for Theme {
type Style = TextEditor;
fn active(&self, style: &Self::Style) -> text_editor::Appearance {
if let TextEditor::Custom(custom) = style {
return custom.active(self);
}
let palette = self.extended_palette();
text_editor::Appearance {
background: palette.background.base.color.into(),
border_radius: 2.0.into(),
border_width: 1.0,
border_color: palette.background.strong.color,
}
}
fn hovered(&self, style: &Self::Style) -> text_editor::Appearance {
if let TextEditor::Custom(custom) = style {
return custom.hovered(self);
}
let palette = self.extended_palette();
text_editor::Appearance {
background: palette.background.base.color.into(),
border_radius: 2.0.into(),
border_width: 1.0,
border_color: palette.background.base.text,
}
}
fn focused(&self, style: &Self::Style) -> text_editor::Appearance {
if let TextEditor::Custom(custom) = style {
return custom.focused(self);
}
let palette = self.extended_palette();
text_editor::Appearance {
background: palette.background.base.color.into(),
border_radius: 2.0.into(),
border_width: 1.0,
border_color: palette.primary.strong.color,
}
}
fn placeholder_color(&self, style: &Self::Style) -> Color {
if let TextEditor::Custom(custom) = style {
return custom.placeholder_color(self);
}
let palette = self.extended_palette();
palette.background.strong.color
}
fn value_color(&self, style: &Self::Style) -> Color {
if let TextEditor::Custom(custom) = style {
return custom.value_color(self);
}
let palette = self.extended_palette();
palette.background.base.text
}
fn selection_color(&self, style: &Self::Style) -> Color {
if let TextEditor::Custom(custom) = style {
return custom.selection_color(self);
}
let palette = self.extended_palette();
palette.primary.weak.color
}
fn disabled(&self, style: &Self::Style) -> text_editor::Appearance {
if let TextEditor::Custom(custom) = style {
return custom.disabled(self);
}
let palette = self.extended_palette();
text_editor::Appearance {
background: palette.background.weak.color.into(),
border_radius: 2.0.into(),
border_width: 1.0,
border_color: palette.background.strong.color,
}
}
fn disabled_color(&self, style: &Self::Style) -> Color {
if let TextEditor::Custom(custom) = style {
return custom.disabled_color(self);
}
self.placeholder_color(style)
}
}