summaryrefslogtreecommitdiffstats
path: root/native/src/widget
diff options
context:
space:
mode:
authorLibravatar Giuliano Bellini <100347457+GyulyVGC@users.noreply.github.com>2023-02-02 16:52:56 +0100
committerLibravatar GitHub <noreply@github.com>2023-02-02 16:52:56 +0100
commita35d6d2e4d59f71309f31c87ea5150959d639185 (patch)
treeefd44456685739bce1962146e66002654c9ecb0e /native/src/widget
parent49e9a9a5379c1e9a9469045ca9a51ffb860ee620 (diff)
parent98a717383acf71d7939d7cc90d350743487f0380 (diff)
downloadiced-a35d6d2e4d59f71309f31c87ea5150959d639185.tar.gz
iced-a35d6d2e4d59f71309f31c87ea5150959d639185.tar.bz2
iced-a35d6d2e4d59f71309f31c87ea5150959d639185.zip
Merge branch 'iced-rs:master' into master
Diffstat (limited to 'native/src/widget')
-rw-r--r--native/src/widget/action.rs12
-rw-r--r--native/src/widget/image.rs68
-rw-r--r--native/src/widget/operation.rs2
-rw-r--r--native/src/widget/pane_grid.rs13
4 files changed, 60 insertions, 35 deletions
diff --git a/native/src/widget/action.rs b/native/src/widget/action.rs
index 1e21ff38..3f1b6b6c 100644
--- a/native/src/widget/action.rs
+++ b/native/src/widget/action.rs
@@ -1,4 +1,6 @@
-use crate::widget::operation::{self, Focusable, Operation, Scrollable};
+use crate::widget::operation::{
+ self, Focusable, Operation, Scrollable, TextInput,
+};
use crate::widget::Id;
use iced_futures::MaybeSend;
@@ -86,6 +88,14 @@ where
self.operation.focusable(state, id);
}
+ fn text_input(
+ &mut self,
+ state: &mut dyn TextInput,
+ id: Option<&Id>,
+ ) {
+ self.operation.text_input(state, id);
+ }
+
fn custom(&mut self, state: &mut dyn Any, id: Option<&Id>) {
self.operation.custom(state, id);
}
diff --git a/native/src/widget/image.rs b/native/src/widget/image.rs
index 8bd8ca1e..3ff06a76 100644
--- a/native/src/widget/image.rs
+++ b/native/src/widget/image.rs
@@ -111,6 +111,45 @@ where
layout::Node::new(final_size)
}
+/// Draws an [`Image`]
+pub fn draw<Renderer, Handle>(
+ renderer: &mut Renderer,
+ layout: Layout<'_>,
+ handle: &Handle,
+ content_fit: ContentFit,
+) where
+ Renderer: image::Renderer<Handle = Handle>,
+ Handle: Clone + Hash,
+{
+ let Size { width, height } = renderer.dimensions(handle);
+ let image_size = Size::new(width as f32, height as f32);
+
+ let bounds = layout.bounds();
+ let adjusted_fit = 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(handle.clone(), drawing_bounds + offset)
+ };
+
+ if adjusted_fit.width > bounds.width || adjusted_fit.height > bounds.height
+ {
+ renderer.with_layer(bounds, render);
+ } else {
+ render(renderer)
+ }
+}
+
impl<Message, Renderer, Handle> Widget<Message, Renderer> for Image<Handle>
where
Renderer: image::Renderer<Handle = Handle>,
@@ -149,34 +188,7 @@ where
_cursor_position: Point,
_viewport: &Rectangle,
) {
- let Size { width, height } = renderer.dimensions(&self.handle);
- let image_size = Size::new(width as f32, height as f32);
-
- 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)
- }
+ draw(renderer, layout, &self.handle, self.content_fit)
}
}
diff --git a/native/src/widget/operation.rs b/native/src/widget/operation.rs
index 73e6a6b0..53688a21 100644
--- a/native/src/widget/operation.rs
+++ b/native/src/widget/operation.rs
@@ -62,7 +62,7 @@ where
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::None => write!(f, "Outcome::None"),
- Self::Some(output) => write!(f, "Outcome::Some({:?})", output),
+ Self::Some(output) => write!(f, "Outcome::Some({output:?})"),
Self::Chain(_) => write!(f, "Outcome::Chain(...)"),
}
}
diff --git a/native/src/widget/pane_grid.rs b/native/src/widget/pane_grid.rs
index 8dbd1825..eb04c0ba 100644
--- a/native/src/widget/pane_grid.rs
+++ b/native/src/widget/pane_grid.rs
@@ -35,7 +35,7 @@ pub use iced_style::pane_grid::{Line, StyleSheet};
use crate::event::{self, Event};
use crate::layout;
use crate::mouse;
-use crate::overlay;
+use crate::overlay::{self, Group};
use crate::renderer;
use crate::touch;
use crate::widget;
@@ -450,14 +450,17 @@ where
layout: Layout<'_>,
renderer: &Renderer,
) -> Option<overlay::Element<'_, Message, Renderer>> {
- self.contents
+ let children = self
+ .contents
.iter_mut()
.zip(&mut tree.children)
.zip(layout.children())
- .filter_map(|(((_, pane), tree), layout)| {
- pane.overlay(tree, layout, renderer)
+ .filter_map(|(((_, content), state), layout)| {
+ content.overlay(state, layout, renderer)
})
- .next()
+ .collect::<Vec<_>>();
+
+ (!children.is_empty()).then(|| Group::with_children(children).overlay())
}
}