use Color's From impl in more places

This commit is contained in:
memoryruins 2019-11-07 01:03:29 -05:00
parent 58bd0824bf
commit e7bd24c13e
7 changed files with 49 additions and 139 deletions

View file

@ -444,12 +444,7 @@ fn explain_layout(
// TODO: Draw borders instead
primitives.push(Primitive::Quad {
bounds: layout.bounds(),
background: Background::Color(Color {
r: 0.0,
g: 0.0,
b: 0.0,
a: 0.05,
}),
background: Background::Color([0.0, 0.0, 0.0, 0.05].into()),
border_radius: 0,
});

View file

@ -1,6 +1,6 @@
use crate::{Primitive, Renderer};
use iced_native::{
button, Align, Background, Button, Color, Layout, Length, MouseCursor,
button, Align, Background, Button, Layout, Length, MouseCursor,
Node, Point, Rectangle, Style,
};
@ -53,23 +53,15 @@ impl button::Renderer for Renderer {
y: bounds.y + shadow_offset,
..bounds
},
background: Background::Color(Color {
r: 0.0,
b: 0.0,
g: 0.0,
a: 0.5,
}),
background: Background::Color(
[0.0, 0.0, 0.0, 0.5].into(),
),
border_radius: button.border_radius,
},
Primitive::Quad {
bounds,
background: button.background.unwrap_or(
Background::Color(Color {
r: 0.8,
b: 0.8,
g: 0.8,
a: 1.0,
}),
Background::Color([0.8, 0.8, 0.8].into()),
),
border_radius: button.border_radius,
},

View file

@ -1,7 +1,7 @@
use crate::{Primitive, Renderer};
use iced_native::{
checkbox, text, text::HorizontalAlignment, text::VerticalAlignment, Align,
Background, Checkbox, Color, Column, Layout, Length, MouseCursor, Node,
Background, Checkbox, Column, Layout, Length, MouseCursor, Node,
Point, Rectangle, Row, Text, Widget,
};
@ -46,12 +46,7 @@ impl checkbox::Renderer for Renderer {
let (checkbox_border, checkbox_box) = (
Primitive::Quad {
bounds: checkbox_bounds,
background: Background::Color(Color {
r: 0.6,
g: 0.6,
b: 0.6,
a: 1.0,
}),
background: Background::Color([0.6, 0.6, 0.6].into()),
border_radius: 6,
},
Primitive::Quad {
@ -61,21 +56,14 @@ impl checkbox::Renderer for Renderer {
width: checkbox_bounds.width - 2.0,
height: checkbox_bounds.height - 2.0,
},
background: Background::Color(if is_mouse_over {
Color {
r: 0.90,
g: 0.90,
b: 0.90,
a: 1.0,
background: Background::Color(
if is_mouse_over {
[0.90, 0.90, 0.90]
} else {
[0.95, 0.95, 0.95]
}
} else {
Color {
r: 0.95,
g: 0.95,
b: 0.95,
a: 1.0,
}
}),
.into(),
),
border_radius: 5,
},
);

View file

@ -1,6 +1,6 @@
use crate::{Primitive, Renderer};
use iced_native::{
radio, text, Align, Background, Color, Column, Layout, Length, MouseCursor,
radio, text, Align, Background, Column, Layout, Length, MouseCursor,
Node, Point, Radio, Rectangle, Row, Text, Widget,
};
@ -41,12 +41,7 @@ impl radio::Renderer for Renderer {
let (radio_border, radio_box) = (
Primitive::Quad {
bounds: radio_bounds,
background: Background::Color(Color {
r: 0.6,
g: 0.6,
b: 0.6,
a: 1.0,
}),
background: Background::Color([0.6, 0.6, 0.6].into()),
border_radius: (SIZE / 2.0) as u16,
},
Primitive::Quad {
@ -56,21 +51,14 @@ impl radio::Renderer for Renderer {
width: radio_bounds.width - 2.0,
height: radio_bounds.height - 2.0,
},
background: Background::Color(if is_mouse_over {
Color {
r: 0.90,
g: 0.90,
b: 0.90,
a: 1.0,
background: Background::Color(
if is_mouse_over {
[0.90, 0.90, 0.90]
} else {
[0.95, 0.95, 0.95]
}
} else {
Color {
r: 0.95,
g: 0.95,
b: 0.95,
a: 1.0,
}
}),
.into(),
),
border_radius: (SIZE / 2.0 - 1.0) as u16,
},
);
@ -85,12 +73,7 @@ impl radio::Renderer for Renderer {
width: radio_bounds.width - DOT_SIZE,
height: radio_bounds.height - DOT_SIZE,
},
background: Background::Color(Color {
r: 0.30,
g: 0.30,
b: 0.30,
a: 1.0,
}),
background: Background::Color([0.3, 0.3, 0.3].into()),
border_radius: (DOT_SIZE / 2.0) as u16,
};

View file

@ -1,6 +1,6 @@
use crate::{Primitive, Renderer};
use iced_native::{
scrollable, Background, Color, Layout, MouseCursor, Point, Rectangle,
scrollable, Background, Layout, MouseCursor, Point, Rectangle,
Scrollable, Vector, Widget,
};
@ -78,12 +78,7 @@ impl scrollable::Renderer for Renderer {
- f32::from(2 * SCROLLBAR_MARGIN),
height: scrollbar_height,
},
background: Background::Color(Color {
r: 0.0,
g: 0.0,
b: 0.0,
a: 0.7,
}),
background: Background::Color([0.0, 0.0, 0.0, 0.7].into()),
border_radius: 5,
};
@ -97,12 +92,9 @@ impl scrollable::Renderer for Renderer {
- f32::from(2 * SCROLLBAR_MARGIN),
..scrollbar_bounds
},
background: Background::Color(Color {
r: 0.0,
g: 0.0,
b: 0.0,
a: 0.3,
}),
background: Background::Color(
[0.0, 0.0, 0.0, 0.3].into(),
),
border_radius: 5,
};

View file

@ -37,12 +37,7 @@ impl slider::Renderer for Renderer {
width: bounds.width,
height: 2.0,
},
background: Background::Color(Color {
r: 0.6,
g: 0.6,
b: 0.6,
a: 1.0,
}),
background: Background::Color([0.6, 0.6, 0.6].into()),
border_radius: 0,
},
Primitive::Quad {
@ -71,12 +66,7 @@ impl slider::Renderer for Renderer {
width: HANDLE_WIDTH + 2.0,
height: HANDLE_HEIGHT + 2.0,
},
background: Background::Color(Color {
r: 0.6,
g: 0.6,
b: 0.6,
a: 1.0,
}),
background: Background::Color([0.6, 0.6, 0.6].into()),
border_radius: 5,
},
Primitive::Quad {
@ -86,28 +76,16 @@ impl slider::Renderer for Renderer {
width: HANDLE_WIDTH,
height: HANDLE_HEIGHT,
},
background: Background::Color(if slider.state.is_dragging() {
Color {
r: 0.85,
g: 0.85,
b: 0.85,
a: 1.0,
background: Background::Color(
if slider.state.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]
}
} else if is_mouse_over {
Color {
r: 0.9,
g: 0.9,
b: 0.9,
a: 1.0,
}
} else {
Color {
r: 0.95,
g: 0.95,
b: 0.95,
a: 1.0,
}
}),
.into(),
),
border_radius: 4,
},
);

View file

@ -25,20 +25,11 @@ impl text_input::Renderer for Renderer {
bounds,
background: Background::Color(
if is_mouse_over || text_input.state.is_focused {
Color {
r: 0.5,
g: 0.5,
b: 0.5,
a: 1.0,
}
[0.5, 0.5, 0.5]
} else {
Color {
r: 0.7,
g: 0.7,
b: 0.7,
a: 1.0,
}
},
[0.7, 0.7, 0.7]
}
.into(),
),
border_radius: 5,
};
@ -64,20 +55,11 @@ impl text_input::Renderer for Renderer {
text.clone()
},
color: if text.is_empty() {
Color {
r: 0.7,
g: 0.7,
b: 0.7,
a: 1.0,
}
[0.7, 0.7, 0.7]
} else {
Color {
r: 0.3,
g: 0.3,
b: 0.3,
a: 1.0,
}
},
[0.3, 0.3, 0.3]
}
.into(),
bounds: Rectangle {
width: f32::INFINITY,
..text_bounds