Skip to content

Commit

Permalink
Merge branch 'RequestUserAttention' of https://github.com/Night-Hunte…
Browse files Browse the repository at this point in the history
…r-NF/iced into RequestUserAttention
  • Loading branch information
n1ght-hunter committed Dec 29, 2022
2 parents 9de0179 + c8601a0 commit dbe008e
Show file tree
Hide file tree
Showing 41 changed files with 717 additions and 70 deletions.
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/BUG-REPORT.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ body:
attributes:
label: Version
description: |
We only offer support for the `0.4` release on crates.io and the `master` branch on this repository. Which version are you using? Please make sure you are using the latest patch available (e.g. run `cargo update`).
We only offer support for the latest release on crates.io and the `master` branch on this repository. Which version are you using? Please make sure you are using the latest patch available (e.g. run `cargo update`).
If you are using an older release, please upgrade to `0.4` before filing an issue.
If you are using an older release, please upgrade to the latest one before filing an issue.
options:
- master
- 0.4
- 0.6
validations:
required: true
- type: dropdown
Expand Down
4 changes: 2 additions & 2 deletions core/src/rectangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ impl std::ops::Mul<f32> for Rectangle<f32> {

fn mul(self, scale: f32) -> Self {
Self {
x: self.x as f32 * scale,
y: self.y as f32 * scale,
x: self.x * scale,
y: self.y * scale,
width: self.width * scale,
height: self.height * scale,
}
Expand Down
6 changes: 4 additions & 2 deletions examples/game_of_life/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,10 @@ mod grid {
let old_scaling = self.scaling;

let scaling = (self.scaling * (1.0 + y / 30.0))
.max(Self::MIN_SCALING)
.min(Self::MAX_SCALING);
.clamp(
Self::MIN_SCALING,
Self::MAX_SCALING,
);

let translation =
if let Some(cursor_to_center) =
Expand Down
4 changes: 4 additions & 0 deletions examples/modal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,13 @@ mod modal {
&self,
state: &mut Tree,
layout: Layout<'_>,
renderer: &Renderer,
operation: &mut dyn widget::Operation<Message>,
) {
self.base.as_widget().operate(
&mut state.children[0],
layout,
renderer,
operation,
);
}
Expand Down Expand Up @@ -436,11 +438,13 @@ mod modal {
fn operate(
&mut self,
layout: Layout<'_>,
renderer: &Renderer,
operation: &mut dyn widget::Operation<Message>,
) {
self.content.as_widget().operate(
self.tree,
layout.children().next().unwrap(),
renderer,
operation,
);
}
Expand Down
9 changes: 9 additions & 0 deletions examples/slider/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "slider"
version = "0.1.0"
authors = ["Casper Rogild Storm<casper@rogildstorm.com>"]
edition = "2021"
publish = false

[dependencies]
iced = { path = "../.." }
14 changes: 14 additions & 0 deletions examples/slider/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Slider

A `Slider` is a bar and a handle that selects a single value from a range of values.
There exists both `Slider` and `VerticalSlider` depending on which orientation you need.

<div align="center">
<img src="sliders.gif">
</div>

You can run it with `cargo run`:

```
cargo run --package slider
```
Binary file added examples/slider/sliders.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions examples/slider/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
use iced::widget::{column, container, slider, text, vertical_slider};
use iced::{Element, Length, Sandbox, Settings};

pub fn main() -> iced::Result {
Slider::run(Settings::default())
}

#[derive(Debug, Clone)]
pub enum Message {
SliderChanged(u8),
}

pub struct Slider {
slider_value: u8,
}

impl Sandbox for Slider {
type Message = Message;

fn new() -> Slider {
Slider { slider_value: 50 }
}

fn title(&self) -> String {
String::from("Slider - Iced")
}

fn update(&mut self, message: Message) {
match message {
Message::SliderChanged(value) => {
self.slider_value = value;
}
}
}

fn view(&self) -> Element<Message> {
let value = self.slider_value;

let h_slider =
container(slider(0..=100, value, Message::SliderChanged))
.width(Length::Units(250));

let v_slider =
container(vertical_slider(0..=100, value, Message::SliderChanged))
.height(Length::Units(200));

let text = text(format!("{value}"));

container(
column![
container(v_slider).width(Length::Fill).center_x(),
container(h_slider).width(Length::Fill).center_x(),
container(text).width(Length::Fill).center_x(),
]
.spacing(25),
)
.height(Length::Fill)
.width(Length::Fill)
.center_x()
.center_y()
.into()
}
}
2 changes: 1 addition & 1 deletion glow/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "iced_glow"
version = "0.5.0"
version = "0.5.1"
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
edition = "2021"
description = "A glow renderer for iced"
Expand Down
2 changes: 1 addition & 1 deletion glow/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl Pipeline {
}

#[cfg(not(feature = "svg"))]
layer::Image::Vector { handle: _, bounds } => (None, bounds),
layer::Image::Vector { bounds, .. } => (None, bounds),
};

unsafe {
Expand Down
5 changes: 3 additions & 2 deletions glutin/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ async fn run_instance<A, E, C>(
let mut cache = user_interface::Cache::default();
let mut state = application::State::new(&application, context.window());
let mut viewport_version = state.viewport_version();
let mut should_exit = false;

application::run_command(
&application,
Expand All @@ -209,6 +210,7 @@ async fn run_instance<A, E, C>(
init_command,
&mut runtime,
&mut clipboard,
&mut should_exit,
&mut proxy,
&mut debug,
context.window(),
Expand Down Expand Up @@ -271,6 +273,7 @@ async fn run_instance<A, E, C>(
&mut renderer,
&mut runtime,
&mut clipboard,
&mut should_exit,
&mut proxy,
&mut debug,
&mut messages,
Expand All @@ -281,8 +284,6 @@ async fn run_instance<A, E, C>(
// Update window
state.synchronize(&application, context.window());

let should_exit = application.should_exit();

user_interface =
ManuallyDrop::new(application::build_user_interface(
&application,
Expand Down
2 changes: 2 additions & 0 deletions lazy/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ where
&self,
tree: &mut Tree,
layout: Layout<'_>,
renderer: &Renderer,
operation: &mut dyn widget::Operation<Message>,
) {
struct MapOperation<'a, B> {
Expand Down Expand Up @@ -274,6 +275,7 @@ where
element.as_widget().operate(
&mut tree.children[0],
layout,
renderer,
&mut MapOperation { operation },
);
});
Expand Down
2 changes: 2 additions & 0 deletions lazy/src/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,14 @@ where
&self,
tree: &mut Tree,
layout: Layout<'_>,
renderer: &Renderer,
operation: &mut dyn widget::Operation<Message>,
) {
self.with_element(|element| {
element.as_widget().operate(
&mut tree.children[0],
layout,
renderer,
operation,
);
});
Expand Down
25 changes: 24 additions & 1 deletion lazy/src/responsive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use iced_native::layout::{self, Layout};
use iced_native::mouse;
use iced_native::overlay;
use iced_native::renderer;
use iced_native::widget::horizontal_space;
use iced_native::widget::tree::{self, Tree};
use iced_native::widget::{self, horizontal_space};
use iced_native::{
Clipboard, Element, Length, Point, Rectangle, Shell, Size, Widget,
};
Expand Down Expand Up @@ -142,6 +142,29 @@ where
layout::Node::new(limits.max())
}

fn operate(
&self,
tree: &mut Tree,
layout: Layout<'_>,
renderer: &Renderer,
operation: &mut dyn widget::Operation<Message>,
) {
let state = tree.state.downcast_mut::<State>();
let mut content = self.content.borrow_mut();

content.resolve(
&mut state.tree.borrow_mut(),
renderer,
layout,
&self.view,
|tree, renderer, layout, element| {
element
.as_widget()
.operate(tree, layout, renderer, operation);
},
);
}

fn on_event(
&mut self,
tree: &mut Tree,
Expand Down
14 changes: 11 additions & 3 deletions native/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ where
&self,
tree: &mut Tree,
layout: Layout<'_>,
renderer: &Renderer,
operation: &mut dyn widget::Operation<B>,
) {
struct MapOperation<'a, B> {
Expand Down Expand Up @@ -334,8 +335,12 @@ where
}
}

self.widget
.operate(tree, layout, &mut MapOperation { operation });
self.widget.operate(
tree,
layout,
renderer,
&mut MapOperation { operation },
);
}

fn on_event(
Expand Down Expand Up @@ -473,9 +478,12 @@ where
&self,
state: &mut Tree,
layout: Layout<'_>,
renderer: &Renderer,
operation: &mut dyn widget::Operation<Message>,
) {
self.element.widget.operate(state, layout, operation)
self.element
.widget
.operate(state, layout, renderer, operation)
}

fn on_event(
Expand Down
22 changes: 8 additions & 14 deletions native/src/layout/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Limits {
}
Length::Units(units) => {
let new_width =
(units as f32).min(self.max.width).max(self.min.width);
(units as f32).clamp(self.min.width, self.max.width);

self.min.width = new_width;
self.max.width = new_width;
Expand All @@ -73,7 +73,7 @@ impl Limits {
}
Length::Units(units) => {
let new_height =
(units as f32).min(self.max.height).max(self.min.height);
(units as f32).clamp(self.min.height, self.max.height);

self.min.height = new_height;
self.max.height = new_height;
Expand All @@ -86,32 +86,30 @@ impl Limits {

/// Applies a minimum width constraint to the current [`Limits`].
pub fn min_width(mut self, min_width: u32) -> Limits {
self.min.width =
self.min.width.max(min_width as f32).min(self.max.width);
self.min.width = self.min.width.clamp(min_width as f32, self.max.width);

self
}

/// Applies a maximum width constraint to the current [`Limits`].
pub fn max_width(mut self, max_width: u32) -> Limits {
self.max.width =
self.max.width.min(max_width as f32).max(self.min.width);
self.max.width = self.max.width.clamp(self.min.width, max_width as f32);

self
}

/// Applies a minimum height constraint to the current [`Limits`].
pub fn min_height(mut self, min_height: u32) -> Limits {
self.min.height =
self.min.height.max(min_height as f32).min(self.max.height);
self.min.height.clamp(min_height as f32, self.max.height);

self
}

/// Applies a maximum height constraint to the current [`Limits`].
pub fn max_height(mut self, max_height: u32) -> Limits {
self.max.height =
self.max.height.min(max_height as f32).max(self.min.height);
self.max.height.clamp(self.min.height, max_height as f32);

self
}
Expand Down Expand Up @@ -157,14 +155,10 @@ impl Limits {
/// intrinsic size of some content.
pub fn resolve(&self, intrinsic_size: Size) -> Size {
Size::new(
intrinsic_size
.width
.min(self.max.width)
.max(self.fill.width),
intrinsic_size.width.clamp(self.fill.width, self.max.width),
intrinsic_size
.height
.min(self.max.height)
.max(self.fill.height),
.clamp(self.fill.height, self.max.height),
)
}
}
1 change: 1 addition & 0 deletions native/src/overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ where
fn operate(
&mut self,
_layout: Layout<'_>,
_renderer: &Renderer,
_operation: &mut dyn widget::Operation<Message>,
) {
}
Expand Down
Loading

0 comments on commit dbe008e

Please sign in to comment.