Merge pull request #60 from hecrj/fix/required-width-height

Make `width` and `height` in `Widget` required methods
This commit is contained in:
Héctor Ramón 2019-11-18 21:55:20 +01:00 committed by GitHub
commit 54ffefcc0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 78 additions and 10 deletions

View File

@ -299,6 +299,14 @@ where
A: Clone,
Renderer: crate::Renderer,
{
fn width(&self) -> Length {
self.widget.width()
}
fn height(&self) -> Length {
self.widget.height()
}
fn layout(
&self,
renderer: &Renderer,
@ -375,6 +383,14 @@ impl<'a, Message, Renderer> Widget<Message, Renderer>
where
Renderer: crate::Renderer + renderer::Debugger,
{
fn width(&self) -> Length {
self.element.widget.width()
}
fn height(&self) -> Length {
self.element.widget.height()
}
fn layout(
&self,
renderer: &Renderer,

View File

@ -69,6 +69,10 @@ pub trait Widget<Message, Renderer>: std::fmt::Debug
where
Renderer: crate::Renderer,
{
fn width(&self) -> Length;
fn height(&self) -> Length;
/// Returns the [`Node`] of the [`Widget`].
///
/// This [`Node`] is used by the runtime to compute the [`Layout`] of the
@ -83,14 +87,6 @@ where
limits: &layout::Limits,
) -> layout::Node;
fn width(&self) -> Length {
Length::Shrink
}
fn height(&self) -> Length {
Length::Shrink
}
/// Draws the [`Widget`] using the associated `Renderer`.
///
/// [`Widget`]: trait.Widget.html

View File

@ -7,7 +7,7 @@
//! [`Class`]: enum.Class.html
use crate::input::{mouse, ButtonState};
use crate::{layout, Element, Event, Hasher, Layout, Point, Widget};
use crate::{layout, Element, Event, Hasher, Layout, Length, Point, Widget};
use std::hash::Hash;
pub use iced_core::button::State;
@ -21,6 +21,14 @@ where
Renderer: self::Renderer,
Message: Clone + std::fmt::Debug,
{
fn width(&self) -> Length {
self.width
}
fn height(&self) -> Length {
Length::Shrink
}
fn layout(
&self,
renderer: &Renderer,

View File

@ -14,6 +14,10 @@ where
Length::Fill
}
fn height(&self) -> Length {
Length::Shrink
}
fn layout(
&self,
renderer: &Renderer,

View File

@ -15,6 +15,10 @@ where
self.width
}
fn height(&self) -> Length {
self.height
}
fn layout(
&self,
renderer: &Renderer,

View File

@ -15,6 +15,10 @@ where
self.width
}
fn height(&self) -> Length {
self.height
}
fn layout(
&self,
renderer: &Renderer,

View File

@ -1,6 +1,6 @@
//! Display images in your user interface.
use crate::{layout, Element, Hasher, Layout, Point, Widget};
use crate::{layout, Element, Hasher, Layout, Length, Point, Widget};
use std::hash::Hash;
@ -10,6 +10,14 @@ impl<Message, Renderer> Widget<Message, Renderer> for Image
where
Renderer: self::Renderer,
{
fn width(&self) -> Length {
self.width
}
fn height(&self) -> Length {
self.height
}
fn layout(
&self,
renderer: &Renderer,

View File

@ -15,6 +15,10 @@ where
Length::Fill
}
fn height(&self) -> Length {
Length::Shrink
}
fn layout(
&self,
renderer: &Renderer,

View File

@ -15,6 +15,10 @@ where
self.width
}
fn height(&self) -> Length {
self.height
}
fn layout(
&self,
renderer: &Renderer,

View File

@ -21,6 +21,14 @@ impl<'a, Message, Renderer> Widget<Message, Renderer>
where
Renderer: self::Renderer + column::Renderer,
{
fn width(&self) -> Length {
Length::Fill
}
fn height(&self) -> Length {
self.height
}
fn layout(
&self,
renderer: &Renderer,

View File

@ -19,6 +19,10 @@ where
self.width
}
fn height(&self) -> Length {
Length::Shrink
}
fn layout(
&self,
renderer: &Renderer,

View File

@ -13,6 +13,10 @@ where
self.width
}
fn height(&self) -> Length {
self.height
}
fn layout(
&self,
renderer: &Renderer,

View File

@ -15,6 +15,10 @@ where
self.width
}
fn height(&self) -> Length {
Length::Shrink
}
fn layout(
&self,
renderer: &Renderer,