fix: bounds for button
This commit is contained in:
parent
59407552b6
commit
722f30c724
1 changed files with 19 additions and 20 deletions
|
|
@ -338,9 +338,12 @@ impl<'a, Message: 'a + Clone> Widget<Message, crate::Theme, crate::Renderer>
|
||||||
renderer_style: &renderer::Style,
|
renderer_style: &renderer::Style,
|
||||||
layout: Layout<'_>,
|
layout: Layout<'_>,
|
||||||
cursor: mouse::Cursor,
|
cursor: mouse::Cursor,
|
||||||
_viewport: &Rectangle,
|
viewport: &Rectangle,
|
||||||
) {
|
) {
|
||||||
let bounds = layout.bounds();
|
let bounds = layout.bounds();
|
||||||
|
if !viewport.intersects(&bounds) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let content_layout = layout.children().next().unwrap();
|
let content_layout = layout.children().next().unwrap();
|
||||||
|
|
||||||
let mut headerbar_alpha = None;
|
let mut headerbar_alpha = None;
|
||||||
|
|
@ -391,6 +394,7 @@ impl<'a, Message: 'a + Clone> Widget<Message, crate::Theme, crate::Renderer>
|
||||||
draw::<_, crate::Theme>(
|
draw::<_, crate::Theme>(
|
||||||
renderer,
|
renderer,
|
||||||
bounds,
|
bounds,
|
||||||
|
*viewport,
|
||||||
&styling,
|
&styling,
|
||||||
|renderer, _styling| {
|
|renderer, _styling| {
|
||||||
self.content.as_widget().draw(
|
self.content.as_widget().draw(
|
||||||
|
|
@ -404,7 +408,7 @@ impl<'a, Message: 'a + Clone> Widget<Message, crate::Theme, crate::Renderer>
|
||||||
},
|
},
|
||||||
content_layout,
|
content_layout,
|
||||||
cursor,
|
cursor,
|
||||||
&bounds,
|
viewport,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
matches!(self.variant, Variant::Image { .. }),
|
matches!(self.variant, Variant::Image { .. }),
|
||||||
|
|
@ -415,12 +419,7 @@ impl<'a, Message: 'a + Clone> Widget<Message, crate::Theme, crate::Renderer>
|
||||||
on_remove,
|
on_remove,
|
||||||
} = &self.variant
|
} = &self.variant
|
||||||
{
|
{
|
||||||
let mut parent_bounds = bounds;
|
renderer.with_layer(*viewport, |renderer| {
|
||||||
parent_bounds.y -= 8.0;
|
|
||||||
parent_bounds.width += 16.0;
|
|
||||||
parent_bounds.height += 16.0;
|
|
||||||
|
|
||||||
renderer.with_layer(parent_bounds, |renderer| {
|
|
||||||
let selection_background = theme.selection_background();
|
let selection_background = theme.selection_background();
|
||||||
|
|
||||||
let c_rad = THEME.lock().unwrap().cosmic().corner_radii;
|
let c_rad = THEME.lock().unwrap().cosmic().corner_radii;
|
||||||
|
|
@ -472,16 +471,15 @@ impl<'a, Message: 'a + Clone> Widget<Message, crate::Theme, crate::Renderer>
|
||||||
|
|
||||||
let svg_handle = svg::Svg::new(crate::widget::common::object_select().clone())
|
let svg_handle = svg::Svg::new(crate::widget::common::object_select().clone())
|
||||||
.color(icon_color);
|
.color(icon_color);
|
||||||
iced_core::svg::Renderer::draw_svg(
|
let bounds = Rectangle {
|
||||||
renderer,
|
width: 16.0,
|
||||||
svg_handle,
|
height: 16.0,
|
||||||
Rectangle {
|
x: bounds.x + 5.0 + styling.border_width,
|
||||||
width: 16.0,
|
y: bounds.y + (bounds.height - 18.0 - styling.border_width),
|
||||||
height: 16.0,
|
};
|
||||||
x: bounds.x + 5.0 + styling.border_width,
|
if bounds.intersects(viewport) {
|
||||||
y: bounds.y + (bounds.height - 18.0 - styling.border_width),
|
iced_core::svg::Renderer::draw_svg(renderer, svg_handle, bounds);
|
||||||
},
|
}
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if on_remove.is_some() {
|
if on_remove.is_some() {
|
||||||
|
|
@ -535,7 +533,7 @@ impl<'a, Message: 'a + Clone> Widget<Message, crate::Theme, crate::Renderer>
|
||||||
renderer: &crate::Renderer,
|
renderer: &crate::Renderer,
|
||||||
mut translation: Vector,
|
mut translation: Vector,
|
||||||
) -> Option<overlay::Element<'b, Message, crate::Theme, crate::Renderer>> {
|
) -> Option<overlay::Element<'b, Message, crate::Theme, crate::Renderer>> {
|
||||||
let mut position = layout.bounds().position();
|
let position = layout.bounds().position();
|
||||||
translation.x += position.x;
|
translation.x += position.x;
|
||||||
translation.y += position.y;
|
translation.y += position.y;
|
||||||
self.content.as_widget_mut().overlay(
|
self.content.as_widget_mut().overlay(
|
||||||
|
|
@ -753,6 +751,7 @@ pub fn update<'a, Message: Clone>(
|
||||||
pub fn draw<Renderer: iced_core::Renderer, Theme>(
|
pub fn draw<Renderer: iced_core::Renderer, Theme>(
|
||||||
renderer: &mut Renderer,
|
renderer: &mut Renderer,
|
||||||
bounds: Rectangle,
|
bounds: Rectangle,
|
||||||
|
viewport_bounds: Rectangle,
|
||||||
styling: &super::style::Style,
|
styling: &super::style::Style,
|
||||||
draw_contents: impl FnOnce(&mut Renderer, &Style),
|
draw_contents: impl FnOnce(&mut Renderer, &Style),
|
||||||
is_image: bool,
|
is_image: bool,
|
||||||
|
|
@ -836,7 +835,7 @@ pub fn draw<Renderer: iced_core::Renderer, Theme>(
|
||||||
// Then draw the button contents onto the background.
|
// Then draw the button contents onto the background.
|
||||||
draw_contents(renderer, styling);
|
draw_contents(renderer, styling);
|
||||||
|
|
||||||
let mut clipped_bounds = bounds;
|
let mut clipped_bounds = viewport_bounds;
|
||||||
clipped_bounds.height += styling.border_width;
|
clipped_bounds.height += styling.border_width;
|
||||||
|
|
||||||
renderer.with_layer(clipped_bounds, |renderer| {
|
renderer.with_layer(clipped_bounds, |renderer| {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue