Merge branch 'master' into virtual-widgets
This commit is contained in:
commit
c35496d80f
58 changed files with 446 additions and 909 deletions
|
|
@ -8,12 +8,10 @@ use crate::overlay;
|
|||
use crate::renderer;
|
||||
use crate::touch;
|
||||
use crate::{
|
||||
Background, Clipboard, Color, Element, Hasher, Layout, Length, Padding,
|
||||
Point, Rectangle, Shell, Vector, Widget,
|
||||
Background, Clipboard, Color, Element, Layout, Length, Padding, Point,
|
||||
Rectangle, Shell, Vector, Widget,
|
||||
};
|
||||
|
||||
use std::hash::Hash;
|
||||
|
||||
pub use iced_style::button::{Style, StyleSheet};
|
||||
|
||||
/// A generic widget that produces a message when pressed.
|
||||
|
|
@ -384,16 +382,6 @@ where
|
|||
);
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
struct Marker;
|
||||
std::any::TypeId::of::<Marker>().hash(state);
|
||||
|
||||
self.width.hash(state);
|
||||
self.height.hash(state);
|
||||
self.padding.hash(state);
|
||||
self.content.hash_layout(state);
|
||||
}
|
||||
|
||||
fn overlay(
|
||||
&mut self,
|
||||
layout: Layout<'_>,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
//! Show toggle controls using checkboxes.
|
||||
use std::hash::Hash;
|
||||
|
||||
use crate::alignment;
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
|
|
@ -10,8 +8,8 @@ use crate::text;
|
|||
use crate::touch;
|
||||
use crate::widget::{self, Row, Text};
|
||||
use crate::{
|
||||
Alignment, Clipboard, Element, Hasher, Layout, Length, Point, Rectangle,
|
||||
Shell, Widget,
|
||||
Alignment, Clipboard, Element, Layout, Length, Point, Rectangle, Shell,
|
||||
Widget,
|
||||
};
|
||||
|
||||
pub use iced_style::checkbox::{Style, StyleSheet};
|
||||
|
|
@ -262,13 +260,6 @@ where
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
struct Marker;
|
||||
std::any::TypeId::of::<Marker>().hash(state);
|
||||
|
||||
self.label.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> From<Checkbox<'a, Message, Renderer>>
|
||||
|
|
|
|||
|
|
@ -1,14 +1,12 @@
|
|||
//! Distribute content vertically.
|
||||
use std::hash::Hash;
|
||||
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
use crate::mouse;
|
||||
use crate::overlay;
|
||||
use crate::renderer;
|
||||
use crate::{
|
||||
Alignment, Clipboard, Element, Hasher, Layout, Length, Padding, Point,
|
||||
Rectangle, Shell, Widget,
|
||||
Alignment, Clipboard, Element, Layout, Length, Padding, Point, Rectangle,
|
||||
Shell, Widget,
|
||||
};
|
||||
|
||||
use std::u32;
|
||||
|
|
@ -199,23 +197,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
struct Marker;
|
||||
std::any::TypeId::of::<Marker>().hash(state);
|
||||
|
||||
self.width.hash(state);
|
||||
self.height.hash(state);
|
||||
self.max_width.hash(state);
|
||||
self.max_height.hash(state);
|
||||
self.align_items.hash(state);
|
||||
self.spacing.hash(state);
|
||||
self.padding.hash(state);
|
||||
|
||||
for child in &self.children {
|
||||
child.widget.hash_layout(state);
|
||||
}
|
||||
}
|
||||
|
||||
fn overlay(
|
||||
&mut self,
|
||||
layout: Layout<'_>,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
//! Decorate content and apply alignment.
|
||||
use std::hash::Hash;
|
||||
|
||||
use crate::alignment::{self, Alignment};
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
|
|
@ -8,8 +6,8 @@ use crate::mouse;
|
|||
use crate::overlay;
|
||||
use crate::renderer;
|
||||
use crate::{
|
||||
Background, Clipboard, Color, Element, Hasher, Layout, Length, Padding,
|
||||
Point, Rectangle, Shell, Widget,
|
||||
Background, Clipboard, Color, Element, Layout, Length, Padding, Point,
|
||||
Rectangle, Shell, Widget,
|
||||
};
|
||||
|
||||
use std::u32;
|
||||
|
|
@ -233,21 +231,6 @@ where
|
|||
);
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
struct Marker;
|
||||
std::any::TypeId::of::<Marker>().hash(state);
|
||||
|
||||
self.padding.hash(state);
|
||||
self.width.hash(state);
|
||||
self.height.hash(state);
|
||||
self.max_width.hash(state);
|
||||
self.max_height.hash(state);
|
||||
self.horizontal_alignment.hash(state);
|
||||
self.vertical_alignment.hash(state);
|
||||
|
||||
self.content.hash_layout(state);
|
||||
}
|
||||
|
||||
fn overlay(
|
||||
&mut self,
|
||||
layout: Layout<'_>,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,9 @@ pub use viewer::Viewer;
|
|||
use crate::image;
|
||||
use crate::layout;
|
||||
use crate::renderer;
|
||||
use crate::{Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget};
|
||||
use crate::{
|
||||
ContentFit, Element, Layout, Length, Point, Rectangle, Size, Vector, Widget,
|
||||
};
|
||||
|
||||
use std::hash::Hash;
|
||||
|
||||
|
|
@ -26,6 +28,7 @@ pub struct Image<Handle> {
|
|||
handle: Handle,
|
||||
width: Length,
|
||||
height: Length,
|
||||
content_fit: ContentFit,
|
||||
}
|
||||
|
||||
impl<Handle> Image<Handle> {
|
||||
|
|
@ -35,6 +38,7 @@ impl<Handle> Image<Handle> {
|
|||
handle: handle.into(),
|
||||
width: Length::Shrink,
|
||||
height: Length::Shrink,
|
||||
content_fit: ContentFit::Contain,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -49,6 +53,16 @@ impl<Handle> Image<Handle> {
|
|||
self.height = height;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the [`ContentFit`] of the [`Image`].
|
||||
///
|
||||
/// Defaults to [`ContentFit::Contain`]
|
||||
pub fn content_fit(self, content_fit: ContentFit) -> Self {
|
||||
Self {
|
||||
content_fit,
|
||||
..self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Computes the layout of an [`Image`].
|
||||
|
|
@ -58,44 +72,37 @@ pub fn layout<Renderer, Handle>(
|
|||
handle: &Handle,
|
||||
width: Length,
|
||||
height: Length,
|
||||
content_fit: ContentFit,
|
||||
) -> layout::Node
|
||||
where
|
||||
Renderer: image::Renderer<Handle = Handle>,
|
||||
{
|
||||
let (original_width, original_height) = renderer.dimensions(handle);
|
||||
// The raw w/h of the underlying image
|
||||
let image_size = {
|
||||
let (width, height) = renderer.dimensions(handle);
|
||||
|
||||
let mut size = limits
|
||||
.width(width)
|
||||
.height(height)
|
||||
.resolve(Size::new(original_width as f32, original_height as f32));
|
||||
Size::new(width as f32, height as f32)
|
||||
};
|
||||
|
||||
let aspect_ratio = original_width as f32 / original_height as f32;
|
||||
let viewport_aspect_ratio = size.width / size.height;
|
||||
// The size to be available to the widget prior to `Shrink`ing
|
||||
let raw_size = limits.width(width).height(height).resolve(image_size);
|
||||
|
||||
if viewport_aspect_ratio > aspect_ratio {
|
||||
size.width =
|
||||
original_width as f32 * size.height / original_height as f32;
|
||||
} else {
|
||||
size.height =
|
||||
original_height as f32 * size.width / original_width as f32;
|
||||
}
|
||||
// The uncropped size of the image when fit to the bounds above
|
||||
let full_size = content_fit.fit(image_size, raw_size);
|
||||
|
||||
layout::Node::new(size)
|
||||
}
|
||||
// Shrink the widget to fit the resized image, if requested
|
||||
let final_size = Size {
|
||||
width: match width {
|
||||
Length::Shrink => f32::min(raw_size.width, full_size.width),
|
||||
_ => raw_size.width,
|
||||
},
|
||||
height: match height {
|
||||
Length::Shrink => f32::min(raw_size.height, full_size.height),
|
||||
_ => raw_size.height,
|
||||
},
|
||||
};
|
||||
|
||||
/// Hashes the layout attributes of an [`Image`].
|
||||
pub fn hash_layout<Handle: Hash>(
|
||||
state: &mut Hasher,
|
||||
handle: &Handle,
|
||||
width: Length,
|
||||
height: Length,
|
||||
) {
|
||||
struct Marker;
|
||||
std::any::TypeId::of::<Marker>().hash(state);
|
||||
|
||||
handle.hash(state);
|
||||
width.hash(state);
|
||||
height.hash(state);
|
||||
layout::Node::new(final_size)
|
||||
}
|
||||
|
||||
impl<Message, Renderer, Handle> Widget<Message, Renderer> for Image<Handle>
|
||||
|
|
@ -116,7 +123,14 @@ where
|
|||
renderer: &Renderer,
|
||||
limits: &layout::Limits,
|
||||
) -> layout::Node {
|
||||
layout(renderer, limits, &self.handle, self.width, self.height)
|
||||
layout(
|
||||
renderer,
|
||||
limits,
|
||||
&self.handle,
|
||||
self.width,
|
||||
self.height,
|
||||
self.content_fit,
|
||||
)
|
||||
}
|
||||
|
||||
fn draw(
|
||||
|
|
@ -127,11 +141,34 @@ where
|
|||
_cursor_position: Point,
|
||||
_viewport: &Rectangle,
|
||||
) {
|
||||
renderer.draw(self.handle.clone(), layout.bounds());
|
||||
}
|
||||
let (width, height) = renderer.dimensions(&self.handle);
|
||||
let image_size = Size::new(width as f32, height as f32);
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
hash_layout(state, &self.handle, self.width, self.height)
|
||||
let bounds = layout.bounds();
|
||||
let adjusted_fit = self.content_fit.fit(image_size, bounds.size());
|
||||
|
||||
let render = |renderer: &mut Renderer| {
|
||||
let offset = Vector::new(
|
||||
(bounds.width - adjusted_fit.width).max(0.0) / 2.0,
|
||||
(bounds.height - adjusted_fit.height).max(0.0) / 2.0,
|
||||
);
|
||||
|
||||
let drawing_bounds = Rectangle {
|
||||
width: adjusted_fit.width,
|
||||
height: adjusted_fit.height,
|
||||
..bounds
|
||||
};
|
||||
|
||||
renderer.draw(self.handle.clone(), drawing_bounds + offset)
|
||||
};
|
||||
|
||||
if adjusted_fit.width > bounds.width
|
||||
|| adjusted_fit.height > bounds.height
|
||||
{
|
||||
renderer.with_layer(bounds, render);
|
||||
} else {
|
||||
render(renderer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ use crate::layout;
|
|||
use crate::mouse;
|
||||
use crate::renderer;
|
||||
use crate::{
|
||||
Clipboard, Element, Hasher, Layout, Length, Point, Rectangle, Shell, Size,
|
||||
Vector, Widget,
|
||||
Clipboard, Element, Layout, Length, Point, Rectangle, Shell, Size, Vector,
|
||||
Widget,
|
||||
};
|
||||
|
||||
use std::hash::Hash;
|
||||
|
|
@ -335,17 +335,6 @@ where
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
struct Marker;
|
||||
std::any::TypeId::of::<Marker>().hash(state);
|
||||
|
||||
self.width.hash(state);
|
||||
self.height.hash(state);
|
||||
self.padding.hash(state);
|
||||
|
||||
self.handle.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
/// The local state of a [`Viewer`].
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@ use crate::overlay;
|
|||
use crate::renderer;
|
||||
use crate::touch;
|
||||
use crate::{
|
||||
Clipboard, Color, Element, Hasher, Layout, Length, Point, Rectangle, Shell,
|
||||
Size, Vector, Widget,
|
||||
Clipboard, Color, Element, Layout, Length, Point, Rectangle, Shell, Size,
|
||||
Vector, Widget,
|
||||
};
|
||||
|
||||
pub use iced_style::pane_grid::{Line, StyleSheet};
|
||||
|
|
@ -666,21 +666,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
use std::hash::Hash;
|
||||
|
||||
struct Marker;
|
||||
std::any::TypeId::of::<Marker>().hash(state);
|
||||
|
||||
self.width.hash(state);
|
||||
self.height.hash(state);
|
||||
self.state.hash_layout(state);
|
||||
|
||||
for (_, element) in &self.elements {
|
||||
element.hash_layout(state);
|
||||
}
|
||||
}
|
||||
|
||||
fn overlay(
|
||||
&mut self,
|
||||
layout: Layout<'_>,
|
||||
|
|
|
|||
|
|
@ -5,9 +5,7 @@ use crate::overlay;
|
|||
use crate::renderer;
|
||||
use crate::widget::container;
|
||||
use crate::widget::pane_grid::TitleBar;
|
||||
use crate::{
|
||||
Clipboard, Element, Hasher, Layout, Point, Rectangle, Shell, Size,
|
||||
};
|
||||
use crate::{Clipboard, Element, Layout, Point, Rectangle, Shell, Size};
|
||||
|
||||
/// The content of a [`Pane`].
|
||||
///
|
||||
|
|
@ -236,14 +234,6 @@ where
|
|||
.max(title_bar_interaction)
|
||||
}
|
||||
|
||||
pub(crate) fn hash_layout(&self, state: &mut Hasher) {
|
||||
if let Some(title_bar) = &self.title_bar {
|
||||
title_bar.hash_layout(state);
|
||||
}
|
||||
|
||||
self.body.hash_layout(state);
|
||||
}
|
||||
|
||||
pub(crate) fn overlay(
|
||||
&mut self,
|
||||
layout: Layout<'_>,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::widget::pane_grid::{
|
||||
Axis, Configuration, Direction, Node, Pane, Split,
|
||||
};
|
||||
use crate::{Hasher, Point, Rectangle, Size};
|
||||
use crate::{Point, Rectangle, Size};
|
||||
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
|
||||
|
|
@ -292,10 +292,4 @@ impl Internal {
|
|||
pub fn idle(&mut self) {
|
||||
self.action = Action::Idle;
|
||||
}
|
||||
|
||||
pub fn hash_layout(&self, hasher: &mut Hasher) {
|
||||
use std::hash::Hash;
|
||||
|
||||
self.layout.hash(hasher);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use crate::overlay;
|
|||
use crate::renderer;
|
||||
use crate::widget::container;
|
||||
use crate::{
|
||||
Clipboard, Element, Hasher, Layout, Padding, Point, Rectangle, Shell, Size,
|
||||
Clipboard, Element, Layout, Padding, Point, Rectangle, Shell, Size,
|
||||
};
|
||||
|
||||
/// The title bar of a [`Pane`].
|
||||
|
|
@ -157,17 +157,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn hash_layout(&self, hasher: &mut Hasher) {
|
||||
use std::hash::Hash;
|
||||
|
||||
self.content.hash_layout(hasher);
|
||||
self.padding.hash(hasher);
|
||||
|
||||
if let Some(controls) = &self.controls {
|
||||
controls.hash_layout(hasher);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn layout(
|
||||
&self,
|
||||
renderer: &Renderer,
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ use crate::renderer;
|
|||
use crate::text::{self, Text};
|
||||
use crate::touch;
|
||||
use crate::{
|
||||
Clipboard, Element, Hasher, Layout, Length, Padding, Point, Rectangle,
|
||||
Shell, Size, Widget,
|
||||
Clipboard, Element, Layout, Length, Padding, Point, Rectangle, Shell, Size,
|
||||
Widget,
|
||||
};
|
||||
use std::borrow::Cow;
|
||||
|
||||
|
|
@ -194,40 +194,6 @@ where
|
|||
layout::Node::new(size)
|
||||
}
|
||||
|
||||
/// Hashes the layout attributes of a [`PickList`].
|
||||
pub fn hash_layout<T>(
|
||||
state: &mut Hasher,
|
||||
width: Length,
|
||||
padding: Padding,
|
||||
text_size: Option<u16>,
|
||||
placeholder: Option<&str>,
|
||||
options: &[T],
|
||||
) where
|
||||
T: ToString,
|
||||
{
|
||||
use std::hash::Hash as _;
|
||||
|
||||
struct Marker;
|
||||
std::any::TypeId::of::<Marker>().hash(state);
|
||||
|
||||
padding.hash(state);
|
||||
text_size.hash(state);
|
||||
|
||||
match width {
|
||||
Length::Shrink => {
|
||||
placeholder.hash(state);
|
||||
|
||||
options
|
||||
.iter()
|
||||
.map(ToString::to_string)
|
||||
.for_each(|label| label.hash(state));
|
||||
}
|
||||
_ => {
|
||||
width.hash(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Processes an [`Event`] and updates the [`State`] of a [`PickList`]
|
||||
/// accordingly.
|
||||
pub fn update<'a, T, Message>(
|
||||
|
|
@ -487,17 +453,6 @@ where
|
|||
)
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
hash_layout(
|
||||
state,
|
||||
self.width,
|
||||
self.padding,
|
||||
self.text_size,
|
||||
self.placeholder.as_ref().map(String::as_str),
|
||||
&self.options,
|
||||
)
|
||||
}
|
||||
|
||||
fn on_event(
|
||||
&mut self,
|
||||
event: Event,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
//! Provide progress feedback to your users.
|
||||
use crate::layout;
|
||||
use crate::renderer;
|
||||
use crate::{
|
||||
Color, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget,
|
||||
};
|
||||
use crate::{Color, Element, Layout, Length, Point, Rectangle, Size, Widget};
|
||||
|
||||
use std::{hash::Hash, ops::RangeInclusive};
|
||||
use std::ops::RangeInclusive;
|
||||
|
||||
pub use iced_style::progress_bar::{Style, StyleSheet};
|
||||
|
||||
|
|
@ -141,14 +139,6 @@ where
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
struct Marker;
|
||||
std::any::TypeId::of::<Marker>().hash(state);
|
||||
|
||||
self.width.hash(state);
|
||||
self.height.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> From<ProgressBar<'a>>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
//! Create choices using radio buttons.
|
||||
use std::hash::Hash;
|
||||
|
||||
use crate::alignment;
|
||||
use crate::event::{self, Event};
|
||||
use crate::layout;
|
||||
|
|
@ -10,8 +8,8 @@ use crate::text;
|
|||
use crate::touch;
|
||||
use crate::widget::{self, Row, Text};
|
||||
use crate::{
|
||||
Alignment, Clipboard, Color, Element, Hasher, Layout, Length, Point,
|
||||
Rectangle, Shell, Widget,
|
||||
Alignment, Clipboard, Color, Element, Layout, Length, Point, Rectangle,
|
||||
Shell, Widget,
|
||||
};
|
||||
|
||||
pub use iced_style::radio::{Style, StyleSheet};
|
||||
|
|
@ -280,13 +278,6 @@ where
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
struct Marker;
|
||||
std::any::TypeId::of::<Marker>().hash(state);
|
||||
|
||||
self.label.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> From<Radio<'a, Message, Renderer>>
|
||||
|
|
|
|||
|
|
@ -5,11 +5,10 @@ use crate::mouse;
|
|||
use crate::overlay;
|
||||
use crate::renderer;
|
||||
use crate::{
|
||||
Alignment, Clipboard, Element, Hasher, Layout, Length, Padding, Point,
|
||||
Rectangle, Shell, Widget,
|
||||
Alignment, Clipboard, Element, Layout, Length, Padding, Point, Rectangle,
|
||||
Shell, Widget,
|
||||
};
|
||||
|
||||
use std::hash::Hash;
|
||||
use std::u32;
|
||||
|
||||
/// A container that distributes its contents horizontally.
|
||||
|
|
@ -198,23 +197,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
struct Marker;
|
||||
std::any::TypeId::of::<Marker>().hash(state);
|
||||
|
||||
self.width.hash(state);
|
||||
self.height.hash(state);
|
||||
self.max_width.hash(state);
|
||||
self.max_height.hash(state);
|
||||
self.align_items.hash(state);
|
||||
self.spacing.hash(state);
|
||||
self.padding.hash(state);
|
||||
|
||||
for child in &self.children {
|
||||
child.widget.hash_layout(state);
|
||||
}
|
||||
}
|
||||
|
||||
fn overlay(
|
||||
&mut self,
|
||||
layout: Layout<'_>,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,7 @@
|
|||
//! Display a horizontal or vertical rule for dividing content.
|
||||
use crate::layout;
|
||||
use crate::renderer;
|
||||
use crate::{
|
||||
Color, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget,
|
||||
};
|
||||
|
||||
use std::hash::Hash;
|
||||
use crate::{Color, Element, Layout, Length, Point, Rectangle, Size, Widget};
|
||||
|
||||
pub use iced_style::rule::{FillMode, Style, StyleSheet};
|
||||
|
||||
|
|
@ -122,14 +118,6 @@ where
|
|||
style.color,
|
||||
);
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
struct Marker;
|
||||
std::any::TypeId::of::<Marker>().hash(state);
|
||||
|
||||
self.width.hash(state);
|
||||
self.height.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> From<Rule<'a>> for Element<'a, Message, Renderer>
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@ use crate::renderer;
|
|||
use crate::touch;
|
||||
use crate::widget::Column;
|
||||
use crate::{
|
||||
Alignment, Background, Clipboard, Color, Element, Hasher, Layout, Length,
|
||||
Padding, Point, Rectangle, Shell, Size, Vector, Widget,
|
||||
Alignment, Background, Clipboard, Color, Element, Layout, Length, Padding,
|
||||
Point, Rectangle, Shell, Size, Vector, Widget,
|
||||
};
|
||||
|
||||
use std::{f32, hash::Hash, u32};
|
||||
use std::{f32, u32};
|
||||
|
||||
pub use iced_style::scrollable::StyleSheet;
|
||||
|
||||
|
|
@ -721,16 +721,6 @@ where
|
|||
)
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
struct Marker;
|
||||
std::any::TypeId::of::<Marker>().hash(state);
|
||||
|
||||
self.height.hash(state);
|
||||
self.max_height.hash(state);
|
||||
|
||||
self.content.hash_layout(state)
|
||||
}
|
||||
|
||||
fn overlay(
|
||||
&mut self,
|
||||
layout: Layout<'_>,
|
||||
|
|
|
|||
|
|
@ -7,11 +7,10 @@ use crate::mouse;
|
|||
use crate::renderer;
|
||||
use crate::touch;
|
||||
use crate::{
|
||||
Background, Clipboard, Color, Element, Hasher, Layout, Length, Point,
|
||||
Rectangle, Shell, Size, Widget,
|
||||
Background, Clipboard, Color, Element, Layout, Length, Point, Rectangle,
|
||||
Shell, Size, Widget,
|
||||
};
|
||||
|
||||
use std::hash::Hash;
|
||||
use std::ops::RangeInclusive;
|
||||
|
||||
pub use iced_style::slider::{Handle, HandleShape, Style, StyleSheet};
|
||||
|
|
@ -344,14 +343,6 @@ pub fn mouse_interaction(
|
|||
}
|
||||
}
|
||||
|
||||
/// Hashes the layout of a [`Slider`].
|
||||
pub fn hash_layout(state: &mut Hasher, width: Length) {
|
||||
struct Marker;
|
||||
std::any::TypeId::of::<Marker>().hash(state);
|
||||
|
||||
width.hash(state);
|
||||
}
|
||||
|
||||
/// The local state of a [`Slider`].
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
pub struct State {
|
||||
|
|
@ -444,10 +435,6 @@ where
|
|||
) -> mouse::Interaction {
|
||||
mouse_interaction(layout, cursor_position, &self.state)
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
hash_layout(state, self.width)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T, Message, Renderer> From<Slider<'a, T, Message>>
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
//! Distribute content vertically.
|
||||
use crate::layout;
|
||||
use crate::renderer;
|
||||
use crate::{Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget};
|
||||
|
||||
use std::hash::Hash;
|
||||
use crate::{Element, Layout, Length, Point, Rectangle, Size, Widget};
|
||||
|
||||
/// An amount of empty space.
|
||||
///
|
||||
|
|
@ -68,13 +66,6 @@ where
|
|||
_viewport: &Rectangle,
|
||||
) {
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
std::any::TypeId::of::<Space>().hash(state);
|
||||
|
||||
self.width.hash(state);
|
||||
self.height.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> From<Space> for Element<'a, Message, Renderer>
|
||||
|
|
|
|||
|
|
@ -2,9 +2,10 @@
|
|||
use crate::layout;
|
||||
use crate::renderer;
|
||||
use crate::svg::{self, Handle};
|
||||
use crate::{Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget};
|
||||
use crate::{
|
||||
ContentFit, Element, Layout, Length, Point, Rectangle, Size, Vector, Widget,
|
||||
};
|
||||
|
||||
use std::hash::Hash;
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// A vector graphics image.
|
||||
|
|
@ -18,6 +19,7 @@ pub struct Svg {
|
|||
handle: Handle,
|
||||
width: Length,
|
||||
height: Length,
|
||||
content_fit: ContentFit,
|
||||
}
|
||||
|
||||
impl Svg {
|
||||
|
|
@ -27,6 +29,7 @@ impl Svg {
|
|||
handle: handle.into(),
|
||||
width: Length::Fill,
|
||||
height: Length::Shrink,
|
||||
content_fit: ContentFit::Contain,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -47,6 +50,16 @@ impl Svg {
|
|||
self.height = height;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the [`ContentFit`] of the [`Svg`].
|
||||
///
|
||||
/// Defaults to [`ContentFit::Contain`]
|
||||
pub fn content_fit(self, content_fit: ContentFit) -> Self {
|
||||
Self {
|
||||
content_fit,
|
||||
..self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Message, Renderer> Widget<Message, Renderer> for Svg
|
||||
|
|
@ -66,24 +79,32 @@ where
|
|||
renderer: &Renderer,
|
||||
limits: &layout::Limits,
|
||||
) -> layout::Node {
|
||||
// The raw w/h of the underlying image
|
||||
let (width, height) = renderer.dimensions(&self.handle);
|
||||
let image_size = Size::new(width as f32, height as f32);
|
||||
|
||||
let aspect_ratio = width as f32 / height as f32;
|
||||
|
||||
let mut size = limits
|
||||
// The size to be available to the widget prior to `Shrink`ing
|
||||
let raw_size = limits
|
||||
.width(self.width)
|
||||
.height(self.height)
|
||||
.resolve(Size::new(width as f32, height as f32));
|
||||
.resolve(image_size);
|
||||
|
||||
let viewport_aspect_ratio = size.width / size.height;
|
||||
// The uncropped size of the image when fit to the bounds above
|
||||
let full_size = self.content_fit.fit(image_size, raw_size);
|
||||
|
||||
if viewport_aspect_ratio > aspect_ratio {
|
||||
size.width = width as f32 * size.height / height as f32;
|
||||
} else {
|
||||
size.height = height as f32 * size.width / width as f32;
|
||||
}
|
||||
// Shrink the widget to fit the resized image, if requested
|
||||
let final_size = Size {
|
||||
width: match self.width {
|
||||
Length::Shrink => f32::min(raw_size.width, full_size.width),
|
||||
_ => raw_size.width,
|
||||
},
|
||||
height: match self.height {
|
||||
Length::Shrink => f32::min(raw_size.height, full_size.height),
|
||||
_ => raw_size.height,
|
||||
},
|
||||
};
|
||||
|
||||
layout::Node::new(size)
|
||||
layout::Node::new(final_size)
|
||||
}
|
||||
|
||||
fn draw(
|
||||
|
|
@ -94,15 +115,34 @@ where
|
|||
_cursor_position: Point,
|
||||
_viewport: &Rectangle,
|
||||
) {
|
||||
renderer.draw(self.handle.clone(), layout.bounds())
|
||||
}
|
||||
let (width, height) = renderer.dimensions(&self.handle);
|
||||
let image_size = Size::new(width as f32, height as f32);
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
std::any::TypeId::of::<Svg>().hash(state);
|
||||
let bounds = layout.bounds();
|
||||
let adjusted_fit = self.content_fit.fit(image_size, bounds.size());
|
||||
|
||||
self.handle.hash(state);
|
||||
self.width.hash(state);
|
||||
self.height.hash(state);
|
||||
let render = |renderer: &mut Renderer| {
|
||||
let offset = Vector::new(
|
||||
(bounds.width - adjusted_fit.width).max(0.0) / 2.0,
|
||||
(bounds.height - adjusted_fit.height).max(0.0) / 2.0,
|
||||
);
|
||||
|
||||
let drawing_bounds = Rectangle {
|
||||
width: adjusted_fit.width,
|
||||
height: adjusted_fit.height,
|
||||
..bounds
|
||||
};
|
||||
|
||||
renderer.draw(self.handle.clone(), drawing_bounds + offset)
|
||||
};
|
||||
|
||||
if adjusted_fit.width > bounds.width
|
||||
|| adjusted_fit.height > bounds.height
|
||||
{
|
||||
renderer.with_layer(bounds, render);
|
||||
} else {
|
||||
render(renderer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,11 +3,7 @@ use crate::alignment;
|
|||
use crate::layout;
|
||||
use crate::renderer;
|
||||
use crate::text;
|
||||
use crate::{
|
||||
Color, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget,
|
||||
};
|
||||
|
||||
use std::hash::Hash;
|
||||
use crate::{Color, Element, Layout, Length, Point, Rectangle, Size, Widget};
|
||||
|
||||
/// A paragraph of text.
|
||||
///
|
||||
|
|
@ -151,16 +147,6 @@ where
|
|||
self.vertical_alignment,
|
||||
);
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
struct Marker;
|
||||
std::any::TypeId::of::<Marker>().hash(state);
|
||||
|
||||
self.content.hash(state);
|
||||
self.size.hash(state);
|
||||
self.width.hash(state);
|
||||
self.height.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
/// Draws text using the same logic as the [`Text`] widget.
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ use crate::renderer;
|
|||
use crate::text::{self, Text};
|
||||
use crate::touch;
|
||||
use crate::{
|
||||
Clipboard, Color, Element, Hasher, Layout, Length, Padding, Point,
|
||||
Rectangle, Shell, Size, Vector, Widget,
|
||||
Clipboard, Color, Element, Layout, Length, Padding, Point, Rectangle,
|
||||
Shell, Size, Vector, Widget,
|
||||
};
|
||||
|
||||
pub use iced_style::text_input::{Style, StyleSheet};
|
||||
|
|
@ -725,21 +725,6 @@ pub fn mouse_interaction(
|
|||
}
|
||||
}
|
||||
|
||||
/// Hashes the layout attributes of a [`TextInput`].
|
||||
pub fn hash_layout(
|
||||
state: &mut Hasher,
|
||||
width: Length,
|
||||
padding: Padding,
|
||||
size: Option<u16>,
|
||||
) {
|
||||
use std::hash::Hash;
|
||||
|
||||
std::any::TypeId::of::<State>().hash(state);
|
||||
width.hash(state);
|
||||
padding.hash(state);
|
||||
size.hash(state);
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> Widget<Message, Renderer>
|
||||
for TextInput<'a, Message, Renderer>
|
||||
where
|
||||
|
|
@ -819,10 +804,6 @@ where
|
|||
self.style_sheet.as_ref(),
|
||||
)
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
hash_layout(state, self.width, self.padding, self.size)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> From<TextInput<'a, Message, Renderer>>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
//! Show toggle controls using togglers.
|
||||
use std::hash::Hash;
|
||||
|
||||
use crate::alignment;
|
||||
use crate::event;
|
||||
|
|
@ -9,8 +8,8 @@ use crate::renderer;
|
|||
use crate::text;
|
||||
use crate::widget::{Row, Text};
|
||||
use crate::{
|
||||
Alignment, Clipboard, Element, Event, Hasher, Layout, Length, Point,
|
||||
Rectangle, Shell, Widget,
|
||||
Alignment, Clipboard, Element, Event, Layout, Length, Point, Rectangle,
|
||||
Shell, Widget,
|
||||
};
|
||||
|
||||
pub use iced_style::toggler::{Style, StyleSheet};
|
||||
|
|
@ -295,13 +294,6 @@ where
|
|||
style.foreground,
|
||||
);
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
struct Marker;
|
||||
std::any::TypeId::of::<Marker>().hash(state);
|
||||
|
||||
self.label.hash(state)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> From<Toggler<'a, Message, Renderer>>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,4 @@
|
|||
//! Display a widget over another.
|
||||
use std::hash::Hash;
|
||||
|
||||
use iced_core::Rectangle;
|
||||
|
||||
use crate::event;
|
||||
use crate::layout;
|
||||
use crate::mouse;
|
||||
|
|
@ -11,8 +7,8 @@ use crate::text;
|
|||
use crate::widget::container;
|
||||
use crate::widget::text::Text;
|
||||
use crate::{
|
||||
Clipboard, Element, Event, Hasher, Layout, Length, Padding, Point, Shell,
|
||||
Size, Vector, Widget,
|
||||
Clipboard, Element, Event, Layout, Length, Padding, Point, Rectangle,
|
||||
Shell, Size, Vector, Widget,
|
||||
};
|
||||
|
||||
/// An element to display a widget over another.
|
||||
|
|
@ -268,13 +264,6 @@ where
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
struct Marker;
|
||||
std::any::TypeId::of::<Marker>().hash(state);
|
||||
|
||||
self.content.hash_layout(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Message, Renderer> From<Tooltip<'a, Message, Renderer>>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue