Introduce Border struct analogous to Shadow

This commit is contained in:
Héctor Ramón Jiménez 2024-01-20 13:29:25 +01:00
parent 4d502012b3
commit 25f182f933
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
44 changed files with 382 additions and 424 deletions

View file

@ -11,7 +11,7 @@ use crate::core::widget::tree::{self, Tree};
use crate::core::widget::Operation;
use crate::core::{
Background, Clipboard, Color, Element, Layout, Length, Padding, Rectangle,
Shell, Size, Vector, Widget,
Shell, Size, Widget,
};
pub use iced_style::button::{Appearance, StyleSheet};
@ -391,29 +391,11 @@ where
style_sheet.active(style)
};
if styling.background.is_some() || styling.border_width > 0.0 {
if styling.shadow_offset != Vector::default() {
// TODO: Implement proper shadow support
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,
..renderer::Quad::default()
},
Background::Color([0.0, 0.0, 0.0, 0.5].into()),
);
}
if styling.background.is_some() || styling.border.width > 0.0 {
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: styling.border_radius,
border_width: styling.border_width,
border_color: styling.border_color,
border: styling.border,
..renderer::Quad::default()
},
styling

View file

@ -284,9 +284,7 @@ where
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: custom_style.border_radius,
border_width: custom_style.border_width,
border_color: custom_style.border_color,
border: custom_style.border,
..renderer::Quad::default()
},
custom_style.background,

View file

@ -337,13 +337,11 @@ pub fn draw_background<Renderer>(
) where
Renderer: crate::core::Renderer,
{
if appearance.background.is_some() || appearance.border_width > 0.0 {
if appearance.background.is_some() || appearance.border.width > 0.0 {
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: appearance.border_radius,
border_width: appearance.border_width,
border_color: appearance.border_color,
border: appearance.border,
..renderer::Quad::default()
},
appearance

View file

@ -10,7 +10,7 @@ use crate::core::text::{self, Text};
use crate::core::touch;
use crate::core::widget::Tree;
use crate::core::{
Clipboard, Length, Padding, Pixels, Point, Rectangle, Size, Vector,
Border, Clipboard, Length, Padding, Pixels, Point, Rectangle, Size, Vector,
};
use crate::core::{Element, Shell, Widget};
use crate::scrollable::{self, Scrollable};
@ -306,9 +306,7 @@ where
renderer.fill_quad(
renderer::Quad {
bounds,
border_color: appearance.border_color,
border_width: appearance.border_width,
border_radius: appearance.border_radius,
border: appearance.border,
..renderer::Quad::default()
},
appearance.background,
@ -513,11 +511,11 @@ where
renderer.fill_quad(
renderer::Quad {
bounds: Rectangle {
x: bounds.x + appearance.border_width,
width: bounds.width - appearance.border_width * 2.0,
x: bounds.x + appearance.border.width,
width: bounds.width - appearance.border.width * 2.0,
..bounds
},
border_radius: appearance.border_radius,
border: Border::with_radius(appearance.border.radius),
..renderer::Quad::default()
},
appearance.selected_background,

View file

@ -917,10 +917,7 @@ pub fn draw<Renderer, T>(
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: hovered_region_style
.border_radius,
border_width: hovered_region_style.border_width,
border_color: hovered_region_style.border_color,
border: hovered_region_style.border,
..renderer::Quad::default()
},
theme.hovered_region(style).background,
@ -948,9 +945,7 @@ pub fn draw<Renderer, T>(
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: hovered_region_style.border_radius,
border_width: hovered_region_style.border_width,
border_color: hovered_region_style.border_color,
border: hovered_region_style.border,
..renderer::Quad::default()
},
theme.hovered_region(style).background,

View file

@ -653,9 +653,7 @@ pub fn draw<'a, T, Renderer>(
renderer.fill_quad(
renderer::Quad {
bounds,
border_color: style.border_color,
border_width: style.border_width,
border_radius: style.border_radius,
border: style.border,
..renderer::Quad::default()
},
style.background,

View file

@ -3,7 +3,7 @@ use crate::core::layout;
use crate::core::mouse;
use crate::core::renderer;
use crate::core::widget::Tree;
use crate::core::{Element, Layout, Length, Rectangle, Size, Widget};
use crate::core::{Border, Element, Layout, Length, Rectangle, Size, Widget};
use std::ops::RangeInclusive;
@ -130,7 +130,7 @@ where
renderer.fill_quad(
renderer::Quad {
bounds: Rectangle { ..bounds },
border_radius: style.border_radius,
border: Border::with_radius(style.border_radius),
..renderer::Quad::default()
},
style.background,
@ -143,7 +143,7 @@ where
width: active_progress_width,
..bounds
},
border_radius: style.border_radius,
border: Border::with_radius(style.border_radius),
..renderer::Quad::default()
},
style.bar,

View file

@ -9,7 +9,8 @@ use crate::core::touch;
use crate::core::widget;
use crate::core::widget::tree::{self, Tree};
use crate::core::{
Clipboard, Element, Layout, Length, Pixels, Rectangle, Shell, Size, Widget,
Border, Clipboard, Element, Layout, Length, Pixels, Rectangle, Shell, Size,
Widget,
};
pub use iced_style::radio::{Appearance, StyleSheet};
@ -311,9 +312,11 @@ where
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: (size / 2.0).into(),
border_width: custom_style.border_width,
border_color: custom_style.border_color,
border: Border {
radius: (size / 2.0).into(),
width: custom_style.border_width,
color: custom_style.border_color,
},
..renderer::Quad::default()
},
custom_style.background,
@ -328,7 +331,7 @@ where
width: bounds.width - dot_size,
height: bounds.height - dot_size,
},
border_radius: (dot_size / 2.0).into(),
border: Border::with_radius(dot_size / 2.0),
..renderer::Quad::default()
},
custom_style.dot_color,

View file

@ -3,7 +3,9 @@ use crate::core::layout;
use crate::core::mouse;
use crate::core::renderer;
use crate::core::widget::Tree;
use crate::core::{Element, Layout, Length, Pixels, Rectangle, Size, Widget};
use crate::core::{
Border, Element, Layout, Length, Pixels, Rectangle, Size, Widget,
};
pub use crate::style::rule::{Appearance, FillMode, StyleSheet};
@ -122,7 +124,7 @@ where
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: style.radius,
border: Border::with_radius(style.radius),
..renderer::Quad::default()
},
style.color,

View file

@ -903,15 +903,13 @@ pub fn draw<Renderer>(
if scrollbar.bounds.width > 0.0
&& scrollbar.bounds.height > 0.0
&& (style.background.is_some()
|| (style.border_color != Color::TRANSPARENT
&& style.border_width > 0.0))
|| (style.border.color != Color::TRANSPARENT
&& style.border.width > 0.0))
{
renderer.fill_quad(
renderer::Quad {
bounds: scrollbar.bounds,
border_radius: style.border_radius,
border_width: style.border_width,
border_color: style.border_color,
border: style.border,
..renderer::Quad::default()
},
style
@ -924,15 +922,13 @@ pub fn draw<Renderer>(
if scrollbar.scroller.bounds.width > 0.0
&& scrollbar.scroller.bounds.height > 0.0
&& (style.scroller.color != Color::TRANSPARENT
|| (style.scroller.border_color != Color::TRANSPARENT
&& style.scroller.border_width > 0.0))
|| (style.scroller.border.color != Color::TRANSPARENT
&& style.scroller.border.width > 0.0))
{
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,
border: style.scroller.border,
..renderer::Quad::default()
},
style.scroller.color,

View file

@ -8,8 +8,8 @@ use crate::core::renderer;
use crate::core::touch;
use crate::core::widget::tree::{self, Tree};
use crate::core::{
Clipboard, Element, Layout, Length, Pixels, Point, Rectangle, Shell, Size,
Widget,
Border, Clipboard, Element, Layout, Length, Pixels, Point, Rectangle,
Shell, Size, Widget,
};
use std::ops::RangeInclusive;
@ -398,7 +398,7 @@ pub fn draw<T, R>(
width: offset + handle_width / 2.0,
height: style.rail.width,
},
border_radius: style.rail.border_radius,
border: Border::with_radius(style.rail.border_radius),
..renderer::Quad::default()
},
style.rail.colors.0,
@ -412,7 +412,7 @@ pub fn draw<T, R>(
width: bounds.width - offset - handle_width / 2.0,
height: style.rail.width,
},
border_radius: style.rail.border_radius,
border: Border::with_radius(style.rail.border_radius),
..renderer::Quad::default()
},
style.rail.colors.1,
@ -426,9 +426,11 @@ pub fn draw<T, R>(
width: handle_width,
height: handle_height,
},
border_radius: handle_border_radius,
border_width: style.handle.border_width,
border_color: style.handle.border_color,
border: Border {
radius: handle_border_radius,
width: style.handle.border_width,
color: style.handle.border_color,
},
..renderer::Quad::default()
},
style.handle.color,

View file

@ -466,9 +466,7 @@ where
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: appearance.border_radius,
border_width: appearance.border_width,
border_color: appearance.border_color,
border: appearance.border,
..renderer::Quad::default()
},
appearance.background,

View file

@ -1082,9 +1082,7 @@ pub fn draw<Renderer>(
renderer.fill_quad(
renderer::Quad {
bounds,
border_radius: appearance.border_radius,
border_width: appearance.border_width,
border_color: appearance.border_color,
border: appearance.border,
..renderer::Quad::default()
},
appearance.background,

View file

@ -9,8 +9,8 @@ use crate::core::touch;
use crate::core::widget;
use crate::core::widget::tree::{self, Tree};
use crate::core::{
Clipboard, Element, Event, Layout, Length, Pixels, Rectangle, Shell, Size,
Widget,
Border, Clipboard, Element, Event, Layout, Length, Pixels, Rectangle,
Shell, Size, Widget,
};
pub use crate::style::toggler::{Appearance, StyleSheet};
@ -312,11 +312,11 @@ where
renderer.fill_quad(
renderer::Quad {
bounds: toggler_background_bounds,
border_radius: border_radius.into(),
border_width: 1.0,
border_color: style
.background_border
.unwrap_or(style.background),
border: Border {
radius: border_radius.into(),
width: 1.0,
color: style.background_border.unwrap_or(style.background),
},
..renderer::Quad::default()
},
style.background,
@ -337,11 +337,11 @@ where
renderer.fill_quad(
renderer::Quad {
bounds: toggler_foreground_bounds,
border_radius: border_radius.into(),
border_width: 1.0,
border_color: style
.foreground_border
.unwrap_or(style.foreground),
border: Border {
radius: border_radius.into(),
width: 1.0,
color: style.foreground_border.unwrap_or(style.foreground),
},
..renderer::Quad::default()
},
style.foreground,

View file

@ -13,7 +13,8 @@ use crate::core::renderer;
use crate::core::touch;
use crate::core::widget::tree::{self, Tree};
use crate::core::{
Clipboard, Element, Length, Pixels, Point, Rectangle, Shell, Size, Widget,
Border, Clipboard, Element, Length, Pixels, Point, Rectangle, Shell, Size,
Widget,
};
/// An vertical bar and a handle that selects a single value from a range of
@ -396,7 +397,7 @@ pub fn draw<T, R>(
width: style.rail.width,
height: offset + handle_width / 2.0,
},
border_radius: style.rail.border_radius,
border: Border::with_radius(style.rail.border_radius),
..renderer::Quad::default()
},
style.rail.colors.1,
@ -410,7 +411,7 @@ pub fn draw<T, R>(
width: style.rail.width,
height: bounds.height - offset - handle_width / 2.0,
},
border_radius: style.rail.border_radius,
border: Border::with_radius(style.rail.border_radius),
..renderer::Quad::default()
},
style.rail.colors.0,
@ -424,9 +425,11 @@ pub fn draw<T, R>(
width: handle_height,
height: handle_width,
},
border_radius: handle_border_radius,
border_width: style.handle.border_width,
border_color: style.handle.border_color,
border: Border {
radius: handle_border_radius,
width: style.handle.border_width,
color: style.handle.border_color,
},
..renderer::Quad::default()
},
style.handle.color,