Skip to content

Commit

Permalink
Merge branch 'master' into shadows
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksenger committed Jul 16, 2023
2 parents 73c9b67 + fd07791 commit e1a9185
Show file tree
Hide file tree
Showing 39 changed files with 547 additions and 234 deletions.
9 changes: 6 additions & 3 deletions core/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ where
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, B>,
viewport: &Rectangle,
) -> event::Status {
let mut local_messages = Vec::new();
let mut local_shell = Shell::new(&mut local_messages);
Expand All @@ -392,6 +393,7 @@ where
renderer,
clipboard,
&mut local_shell,
viewport,
);

shell.merge(local_shell, &self.mapper);
Expand Down Expand Up @@ -511,10 +513,11 @@ where
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
viewport: &Rectangle,
) -> event::Status {
self.element
.widget
.on_event(state, event, layout, cursor, renderer, clipboard, shell)
self.element.widget.on_event(
state, event, layout, cursor, renderer, clipboard, shell, viewport,
)
}

fn draw(
Expand Down
1 change: 1 addition & 0 deletions core/src/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ where
_renderer: &Renderer,
_clipboard: &mut dyn Clipboard,
_shell: &mut Shell<'_, Message>,
_viewport: &Rectangle,
) -> event::Status {
event::Status::Ignored
}
Expand Down
1 change: 1 addition & 0 deletions examples/loading_spinners/src/circular.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ where
_renderer: &iced::Renderer<Theme>,
_clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
_viewport: &Rectangle,
) -> event::Status {
const FRAME_RATE: u64 = 60;

Expand Down
1 change: 1 addition & 0 deletions examples/loading_spinners/src/linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ where
_renderer: &Renderer,
_clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
_viewport: &Rectangle,
) -> event::Status {
const FRAME_RATE: u64 = 60;

Expand Down
3 changes: 3 additions & 0 deletions examples/modal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ mod modal {
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
viewport: &Rectangle,
) -> event::Status {
self.base.as_widget_mut().on_event(
&mut state.children[0],
Expand All @@ -309,6 +310,7 @@ mod modal {
renderer,
clipboard,
shell,
viewport,
)
}

Expand Down Expand Up @@ -446,6 +448,7 @@ mod modal {
renderer,
clipboard,
shell,
&layout.bounds(),
)
}

Expand Down
2 changes: 1 addition & 1 deletion examples/pokedex/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl Pokemon {
}

let id = {
let mut rng = rand::rngs::OsRng::default();
let mut rng = rand::rngs::OsRng;

rng.gen_range(0, Pokemon::TOTAL)
};
Expand Down
52 changes: 45 additions & 7 deletions examples/scrollable/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct ScrollableDemo {
scrollbar_margin: u16,
scroller_width: u16,
current_scroll_offset: scrollable::RelativeOffset,
alignment: scrollable::Alignment,
}

#[derive(Debug, Clone, Eq, PartialEq, Copy)]
Expand All @@ -32,6 +33,7 @@ enum Direction {
#[derive(Debug, Clone)]
enum Message {
SwitchDirection(Direction),
AlignmentChanged(scrollable::Alignment),
ScrollbarWidthChanged(u16),
ScrollbarMarginChanged(u16),
ScrollerWidthChanged(u16),
Expand All @@ -54,6 +56,7 @@ impl Application for ScrollableDemo {
scrollbar_margin: 0,
scroller_width: 10,
current_scroll_offset: scrollable::RelativeOffset::START,
alignment: scrollable::Alignment::Start,
},
Command::none(),
)
Expand All @@ -74,6 +77,15 @@ impl Application for ScrollableDemo {
self.current_scroll_offset,
)
}
Message::AlignmentChanged(alignment) => {
self.current_scroll_offset = scrollable::RelativeOffset::START;
self.alignment = alignment;

scrollable::snap_to(
SCROLLABLE_ID.clone(),
self.current_scroll_offset,
)
}
Message::ScrollbarWidthChanged(width) => {
self.scrollbar_width = width;

Expand Down Expand Up @@ -165,10 +177,33 @@ impl Application for ScrollableDemo {
.spacing(10)
.width(Length::Fill);

let scroll_controls =
row![scroll_slider_controls, scroll_orientation_controls]
.spacing(20)
.width(Length::Fill);
let scroll_alignment_controls = column(vec![
text("Scrollable alignment:").into(),
radio(
"Start",
scrollable::Alignment::Start,
Some(self.alignment),
Message::AlignmentChanged,
)
.into(),
radio(
"End",
scrollable::Alignment::End,
Some(self.alignment),
Message::AlignmentChanged,
)
.into(),
])
.spacing(10)
.width(Length::Fill);

let scroll_controls = row![
scroll_slider_controls,
scroll_orientation_controls,
scroll_alignment_controls
]
.spacing(20)
.width(Length::Fill);

let scroll_to_end_button = || {
button("Scroll to end")
Expand Down Expand Up @@ -204,7 +239,8 @@ impl Application for ScrollableDemo {
Properties::new()
.width(self.scrollbar_width)
.margin(self.scrollbar_margin)
.scroller_width(self.scroller_width),
.scroller_width(self.scroller_width)
.alignment(self.alignment),
))
.id(SCROLLABLE_ID.clone())
.on_scroll(Message::Scrolled),
Expand All @@ -228,7 +264,8 @@ impl Application for ScrollableDemo {
Properties::new()
.width(self.scrollbar_width)
.margin(self.scrollbar_margin)
.scroller_width(self.scroller_width),
.scroller_width(self.scroller_width)
.alignment(self.alignment),
))
.style(theme::Scrollable::custom(ScrollbarCustomStyle))
.id(SCROLLABLE_ID.clone())
Expand Down Expand Up @@ -269,7 +306,8 @@ impl Application for ScrollableDemo {
let properties = Properties::new()
.width(self.scrollbar_width)
.margin(self.scrollbar_margin)
.scroller_width(self.scroller_width);
.scroller_width(self.scroller_width)
.alignment(self.alignment);

scrollable::Direction::Both {
horizontal: properties,
Expand Down
5 changes: 5 additions & 0 deletions examples/toast/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ mod toast {
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
viewport: &Rectangle,
) -> event::Status {
self.content.as_widget_mut().on_event(
&mut state.children[0],
Expand All @@ -409,6 +410,7 @@ mod toast {
renderer,
clipboard,
shell,
viewport,
)
}

Expand Down Expand Up @@ -559,6 +561,8 @@ mod toast {
}
}

let viewport = layout.bounds();

self.toasts
.iter_mut()
.zip(self.state.iter_mut())
Expand All @@ -576,6 +580,7 @@ mod toast {
renderer,
clipboard,
&mut local_shell,
&viewport,
);

if !local_shell.is_empty() {
Expand Down
3 changes: 3 additions & 0 deletions runtime/src/user_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ where
(cursor, vec![event::Status::Ignored; events.len()])
};

let viewport = Rectangle::with_size(self.bounds);

let _ = ManuallyDrop::into_inner(manual_overlay);

let event_statuses = events
Expand All @@ -305,6 +307,7 @@ where
renderer,
clipboard,
&mut shell,
&viewport,
);

if matches!(event_status, event::Status::Captured) {
Expand Down
4 changes: 2 additions & 2 deletions tiny_skia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ geometry = ["iced_graphics/geometry"]
[dependencies]
raw-window-handle = "0.5"
softbuffer = "0.2"
tiny-skia = "0.9"
tiny-skia = "0.10"
bytemuck = "1"
rustc-hash = "1.1"
kurbo = "0.9"
Expand All @@ -34,5 +34,5 @@ version = "1.6.1"
features = ["std"]

[dependencies.resvg]
version = "0.32"
version = "0.35"
optional = true
10 changes: 9 additions & 1 deletion tiny_skia/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,15 @@ fn adjust_clip_mask(clip_mask: &mut tiny_skia::Mask, bounds: Rectangle) {

let path = {
let mut builder = tiny_skia::PathBuilder::new();
builder.push_rect(bounds.x, bounds.y, bounds.width, bounds.height);
builder.push_rect(
tiny_skia::Rect::from_xywh(
bounds.x,
bounds.y,
bounds.width,
bounds.height,
)
.unwrap(),
);

builder.finish().unwrap()
};
Expand Down
6 changes: 3 additions & 3 deletions tiny_skia/src/raster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ impl Cache {
for (i, pixel) in image.pixels().enumerate() {
let [r, g, b, a] = pixel.0;

buffer[i] = tiny_skia::ColorU8::from_rgba(b, g, r, a)
.premultiply()
.get();
buffer[i] = bytemuck::cast(
tiny_skia::ColorU8::from_rgba(b, g, r, a).premultiply(),
);
}

entry.insert(Some(Entry {
Expand Down
34 changes: 18 additions & 16 deletions tiny_skia/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,15 @@ impl GlyphCache {

for _y in 0..image.placement.height {
for _x in 0..image.placement.width {
buffer[i] = tiny_skia::ColorU8::from_rgba(
b,
g,
r,
image.data[i],
)
.premultiply()
.get();
buffer[i] = bytemuck::cast(
tiny_skia::ColorU8::from_rgba(
b,
g,
r,
image.data[i],
)
.premultiply(),
);

i += 1;
}
Expand All @@ -307,14 +308,15 @@ impl GlyphCache {
for _y in 0..image.placement.height {
for _x in 0..image.placement.width {
// TODO: Blend alpha
buffer[i >> 2] = tiny_skia::ColorU8::from_rgba(
image.data[i + 2],
image.data[i + 1],
image.data[i],
image.data[i + 3],
)
.premultiply()
.get();
buffer[i >> 2] = bytemuck::cast(
tiny_skia::ColorU8::from_rgba(
image.data[i + 2],
image.data[i + 1],
image.data[i],
image.data[i + 3],
)
.premultiply(),
);

i += 4;
}
Expand Down
Loading

0 comments on commit e1a9185

Please sign in to comment.