Rename fill_rectangle to fill_quad in Renderer

This commit is contained in:
Héctor Ramón Jiménez 2021-11-04 19:22:29 +07:00
parent 343f9b7e2e
commit 023aded277
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
19 changed files with 320 additions and 245 deletions

View file

@ -293,28 +293,32 @@ where
if styling.background.is_some() || styling.border_width > 0.0 {
if styling.shadow_offset != Vector::default() {
// TODO: Implement proper shadow support
renderer.fill_rectangle(renderer::Quad {
bounds: Rectangle {
x: bounds.x + styling.shadow_offset.x,
y: bounds.y + styling.shadow_offset.y,
..bounds
renderer.fill_quad(
renderer::Quad {
bounds: Rectangle {
x: bounds.x + styling.shadow_offset.x,
y: bounds.y + styling.shadow_offset.y,
..bounds
},
border_radius: styling.border_radius,
border_width: 0.0,
border_color: Color::TRANSPARENT,
},
background: Background::Color([0.0, 0.0, 0.0, 0.5].into()),
border_radius: styling.border_radius,
border_width: 0.0,
border_color: Color::TRANSPARENT,
});
Background::Color([0.0, 0.0, 0.0, 0.5].into()),
);
}
renderer.fill_rectangle(renderer::Quad {
bounds,
background: styling
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: styling.border_radius,
border_width: styling.border_width,
border_color: styling.border_color,
},
styling
.background
.unwrap_or(Background::Color(Color::TRANSPARENT)),
border_radius: styling.border_radius,
border_width: styling.border_width,
border_color: styling.border_color,
});
);
}
self.content.draw(

View file

@ -226,13 +226,15 @@ where
self.style_sheet.active(self.is_checked)
};
renderer.fill_rectangle(renderer::Quad {
bounds,
background: style.background,
border_radius: style.border_radius,
border_width: style.border_width,
border_color: style.border_color,
});
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: style.border_radius,
border_width: style.border_width,
border_color: style.border_color,
},
style.background,
);
if self.is_checked {
renderer.fill_text(text::Text {

View file

@ -238,6 +238,7 @@ where
}
}
/// Draws the background of a [`Container`] given its [`Style`] and its `bounds`.
pub fn draw_background<Renderer>(
renderer: &mut Renderer,
style: &Style,
@ -246,15 +247,17 @@ pub fn draw_background<Renderer>(
Renderer: crate::Renderer,
{
if style.background.is_some() || style.border_width > 0.0 {
renderer.fill_rectangle(renderer::Quad {
bounds,
background: style
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: style.border_radius,
border_width: style.border_width,
border_color: style.border_color,
},
style
.background
.unwrap_or(Background::Color(Color::TRANSPARENT)),
border_radius: style.border_radius,
border_width: style.border_width,
border_color: style.border_color,
});
);
}
}

View file

@ -609,31 +609,34 @@ where
};
if let Some(highlight) = highlight {
renderer.fill_rectangle(renderer::Quad {
bounds: match axis {
Axis::Horizontal => Rectangle {
x: split_region.x,
y: (split_region.y
+ (split_region.height - highlight.width)
/ 2.0)
.round(),
width: split_region.width,
height: highlight.width,
},
Axis::Vertical => Rectangle {
x: (split_region.x
+ (split_region.width - highlight.width) / 2.0)
.round(),
y: split_region.y,
width: highlight.width,
height: split_region.height,
renderer.fill_quad(
renderer::Quad {
bounds: match axis {
Axis::Horizontal => Rectangle {
x: split_region.x,
y: (split_region.y
+ (split_region.height - highlight.width)
/ 2.0)
.round(),
width: split_region.width,
height: highlight.width,
},
Axis::Vertical => Rectangle {
x: (split_region.x
+ (split_region.width - highlight.width)
/ 2.0)
.round(),
y: split_region.y,
width: highlight.width,
height: split_region.height,
},
},
border_radius: 0.0,
border_width: 0.0,
border_color: Color::TRANSPARENT,
},
background: highlight.color.into(),
border_radius: 0.0,
border_width: 0.0,
border_color: Color::TRANSPARENT,
});
highlight.color,
);
}
}
}

View file

@ -360,13 +360,15 @@ where
self.style_sheet.active()
};
renderer.fill_rectangle(renderer::Quad {
bounds,
background: style.background,
border_color: style.border_color,
border_width: style.border_width,
border_radius: style.border_radius,
});
renderer.fill_quad(
renderer::Quad {
bounds,
border_color: style.border_color,
border_width: style.border_width,
border_radius: style.border_radius,
},
style.background,
);
renderer.fill_text(Text {
content: &Renderer::ARROW_DOWN_ICON.to_string(),

View file

@ -116,25 +116,29 @@ where
let style = self.style_sheet.style();
renderer.fill_rectangle(renderer::Quad {
bounds: Rectangle { ..bounds },
background: style.background,
border_radius: style.border_radius,
border_width: 0.0,
border_color: Color::TRANSPARENT,
});
if active_progress_width > 0.0 {
renderer.fill_rectangle(renderer::Quad {
bounds: Rectangle {
width: active_progress_width,
..bounds
},
background: style.bar,
renderer.fill_quad(
renderer::Quad {
bounds: Rectangle { ..bounds },
border_radius: style.border_radius,
border_width: 0.0,
border_color: Color::TRANSPARENT,
});
},
style.background,
);
if active_progress_width > 0.0 {
renderer.fill_quad(
renderer::Quad {
bounds: Rectangle {
width: active_progress_width,
..bounds
},
border_radius: style.border_radius,
border_width: 0.0,
border_color: Color::TRANSPARENT,
},
style.bar,
);
}
}

View file

@ -10,8 +10,8 @@ use crate::text;
use crate::touch;
use crate::widget::{self, Row, Text};
use crate::{
Alignment, Background, Clipboard, Color, Element, Hasher, Layout, Length,
Point, Rectangle, Widget,
Alignment, Clipboard, Color, Element, Hasher, Layout, Length, Point,
Rectangle, Widget,
};
pub use iced_style::radio::{Style, StyleSheet};
@ -243,27 +243,31 @@ where
self.style_sheet.active()
};
renderer.fill_rectangle(renderer::Quad {
bounds,
background: style.background,
border_radius: size / 2.0,
border_width: style.border_width,
border_color: style.border_color,
});
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: size / 2.0,
border_width: style.border_width,
border_color: style.border_color,
},
style.background,
);
if self.is_selected {
renderer.fill_rectangle(renderer::Quad {
bounds: Rectangle {
x: bounds.x + dot_size / 2.0,
y: bounds.y + dot_size / 2.0,
width: bounds.width - dot_size,
height: bounds.height - dot_size,
renderer.fill_quad(
renderer::Quad {
bounds: Rectangle {
x: bounds.x + dot_size / 2.0,
y: bounds.y + dot_size / 2.0,
width: bounds.width - dot_size,
height: bounds.height - dot_size,
},
border_radius: dot_size / 2.0,
border_width: 0.0,
border_color: Color::TRANSPARENT,
},
background: Background::Color(style.dot_color),
border_radius: dot_size / 2.0,
border_width: 0.0,
border_color: Color::TRANSPARENT,
});
style.dot_color,
);
}
}

View file

@ -2,8 +2,7 @@
use crate::layout;
use crate::renderer;
use crate::{
Background, Color, Element, Hasher, Layout, Length, Point, Rectangle, Size,
Widget,
Color, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget,
};
use std::hash::Hash;
@ -113,13 +112,15 @@ where
}
};
renderer.fill_rectangle(renderer::Quad {
bounds,
background: Background::Color(style.color),
border_radius: style.radius,
border_width: 0.0,
border_color: Color::TRANSPARENT,
});
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: style.radius,
border_width: 0.0,
border_color: Color::TRANSPARENT,
},
style.color,
);
}
fn hash_layout(&self, state: &mut Hasher) {

View file

@ -526,28 +526,32 @@ where
},
|renderer| {
if is_scrollbar_visible {
renderer.fill_rectangle(renderer::Quad {
bounds: scrollbar.bounds,
background: style.background.unwrap_or(
Background::Color(Color::TRANSPARENT),
),
border_radius: style.border_radius,
border_width: style.border_width,
border_color: style.border_color,
});
renderer.fill_quad(
renderer::Quad {
bounds: scrollbar.bounds,
border_radius: style.border_radius,
border_width: style.border_width,
border_color: style.border_color,
},
style.background.unwrap_or(Background::Color(
Color::TRANSPARENT,
)),
);
}
if is_mouse_over
|| self.state.is_scroller_grabbed()
|| is_scrollbar_visible
{
renderer.fill_rectangle(renderer::Quad {
bounds: scrollbar.scroller.bounds,
background: Background::Color(style.scroller.color),
border_radius: style.scroller.border_radius,
border_width: style.scroller.border_width,
border_color: style.scroller.border_color,
});
renderer.fill_quad(
renderer::Quad {
bounds: scrollbar.scroller.bounds,
border_radius: style.scroller.border_radius,
border_width: style.scroller.border_width,
border_color: style.scroller.border_color,
},
style.scroller.color,
);
}
},
);

View file

@ -58,6 +58,7 @@ where
T: Copy + From<u8> + std::cmp::PartialOrd,
Message: Clone,
{
/// The default height of a [`Slider`].
pub const DEFAULT_HEIGHT: u16 = 22;
/// Creates a new [`Slider`].
@ -272,31 +273,35 @@ where
let rail_y = bounds.y + (bounds.height / 2.0).round();
renderer.fill_rectangle(renderer::Quad {
bounds: Rectangle {
x: bounds.x,
y: rail_y,
width: bounds.width,
height: 2.0,
renderer.fill_quad(
renderer::Quad {
bounds: Rectangle {
x: bounds.x,
y: rail_y,
width: bounds.width,
height: 2.0,
},
border_radius: 0.0,
border_width: 0.0,
border_color: Color::TRANSPARENT,
},
background: Background::Color(style.rail_colors.0),
border_radius: 0.0,
border_width: 0.0,
border_color: Color::TRANSPARENT,
});
style.rail_colors.0,
);
renderer.fill_rectangle(renderer::Quad {
bounds: Rectangle {
x: bounds.x,
y: rail_y + 2.0,
width: bounds.width,
height: 2.0,
renderer.fill_quad(
renderer::Quad {
bounds: Rectangle {
x: bounds.x,
y: rail_y + 2.0,
width: bounds.width,
height: 2.0,
},
border_radius: 0.0,
border_width: 0.0,
border_color: Color::TRANSPARENT,
},
background: Background::Color(style.rail_colors.1),
border_radius: 0.0,
border_width: 0.0,
border_color: Color::TRANSPARENT,
});
Background::Color(style.rail_colors.1),
);
let (handle_width, handle_height, handle_border_radius) = match style
.handle
@ -325,18 +330,20 @@ where
/ (range_end - range_start)
};
renderer.fill_rectangle(renderer::Quad {
bounds: Rectangle {
x: bounds.x + handle_offset.round(),
y: rail_y - handle_height / 2.0,
width: handle_width,
height: handle_height,
renderer.fill_quad(
renderer::Quad {
bounds: Rectangle {
x: bounds.x + handle_offset.round(),
y: rail_y - handle_height / 2.0,
width: handle_width,
height: handle_height,
},
border_radius: handle_border_radius,
border_width: style.handle.border_width,
border_color: style.handle.border_color,
},
background: Background::Color(style.handle.color),
border_radius: handle_border_radius,
border_width: style.handle.border_width,
border_color: style.handle.border_color,
});
style.handle.color,
);
}
fn mouse_interaction(

View file

@ -163,6 +163,16 @@ where
}
}
/// Draws text using the same logic as the [`Text`] widget.
///
/// Specifically:
///
/// * If no `size` is provided, the default text size of the `Renderer` will be
/// used.
/// * If no `color` is provided, the [`renderer::Style::text_color`] will be
/// used.
/// * The alignment attributes do not affect the position of the bounds of the
/// [`Layout`].
pub fn draw<Renderer>(
renderer: &mut Renderer,
style: &renderer::Style,

View file

@ -20,8 +20,8 @@ use crate::renderer;
use crate::text::{self, Text};
use crate::touch;
use crate::{
Background, Clipboard, Color, Element, Hasher, Layout, Length, Padding,
Point, Rectangle, Size, Vector, Widget,
Clipboard, Color, Element, Hasher, Layout, Length, Padding, Point,
Rectangle, Size, Vector, Widget,
};
use std::u32;
@ -196,13 +196,15 @@ where
self.style_sheet.active()
};
renderer.fill_rectangle(renderer::Quad {
bounds,
background: style.background,
border_radius: style.border_radius,
border_width: style.border_width,
border_color: style.border_color,
});
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: style.border_radius,
border_width: style.border_width,
border_color: style.border_color,
},
style.background,
);
let text = value.to_string();
let size = self.size.unwrap_or(renderer.default_size());
@ -221,20 +223,20 @@ where
);
(
Some(renderer::Quad {
bounds: Rectangle {
x: text_bounds.x + text_value_width,
y: text_bounds.y,
width: 1.0,
height: text_bounds.height,
Some((
renderer::Quad {
bounds: Rectangle {
x: text_bounds.x + text_value_width,
y: text_bounds.y,
width: 1.0,
height: text_bounds.height,
},
border_radius: 0.0,
border_width: 0.0,
border_color: Color::TRANSPARENT,
},
background: Background::Color(
self.style_sheet.value_color(),
),
border_radius: 0.0,
border_width: 0.0,
border_color: Color::TRANSPARENT,
}),
self.style_sheet.value_color(),
)),
offset,
)
}
@ -265,20 +267,20 @@ where
let width = right_position - left_position;
(
Some(renderer::Quad {
bounds: Rectangle {
x: text_bounds.x + left_position,
y: text_bounds.y,
width,
height: text_bounds.height,
Some((
renderer::Quad {
bounds: Rectangle {
x: text_bounds.x + left_position,
y: text_bounds.y,
width,
height: text_bounds.height,
},
border_radius: 0.0,
border_width: 0.0,
border_color: Color::TRANSPARENT,
},
background: Background::Color(
self.style_sheet.selection_color(),
),
border_radius: 0.0,
border_width: 0.0,
border_color: Color::TRANSPARENT,
}),
self.style_sheet.selection_color(),
)),
if end == right {
right_offset
} else {
@ -302,8 +304,8 @@ where
);
let render = |renderer: &mut Renderer| {
if let Some(cursor) = cursor {
renderer.fill_rectangle(cursor);
if let Some((cursor, color)) = cursor {
renderer.fill_quad(cursor, color);
}
renderer.fill_text(Text {

View file

@ -258,13 +258,17 @@ where
height: bounds.height - (2.0 * space),
};
renderer.fill_rectangle(renderer::Quad {
bounds: toggler_background_bounds,
background: style.background.into(),
border_radius,
border_width: 1.0,
border_color: style.background_border.unwrap_or(style.background),
});
renderer.fill_quad(
renderer::Quad {
bounds: toggler_background_bounds,
border_radius,
border_width: 1.0,
border_color: style
.background_border
.unwrap_or(style.background),
},
style.background,
);
let toggler_foreground_bounds = Rectangle {
x: bounds.x
@ -278,13 +282,17 @@ where
height: bounds.height - (4.0 * space),
};
renderer.fill_rectangle(renderer::Quad {
bounds: toggler_foreground_bounds,
background: style.foreground.into(),
border_radius,
border_width: 1.0,
border_color: style.foreground_border.unwrap_or(style.foreground),
});
renderer.fill_quad(
renderer::Quad {
bounds: toggler_foreground_bounds,
border_radius,
border_width: 1.0,
border_color: style
.foreground_border
.unwrap_or(style.foreground),
},
style.foreground,
);
}
fn hash_layout(&self, state: &mut Hasher) {