Add border_width and border_color to Quad

This commit is contained in:
Héctor Ramón Jiménez 2019-12-31 21:35:42 +01:00
parent 649d72e7de
commit 9ab7c47dc7
17 changed files with 180 additions and 128 deletions

View file

@ -1,5 +1,7 @@
use crate::{button::StyleSheet, defaults, Defaults, Primitive, Renderer};
use iced_native::{Background, Element, Layout, MouseCursor, Point, Rectangle};
use iced_native::{
Background, Color, Element, Layout, MouseCursor, Point, Rectangle,
};
impl iced_native::button::Renderer for Renderer {
type Style = Box<dyn StyleSheet>;
@ -57,11 +59,15 @@ impl iced_native::button::Renderer for Renderer {
[0.0, 0.0, 0.0, 0.5].into(),
),
border_radius: styling.border_radius,
border_width: 0,
border_color: Color::TRANSPARENT,
},
Primitive::Quad {
bounds,
background,
border_radius: styling.border_radius,
border_width: 0,
border_color: Color::TRANSPARENT,
},
content,
],

View file

@ -1,6 +1,6 @@
use crate::{Primitive, Renderer};
use iced_native::{
checkbox, Background, HorizontalAlignment, MouseCursor, Rectangle,
checkbox, Background, Color, HorizontalAlignment, MouseCursor, Rectangle,
VerticalAlignment,
};
@ -18,30 +18,20 @@ impl checkbox::Renderer for Renderer {
is_mouse_over: bool,
(label, _): Self::Output,
) -> Self::Output {
let (checkbox_border, checkbox_box) = (
Primitive::Quad {
bounds,
background: Background::Color([0.6, 0.6, 0.6].into()),
border_radius: 6,
},
Primitive::Quad {
bounds: Rectangle {
x: bounds.x + 1.0,
y: bounds.y + 1.0,
width: bounds.width - 2.0,
height: bounds.height - 2.0,
},
background: Background::Color(
if is_mouse_over {
[0.90, 0.90, 0.90]
} else {
[0.95, 0.95, 0.95]
}
.into(),
),
border_radius: 5,
},
);
let checkbox = Primitive::Quad {
bounds,
background: Background::Color(
if is_mouse_over {
[0.90, 0.90, 0.90]
} else {
[0.95, 0.95, 0.95]
}
.into(),
),
border_radius: 5,
border_width: 1,
border_color: Color::from_rgb(0.6, 0.6, 0.6),
};
(
Primitive::Group {
@ -56,9 +46,9 @@ impl checkbox::Renderer for Renderer {
vertical_alignment: VerticalAlignment::Center,
};
vec![checkbox_border, checkbox_box, check, label]
vec![checkbox, check, label]
} else {
vec![checkbox_border, checkbox_box, label]
vec![checkbox, label]
},
},
if is_mouse_over {

View file

@ -1,5 +1,5 @@
use crate::{container, defaults, Defaults, Primitive, Renderer};
use iced_native::{Element, Layout, Point, Rectangle};
use iced_native::{Color, Element, Layout, Point, Rectangle};
impl iced_native::container::Renderer for Renderer {
type Style = Box<dyn container::StyleSheet>;
@ -31,6 +31,8 @@ impl iced_native::container::Renderer for Renderer {
bounds,
background,
border_radius: style.border_radius,
border_width: 0,
border_color: Color::TRANSPARENT,
};
(

View file

@ -1,5 +1,5 @@
use crate::{Primitive, Renderer};
use iced_native::{radio, Background, MouseCursor, Rectangle};
use iced_native::{radio, Background, Color, MouseCursor, Rectangle};
const SIZE: f32 = 28.0;
const DOT_SIZE: f32 = SIZE / 2.0;
@ -16,30 +16,20 @@ impl radio::Renderer for Renderer {
is_mouse_over: bool,
(label, _): Self::Output,
) -> Self::Output {
let (radio_border, radio_box) = (
Primitive::Quad {
bounds,
background: Background::Color([0.6, 0.6, 0.6].into()),
border_radius: (SIZE / 2.0) as u16,
},
Primitive::Quad {
bounds: Rectangle {
x: bounds.x + 1.0,
y: bounds.y + 1.0,
width: bounds.width - 2.0,
height: bounds.height - 2.0,
},
background: Background::Color(
if is_mouse_over {
[0.90, 0.90, 0.90]
} else {
[0.95, 0.95, 0.95]
}
.into(),
),
border_radius: (SIZE / 2.0 - 1.0) as u16,
},
);
let radio = Primitive::Quad {
bounds,
background: Background::Color(
if is_mouse_over {
[0.90, 0.90, 0.90]
} else {
[0.95, 0.95, 0.95]
}
.into(),
),
border_radius: (SIZE / 2.0) as u16,
border_width: 1,
border_color: Color::from_rgb(0.6, 0.6, 0.6),
};
(
Primitive::Group {
@ -53,11 +43,13 @@ impl radio::Renderer for Renderer {
},
background: Background::Color([0.3, 0.3, 0.3].into()),
border_radius: (DOT_SIZE / 2.0) as u16,
border_width: 0,
border_color: Color::TRANSPARENT,
};
vec![radio_border, radio_box, radio_circle, label]
vec![radio, radio_circle, label]
} else {
vec![radio_border, radio_box, label]
vec![radio, label]
},
},
if is_mouse_over {

View file

@ -1,5 +1,7 @@
use crate::{Primitive, Renderer};
use iced_native::{scrollable, Background, MouseCursor, Rectangle, Vector};
use iced_native::{
scrollable, Background, Color, MouseCursor, Rectangle, Vector,
};
const SCROLLBAR_WIDTH: u16 = 10;
const SCROLLBAR_MARGIN: u16 = 2;
@ -68,6 +70,8 @@ impl scrollable::Renderer for Renderer {
[0.0, 0.0, 0.0, 0.7].into(),
),
border_radius: 5,
border_width: 0,
border_color: Color::TRANSPARENT,
};
if is_mouse_over_scrollbar || state.is_scroller_grabbed() {
@ -83,6 +87,8 @@ impl scrollable::Renderer for Renderer {
[0.0, 0.0, 0.0, 0.3].into(),
),
border_radius: 5,
border_width: 0,
border_color: Color::TRANSPARENT,
};
Primitive::Group {

View file

@ -29,8 +29,10 @@ impl slider::Renderer for Renderer {
width: bounds.width,
height: 2.0,
},
background: Color::from_rgb(0.6, 0.6, 0.6).into(),
background: Background::Color([0.6, 0.6, 0.6, 0.5].into()),
border_radius: 0,
border_width: 0,
border_color: Color::TRANSPARENT,
},
Primitive::Quad {
bounds: Rectangle {
@ -41,6 +43,8 @@ impl slider::Renderer for Renderer {
},
background: Background::Color(Color::WHITE),
border_radius: 0,
border_width: 0,
border_color: Color::TRANSPARENT,
},
);
@ -49,41 +53,31 @@ impl slider::Renderer for Renderer {
let handle_offset = (bounds.width - HANDLE_WIDTH)
* ((value - range_start) / (range_end - range_start).max(1.0));
let (handle_border, handle) = (
Primitive::Quad {
bounds: Rectangle {
x: bounds.x + handle_offset.round() - 1.0,
y: rail_y - HANDLE_HEIGHT / 2.0 - 1.0,
width: HANDLE_WIDTH + 2.0,
height: HANDLE_HEIGHT + 2.0,
},
background: Color::from_rgb(0.6, 0.6, 0.6).into(),
border_radius: 5,
let handle = Primitive::Quad {
bounds: Rectangle {
x: bounds.x + handle_offset.round(),
y: rail_y - HANDLE_HEIGHT / 2.0,
width: HANDLE_WIDTH,
height: HANDLE_HEIGHT,
},
Primitive::Quad {
bounds: Rectangle {
x: bounds.x + handle_offset.round(),
y: rail_y - HANDLE_HEIGHT / 2.0,
width: HANDLE_WIDTH,
height: HANDLE_HEIGHT,
},
background: Background::Color(
if is_dragging {
[0.85, 0.85, 0.85]
} else if is_mouse_over {
[0.90, 0.90, 0.90]
} else {
[0.95, 0.95, 0.95]
}
.into(),
),
border_radius: 4,
},
);
background: Background::Color(
if is_dragging {
[0.85, 0.85, 0.85]
} else if is_mouse_over {
[0.90, 0.90, 0.90]
} else {
[0.95, 0.95, 0.95]
}
.into(),
),
border_radius: 4,
border_width: 1,
border_color: Color::from_rgb(0.6, 0.6, 0.6),
};
(
Primitive::Group {
primitives: vec![rail_top, rail_bottom, handle_border, handle],
primitives: vec![rail_top, rail_bottom, handle],
},
if is_dragging {
MouseCursor::Grabbing

View file

@ -64,28 +64,17 @@ impl text_input::Renderer for Renderer {
) -> Self::Output {
let is_mouse_over = bounds.contains(cursor_position);
let border = Primitive::Quad {
bounds,
background: Background::Color(
if is_mouse_over || state.is_focused() {
[0.5, 0.5, 0.5]
} else {
[0.7, 0.7, 0.7]
}
.into(),
),
border_radius: 5,
};
let input = Primitive::Quad {
bounds: Rectangle {
x: bounds.x + 1.0,
y: bounds.y + 1.0,
width: bounds.width - 2.0,
height: bounds.height - 2.0,
},
bounds,
background: Background::Color(Color::WHITE),
border_radius: 4,
border_radius: 5,
border_width: 1,
border_color: if is_mouse_over || state.is_focused() {
[0.5, 0.5, 0.5]
} else {
[0.7, 0.7, 0.7]
}
.into(),
};
let text = value.to_string();
@ -130,6 +119,8 @@ impl text_input::Renderer for Renderer {
},
background: Background::Color(Color::BLACK),
border_radius: 0,
border_width: 0,
border_color: Color::TRANSPARENT,
};
(
@ -150,7 +141,7 @@ impl text_input::Renderer for Renderer {
(
Primitive::Group {
primitives: vec![border, input, contents],
primitives: vec![input, contents],
},
if is_mouse_over {
MouseCursor::Text