Simplify theming for TextEditor widget
This commit is contained in:
parent
69bc1df252
commit
68c8f23f02
5 changed files with 105 additions and 185 deletions
|
|
@ -8,7 +8,6 @@ use crate::core::widget::text;
|
|||
use crate::menu;
|
||||
use crate::pane_grid;
|
||||
use crate::pick_list;
|
||||
use crate::text_editor;
|
||||
|
||||
use crate::core::{Background, Border, Color};
|
||||
|
||||
|
|
@ -440,123 +439,3 @@ impl pane_grid::StyleSheet for Theme {
|
|||
}
|
||||
|
||||
impl text::StyleSheet for Theme {}
|
||||
|
||||
/// 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: Border {
|
||||
radius: 2.0.into(),
|
||||
width: 1.0,
|
||||
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: Border {
|
||||
radius: 2.0.into(),
|
||||
width: 1.0,
|
||||
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: Border {
|
||||
radius: 2.0.into(),
|
||||
width: 1.0,
|
||||
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: Border {
|
||||
radius: 2.0.into(),
|
||||
width: 1.0,
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue