Skip to content

Commit

Permalink
Revert "provide ID to operation.container in applicable widgets"
Browse files Browse the repository at this point in the history
This reverts commit 8f9550b.
  • Loading branch information
nicksenger authored and hecrj committed Feb 16, 2023
1 parent 84a6038 commit d05ac38
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 226 deletions.
53 changes: 9 additions & 44 deletions native/src/widget/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::overlay;
use crate::renderer;
use crate::touch;
use crate::widget::tree::{self, Tree};
use crate::widget::{self, Operation};
use crate::widget::Operation;
use crate::{
Background, Clipboard, Color, Element, Layout, Length, Padding, Point,
Rectangle, Shell, Vector, Widget,
Expand Down Expand Up @@ -56,7 +56,6 @@ where
Renderer: crate::Renderer,
Renderer::Theme: StyleSheet,
{
id: Option<Id>,
content: Element<'a, Message, Renderer>,
on_press: Option<Message>,
width: Length,
Expand All @@ -73,7 +72,6 @@ where
/// Creates a new [`Button`] with the given content.
pub fn new(content: impl Into<Element<'a, Message, Renderer>>) -> Self {
Button {
id: None,
content: content.into(),
on_press: None,
width: Length::Shrink,
Expand All @@ -83,12 +81,6 @@ where
}
}

/// Sets the [`Id`] of the [`Button`].
pub fn id(mut self, id: Id) -> Self {
self.id = Some(id);
self
}

/// Sets the width of the [`Button`].
pub fn width(mut self, width: Length) -> Self {
self.width = width;
Expand Down Expand Up @@ -180,17 +172,14 @@ where
renderer: &Renderer,
operation: &mut dyn Operation<Message>,
) {
operation.container(
self.id.as_ref().map(|id| &id.0),
&mut |operation| {
self.content.as_widget().operate(
&mut tree.children[0],
layout.children().next().unwrap(),
renderer,
operation,
);
},
);
operation.container(None, &mut |operation| {
self.content.as_widget().operate(
&mut tree.children[0],
layout.children().next().unwrap(),
renderer,
operation,
);
});
}

fn on_event(
Expand Down Expand Up @@ -464,27 +453,3 @@ pub fn mouse_interaction(
mouse::Interaction::default()
}
}

/// The identifier of a [`Button`].
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Id(widget::Id);

impl Id {
/// Creates a custom [`Id`].
pub fn new(id: impl Into<std::borrow::Cow<'static, str>>) -> Self {
Self(widget::Id::new(id))
}

/// Creates a unique [`Id`].
///
/// This function produces a different [`Id`] every time it is called.
pub fn unique() -> Self {
Self(widget::Id::unique())
}
}

impl From<Id> for widget::Id {
fn from(id: Id) -> Self {
id.0
}
}
59 changes: 12 additions & 47 deletions native/src/widget/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::layout;
use crate::mouse;
use crate::overlay;
use crate::renderer;
use crate::widget::{self, Operation, Tree};
use crate::widget::{Operation, Tree};
use crate::{
Alignment, Clipboard, Element, Layout, Length, Padding, Point, Rectangle,
Shell, Widget,
Expand All @@ -13,7 +13,6 @@ use crate::{
/// A container that distributes its contents vertically.
#[allow(missing_debug_implementations)]
pub struct Column<'a, Message, Renderer> {
id: Option<Id>,
spacing: u16,
padding: Padding,
width: Length,
Expand All @@ -34,7 +33,6 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> {
children: Vec<Element<'a, Message, Renderer>>,
) -> Self {
Column {
id: None,
spacing: 0,
padding: Padding::ZERO,
width: Length::Shrink,
Expand All @@ -45,12 +43,6 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> {
}
}

/// Sets the [`Id`] of the [`Column`].
pub fn id(mut self, id: Id) -> Self {
self.id = Some(id);
self
}

/// Sets the vertical spacing _between_ elements.
///
/// Custom margins per element do not exist in iced. You should use this
Expand Down Expand Up @@ -156,20 +148,17 @@ where
renderer: &Renderer,
operation: &mut dyn Operation<Message>,
) {
operation.container(
self.id.as_ref().map(|id| &id.0),
&mut |operation| {
self.children
.iter()
.zip(&mut tree.children)
.zip(layout.children())
.for_each(|((child, state), layout)| {
child
.as_widget()
.operate(state, layout, renderer, operation);
})
},
);
operation.container(None, &mut |operation| {
self.children
.iter()
.zip(&mut tree.children)
.zip(layout.children())
.for_each(|((child, state), layout)| {
child
.as_widget()
.operate(state, layout, renderer, operation);
})
});
}

fn on_event(
Expand Down Expand Up @@ -273,27 +262,3 @@ where
Self::new(column)
}
}

/// The identifier of a [`Column`].
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Id(widget::Id);

impl Id {
/// Creates a custom [`Id`].
pub fn new(id: impl Into<std::borrow::Cow<'static, str>>) -> Self {
Self(widget::Id::new(id))
}

/// Creates a unique [`Id`].
///
/// This function produces a different [`Id`] every time it is called.
pub fn unique() -> Self {
Self(widget::Id::unique())
}
}

impl From<Id> for widget::Id {
fn from(id: Id) -> Self {
id.0
}
}
53 changes: 9 additions & 44 deletions native/src/widget/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::layout;
use crate::mouse;
use crate::overlay;
use crate::renderer;
use crate::widget::{self, Operation, Tree};
use crate::widget::{Operation, Tree};
use crate::{
Background, Clipboard, Color, Element, Layout, Length, Padding, Point,
Rectangle, Shell, Widget,
Expand All @@ -24,7 +24,6 @@ where
Renderer: crate::Renderer,
Renderer::Theme: StyleSheet,
{
id: Option<Id>,
padding: Padding,
width: Length,
height: Length,
Expand All @@ -47,7 +46,6 @@ where
T: Into<Element<'a, Message, Renderer>>,
{
Container {
id: None,
padding: Padding::ZERO,
width: Length::Shrink,
height: Length::Shrink,
Expand All @@ -60,12 +58,6 @@ where
}
}

/// Sets the [`Id`] of the [`Container`].
pub fn id(mut self, id: Id) -> Self {
self.id = Some(id);
self
}

/// Sets the [`Padding`] of the [`Container`].
pub fn padding<P: Into<Padding>>(mut self, padding: P) -> Self {
self.padding = padding.into();
Expand Down Expand Up @@ -180,17 +172,14 @@ where
renderer: &Renderer,
operation: &mut dyn Operation<Message>,
) {
operation.container(
self.id.as_ref().map(|id| &id.0),
&mut |operation| {
self.content.as_widget().operate(
&mut tree.children[0],
layout.children().next().unwrap(),
renderer,
operation,
);
},
);
operation.container(None, &mut |operation| {
self.content.as_widget().operate(
&mut tree.children[0],
layout.children().next().unwrap(),
renderer,
operation,
);
});
}

fn on_event(
Expand Down Expand Up @@ -344,27 +333,3 @@ pub fn draw_background<Renderer>(
);
}
}

/// The identifier of a [`Container`].
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Id(widget::Id);

impl Id {
/// Creates a custom [`Id`].
pub fn new(id: impl Into<std::borrow::Cow<'static, str>>) -> Self {
Self(widget::Id::new(id))
}

/// Creates a unique [`Id`].
///
/// This function produces a different [`Id`] every time it is called.
pub fn unique() -> Self {
Self(widget::Id::unique())
}
}

impl From<Id> for widget::Id {
fn from(id: Id) -> Self {
id.0
}
}
53 changes: 9 additions & 44 deletions native/src/widget/pane_grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ where
Renderer: crate::Renderer,
Renderer::Theme: StyleSheet + container::StyleSheet,
{
id: Option<Id>,
contents: Contents<'a, Content<'a, Message, Renderer>>,
width: Length,
height: Length,
Expand Down Expand Up @@ -148,7 +147,6 @@ where
};

Self {
id: None,
contents,
width: Length::Fill,
height: Length::Fill,
Expand All @@ -160,12 +158,6 @@ where
}
}

/// Sets the [`Id`] of the [`PaneGrid`].
pub fn id(mut self, id: Id) -> Self {
self.id = Some(id);
self
}

/// Sets the width of the [`PaneGrid`].
pub fn width(mut self, width: Length) -> Self {
self.width = width;
Expand Down Expand Up @@ -305,18 +297,15 @@ where
renderer: &Renderer,
operation: &mut dyn widget::Operation<Message>,
) {
operation.container(
self.id.as_ref().map(|id| &id.0),
&mut |operation| {
self.contents
.iter()
.zip(&mut tree.children)
.zip(layout.children())
.for_each(|(((_pane, content), state), layout)| {
content.operate(state, layout, renderer, operation);
})
},
);
operation.container(None, &mut |operation| {
self.contents
.iter()
.zip(&mut tree.children)
.zip(layout.children())
.for_each(|(((_pane, content), state), layout)| {
content.operate(state, layout, renderer, operation);
})
});
}

fn on_event(
Expand Down Expand Up @@ -1007,27 +996,3 @@ impl<'a, T> Contents<'a, T> {
matches!(self, Self::Maximized(..))
}
}

/// The identifier of a [`PaneGrid`].
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Id(widget::Id);

impl Id {
/// Creates a custom [`Id`].
pub fn new(id: impl Into<std::borrow::Cow<'static, str>>) -> Self {
Self(widget::Id::new(id))
}

/// Creates a unique [`Id`].
///
/// This function produces a different [`Id`] every time it is called.
pub fn unique() -> Self {
Self(widget::Id::unique())
}
}

impl From<Id> for widget::Id {
fn from(id: Id) -> Self {
id.0
}
}
Loading

0 comments on commit d05ac38

Please sign in to comment.