improv(icon): default to ContentFit::ScaleDown
This commit is contained in:
parent
18a21937b4
commit
8fc3d4f0c1
1 changed files with 17 additions and 30 deletions
|
|
@ -168,8 +168,7 @@ pub struct Icon<'a> {
|
||||||
theme: Option<Cow<'a, str>>,
|
theme: Option<Cow<'a, str>>,
|
||||||
style: crate::theme::Svg,
|
style: crate::theme::Svg,
|
||||||
size: u16,
|
size: u16,
|
||||||
#[setters(strip_option)]
|
content_fit: ContentFit,
|
||||||
content_fit: Option<ContentFit>,
|
|
||||||
#[setters(strip_option)]
|
#[setters(strip_option)]
|
||||||
width: Option<Length>,
|
width: Option<Length>,
|
||||||
#[setters(strip_option)]
|
#[setters(strip_option)]
|
||||||
|
|
@ -181,7 +180,7 @@ pub struct Icon<'a> {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn icon<'a>(source: impl Into<IconSource<'a>>, size: u16) -> Icon<'a> {
|
pub fn icon<'a>(source: impl Into<IconSource<'a>>, size: u16) -> Icon<'a> {
|
||||||
Icon {
|
Icon {
|
||||||
content_fit: None,
|
content_fit: ContentFit::ScaleDown,
|
||||||
height: None,
|
height: None,
|
||||||
source: source.into(),
|
source: source.into(),
|
||||||
size,
|
size,
|
||||||
|
|
@ -196,13 +195,11 @@ impl<'a> Icon<'a> {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn into_element<Message: 'static>(self) -> Element<'a, Message> {
|
fn into_element<Message: 'static>(self) -> Element<'a, Message> {
|
||||||
if let IconSource::Embedded(image) = self.source {
|
if let IconSource::Embedded(image) = self.source {
|
||||||
let mut image = iced::widget::image(image)
|
return iced::widget::image(image)
|
||||||
.width(self.width.unwrap_or(Length::Units(self.size)))
|
.width(self.width.unwrap_or(Length::Units(self.size)))
|
||||||
.height(self.height.unwrap_or(Length::Units(self.size)));
|
.height(self.height.unwrap_or(Length::Units(self.size)))
|
||||||
if let Some(content_fit) = self.content_fit {
|
.content_fit(self.content_fit)
|
||||||
image = image.content_fit(content_fit);
|
.into();
|
||||||
}
|
|
||||||
return image.into();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut hasher = DefaultHasher::new();
|
let mut hasher = DefaultHasher::new();
|
||||||
|
|
@ -219,27 +216,17 @@ impl<'a> Icon<'a> {
|
||||||
.source
|
.source
|
||||||
.load(self.size, self.theme.as_deref(), self.force_svg)
|
.load(self.size, self.theme.as_deref(), self.force_svg)
|
||||||
{
|
{
|
||||||
Handle::Svg(handle) => {
|
Handle::Svg(handle) => svg::Svg::<Renderer>::new(handle)
|
||||||
let mut widget = svg::Svg::<Renderer>::new(handle)
|
.style(self.style)
|
||||||
.style(self.style)
|
.width(self.width.unwrap_or(Length::Units(self.size)))
|
||||||
.width(self.width.unwrap_or(Length::Units(self.size)))
|
.height(self.height.unwrap_or(Length::Units(self.size)))
|
||||||
.height(self.height.unwrap_or(Length::Units(self.size)));
|
.content_fit(self.content_fit)
|
||||||
|
.into(),
|
||||||
if let Some(content_fit) = self.content_fit {
|
Handle::Image(handle) => Image::new(handle)
|
||||||
widget = widget.content_fit(content_fit);
|
.width(self.width.unwrap_or(Length::Units(self.size)))
|
||||||
}
|
.height(self.height.unwrap_or(Length::Units(self.size)))
|
||||||
|
.content_fit(self.content_fit)
|
||||||
widget.into()
|
.into(),
|
||||||
}
|
|
||||||
Handle::Image(handle) => {
|
|
||||||
let mut image = Image::new(handle)
|
|
||||||
.width(self.width.unwrap_or(Length::Units(self.size)))
|
|
||||||
.height(self.height.unwrap_or(Length::Units(self.size)));
|
|
||||||
if let Some(content_fit) = self.content_fit {
|
|
||||||
image = image.content_fit(content_fit);
|
|
||||||
}
|
|
||||||
image.into()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.into()
|
.into()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue