Skip to content

Commit d3d3cec

Browse files
edfloreshzjackpot51
authored andcommitted
fix: set style and padding to text editor
1 parent a8fceb4 commit d3d3cec

File tree

1 file changed

+69
-5
lines changed

1 file changed

+69
-5
lines changed

src/tab.rs

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,7 @@ impl Item {
13131313
}
13141314

13151315
fn preview<'a>(&'a self, sizes: IconSizes) -> Element<'a, app::Message> {
1316+
let spacing = cosmic::theme::active().cosmic().spacing;
13161317
// This loads the image only if thumbnailing worked
13171318
let icon = widget::icon::icon(self.icon_handle_grid.clone())
13181319
.content_fit(ContentFit::Contain)
@@ -1333,10 +1334,16 @@ impl Item {
13331334
widget::image(handle.clone()).into()
13341335
}
13351336
ItemThumbnail::Svg(handle) => widget::svg(handle.clone()).into(),
1336-
ItemThumbnail::Text(content) => widget::container(widget::text_editor(content))
1337-
.width(Length::Fixed(THUMBNAIL_SIZE as f32))
1338-
.height(Length::Fixed(THUMBNAIL_SIZE as f32))
1339-
.into(),
1337+
ItemThumbnail::Text(content) => widget::container(
1338+
widget::text_editor(content)
1339+
.class(cosmic::theme::iced::TextEditor::Custom(Box::new(
1340+
text_editor_class,
1341+
)))
1342+
.padding(spacing.space_xxs),
1343+
)
1344+
.width(Length::Fixed(THUMBNAIL_SIZE as f32))
1345+
.height(Length::Fixed(THUMBNAIL_SIZE as f32))
1346+
.into(),
13401347
}
13411348
}
13421349

@@ -3101,7 +3108,14 @@ impl Tab {
31013108
);
31023109
}
31033110
ItemThumbnail::Text(text) => {
3104-
element_opt = Some(widget::text_editor(text).into())
3111+
element_opt = Some(
3112+
widget::text_editor(text)
3113+
.padding(space_xxs)
3114+
.class(cosmic::theme::iced::TextEditor::Custom(Box::new(
3115+
text_editor_class,
3116+
)))
3117+
.into(),
3118+
)
31053119
}
31063120
}
31073121
}
@@ -4990,3 +5004,53 @@ impl<Message: 'static> From<ArcElementWrapper<Message>> for Element<'static, Mes
49905004
Element::new(wrapper)
49915005
}
49925006
}
5007+
5008+
fn text_editor_class(
5009+
theme: &cosmic::Theme,
5010+
status: cosmic::widget::text_editor::Status,
5011+
) -> cosmic::iced_widget::text_editor::Style {
5012+
let cosmic = theme.cosmic();
5013+
let container = theme.current_container();
5014+
5015+
let mut background: cosmic::iced::Color = container.component.base.into();
5016+
background.a = 0.25;
5017+
let selection = cosmic.accent.base.into();
5018+
let value = cosmic.palette.neutral_9.into();
5019+
let mut placeholder = cosmic.palette.neutral_9;
5020+
placeholder.alpha = 0.7;
5021+
let placeholder = placeholder.into();
5022+
let icon = cosmic.background.on.into();
5023+
5024+
match status {
5025+
cosmic::iced_widget::text_editor::Status::Active
5026+
| cosmic::iced_widget::text_editor::Status::Disabled => {
5027+
cosmic::iced_widget::text_editor::Style {
5028+
background: background.into(),
5029+
border: cosmic::iced::Border {
5030+
radius: cosmic.corner_radii.radius_m.into(),
5031+
width: 2.0,
5032+
color: container.component.divider.into(),
5033+
},
5034+
icon,
5035+
placeholder,
5036+
value,
5037+
selection,
5038+
}
5039+
}
5040+
cosmic::iced_widget::text_editor::Status::Hovered
5041+
| cosmic::iced_widget::text_editor::Status::Focused => {
5042+
cosmic::iced_widget::text_editor::Style {
5043+
background: background.into(),
5044+
border: cosmic::iced::Border {
5045+
radius: cosmic.corner_radii.radius_m.into(),
5046+
width: 2.0,
5047+
color: cosmic::iced::Color::from(cosmic.accent.base),
5048+
},
5049+
icon,
5050+
placeholder,
5051+
value,
5052+
selection,
5053+
}
5054+
}
5055+
}
5056+
}

0 commit comments

Comments
 (0)