summaryrefslogtreecommitdiffstats
path: root/native/src/widget
diff options
context:
space:
mode:
Diffstat (limited to 'native/src/widget')
-rw-r--r--native/src/widget/checkbox.rs4
-rw-r--r--native/src/widget/image.rs19
-rw-r--r--native/src/widget/radio.rs4
-rw-r--r--native/src/widget/scrollable.rs17
-rw-r--r--native/src/widget/text.rs5
-rw-r--r--native/src/widget/text_input.rs5
6 files changed, 28 insertions, 26 deletions
diff --git a/native/src/widget/checkbox.rs b/native/src/widget/checkbox.rs
index 655fd0ae..9563291c 100644
--- a/native/src/widget/checkbox.rs
+++ b/native/src/widget/checkbox.rs
@@ -14,7 +14,7 @@ use crate::{
///
/// ```
/// # use iced_native::Checkbox;
-///
+/// #
/// pub enum Message {
/// CheckboxToggled(bool),
/// }
@@ -24,7 +24,7 @@ use crate::{
/// Checkbox::new(is_checked, "Toggle me!", Message::CheckboxToggled);
/// ```
///
-/// ![Checkbox drawn by Coffee's renderer](https://github.com/hecrj/coffee/blob/bda9818f823dfcb8a7ad0ff4940b4d4b387b5208/images/ui/checkbox.png?raw=true)
+/// ![Checkbox drawn by `iced_wgpu`](https://github.com/hecrj/iced/blob/7760618fb112074bc40b148944521f312152012a/docs/images/checkbox.png?raw=true)
#[allow(missing_debug_implementations)]
pub struct Checkbox<Message> {
is_checked: bool,
diff --git a/native/src/widget/image.rs b/native/src/widget/image.rs
index c64f07b1..4c588c9d 100644
--- a/native/src/widget/image.rs
+++ b/native/src/widget/image.rs
@@ -10,19 +10,16 @@ use std::hash::Hash;
///
/// ```
/// # use iced_native::Image;
-///
+/// #
/// let image = Image::new("resources/ferris.png");
/// ```
+///
+/// <img src="https://github.com/hecrj/iced/blob/9712b319bb7a32848001b96bd84977430f14b623/examples/resources/ferris.png?raw=true" width="300">
#[derive(Debug)]
pub struct Image {
- /// The image path
- pub path: String,
-
- /// The width of the image
- pub width: Length,
-
- /// The height of the image
- pub height: Length,
+ path: String,
+ width: Length,
+ height: Length,
}
impl Image {
@@ -99,7 +96,7 @@ where
layout: Layout<'_>,
_cursor_position: Point,
) -> Renderer::Output {
- renderer.draw(&self, layout)
+ renderer.draw(&self.path, layout)
}
fn hash_layout(&self, state: &mut Hasher) {
@@ -124,7 +121,7 @@ pub trait Renderer: crate::Renderer {
/// Draws an [`Image`].
///
/// [`Image`]: struct.Image.html
- fn draw(&mut self, image: &Image, layout: Layout<'_>) -> Self::Output;
+ fn draw(&mut self, path: &str, layout: Layout<'_>) -> Self::Output;
}
impl<'a, Message, Renderer> From<Image> for Element<'a, Message, Renderer>
diff --git a/native/src/widget/radio.rs b/native/src/widget/radio.rs
index cc642d1c..a9d145db 100644
--- a/native/src/widget/radio.rs
+++ b/native/src/widget/radio.rs
@@ -13,7 +13,7 @@ use std::hash::Hash;
/// # Example
/// ```
/// # use iced_native::Radio;
-///
+/// #
/// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
/// pub enum Choice {
/// A,
@@ -32,7 +32,7 @@ use std::hash::Hash;
/// Radio::new(Choice::B, "This is B", selected_choice, Message::RadioSelected);
/// ```
///
-/// ![Radio buttons drawn by Coffee's renderer](https://github.com/hecrj/coffee/blob/bda9818f823dfcb8a7ad0ff4940b4d4b387b5208/images/ui/radio.png?raw=true)
+/// ![Radio buttons drawn by `iced_wgpu`](https://github.com/hecrj/iced/blob/7760618fb112074bc40b148944521f312152012a/docs/images/radio.png?raw=true)
#[allow(missing_debug_implementations)]
pub struct Radio<Message> {
is_selected: bool,
diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs
index 0d745756..678d837a 100644
--- a/native/src/widget/scrollable.rs
+++ b/native/src/widget/scrollable.rs
@@ -163,7 +163,7 @@ where
match delta {
mouse::ScrollDelta::Lines { y, .. } => {
// TODO: Configurable speed (?)
- self.state.scroll(y * 15.0, bounds, content_bounds);
+ self.state.scroll(y * 60.0, bounds, content_bounds);
}
mouse::ScrollDelta::Pixels { y, .. } => {
self.state.scroll(y, bounds, content_bounds);
@@ -295,7 +295,7 @@ where
#[derive(Debug, Clone, Copy, Default)]
pub struct State {
scrollbar_grabbed_at: Option<Point>,
- offset: u32,
+ offset: f32,
}
impl State {
@@ -321,10 +321,9 @@ impl State {
return;
}
- self.offset = (self.offset as i32 - delta_y.round() as i32)
- .max(0)
- .min((content_bounds.height - bounds.height) as i32)
- as u32;
+ self.offset = (self.offset - delta_y)
+ .max(0.0)
+ .min((content_bounds.height - bounds.height) as f32);
}
/// Moves the scroll position to a relative amount, given the bounds of
@@ -341,8 +340,8 @@ impl State {
bounds: Rectangle,
content_bounds: Rectangle,
) {
- self.offset = ((content_bounds.height - bounds.height) * percentage)
- .max(0.0) as u32;
+ self.offset =
+ ((content_bounds.height - bounds.height) * percentage).max(0.0);
}
/// Returns the current scrolling offset of the [`State`], given the bounds
@@ -354,7 +353,7 @@ impl State {
let hidden_content =
(content_bounds.height - bounds.height).max(0.0).round() as u32;
- self.offset.min(hidden_content)
+ self.offset.min(hidden_content as f32) as u32
}
/// Returns whether the scrollbar is currently grabbed or not.
diff --git a/native/src/widget/text.rs b/native/src/widget/text.rs
index cf0701b9..cf9c9565 100644
--- a/native/src/widget/text.rs
+++ b/native/src/widget/text.rs
@@ -12,10 +12,13 @@ use std::hash::Hash;
///
/// ```
/// # use iced_native::Text;
-///
+/// #
/// Text::new("I <3 iced!")
+/// .color([0.0, 0.0, 1.0])
/// .size(40);
/// ```
+///
+/// ![Text drawn by `iced_wgpu`](https://github.com/hecrj/iced/blob/7760618fb112074bc40b148944521f312152012a/docs/images/text.png?raw=true)
#[derive(Debug, Clone)]
pub struct Text {
content: String,
diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs
index fbf144e3..f97ed424 100644
--- a/native/src/widget/text_input.rs
+++ b/native/src/widget/text_input.rs
@@ -16,6 +16,7 @@ use crate::{
/// ```
/// # use iced_native::{text_input, TextInput};
/// #
+/// #[derive(Debug, Clone)]
/// enum Message {
/// TextInputChanged(String),
/// }
@@ -28,8 +29,10 @@ use crate::{
/// "This is the placeholder...",
/// value,
/// Message::TextInputChanged,
-/// );
+/// )
+/// .padding(10);
/// ```
+/// ![Text input drawn by `iced_wgpu`](https://github.com/hecrj/iced/blob/7760618fb112074bc40b148944521f312152012a/docs/images/text_input.png?raw=true)
#[allow(missing_debug_implementations)]
pub struct TextInput<'a, Message> {
state: &'a mut State,