Skip to content

Commit

Permalink
Merge pull request #1 from casperstorm/fix/pr/1643
Browse files Browse the repository at this point in the history
Added `border_radius`, `border_width`, `border_color` and renamed variables.
  • Loading branch information
n1ght-hunter authored Feb 10, 2023
2 parents 7528b4d + 689b76e commit 1767fbe
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 30 deletions.
37 changes: 24 additions & 13 deletions native/src/widget/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use crate::renderer;
use crate::touch;
use crate::widget::tree::{self, Tree};
use crate::{
Clipboard, Color, Element, Layout, Length, Point, Rectangle, Shell, Size,
Widget,
Clipboard, Element, Layout, Length, Point, Rectangle, Shell, Size, Widget,
};

use std::ops::RangeInclusive;
Expand Down Expand Up @@ -398,7 +397,7 @@ pub fn draw<T, R>(
- handle_width / 2.0
};

let line_y = bounds.y + bounds.height / 2.0 - style.rail.rail_size / 2.0;
let line_y = bounds.y + bounds.height / 2.0 - style.rail.size / 2.0;
let line_offset = offset + handle_width / 2.0;

renderer.fill_quad(
Expand All @@ -407,13 +406,19 @@ pub fn draw<T, R>(
x: bounds.x,
y: line_y,
width: line_offset,
height: style.rail.rail_size,
height: style.rail.size,
},
border_radius: 0.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
border_radius: [
style.rail.border_radius,
0.0,
0.0,
style.rail.border_radius,
]
.into(),
border_width: style.rail.border_width,
border_color: style.rail.border_color,
},
style.rail.rail_colors.0,
style.rail.colors.0,
);

renderer.fill_quad(
Expand All @@ -422,13 +427,19 @@ pub fn draw<T, R>(
x: bounds.x + line_offset.round(),
y: line_y,
width: bounds.width - line_offset,
height: style.rail.rail_size,
height: style.rail.size,
},
border_radius: 0.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
border_radius: [
0.0,
style.rail.border_radius,
style.rail.border_radius,
0.0,
]
.into(),
border_width: style.rail.border_width,
border_color: style.rail.border_color,
},
style.rail.rail_colors.1,
style.rail.colors.1,
);

renderer.fill_quad(
Expand Down
38 changes: 25 additions & 13 deletions native/src/widget/vertical_slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ pub use iced_style::slider::{Appearance, Handle, HandleShape, StyleSheet};
use crate::event::{self, Event};
use crate::widget::tree::{self, Tree};
use crate::{
layout, mouse, renderer, touch, Clipboard, Color, Element, Layout, Length,
Point, Rectangle, Shell, Size, Widget,
layout, mouse, renderer, touch, Clipboard, Element, Layout, Length, Point,
Rectangle, Shell, Size, Widget,
};

/// An vertical bar and a handle that selects a single value from a range of
Expand Down Expand Up @@ -390,37 +390,49 @@ pub fn draw<T, R>(
- handle_width / 2.0
};

let line_x = bounds.x + bounds.width / 2.0 - style.rail.rail_size / 2.0;
let line_x = bounds.x + bounds.width / 2.0 - style.rail.size / 2.0;
let line_offset = offset + handle_width / 2.0;

renderer.fill_quad(
renderer::Quad {
bounds: Rectangle {
x: line_x,
y: bounds.y,
width: style.rail.rail_size,
width: style.rail.size,
height: line_offset,
},
border_radius: 0.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
border_radius: [
style.rail.border_radius,
style.rail.border_radius,
0.0,
0.0,
]
.into(),
border_width: style.rail.border_width,
border_color: style.rail.border_color,
},
style.rail.rail_colors.1,
style.rail.colors.1,
);

renderer.fill_quad(
renderer::Quad {
bounds: Rectangle {
x: line_x,
y: bounds.y + line_offset.round(),
width: style.rail.rail_size,
width: style.rail.size,
height: bounds.height - line_offset,
},
border_radius: 0.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
border_radius: [
0.0,
0.0,
style.rail.border_radius,
style.rail.border_radius,
]
.into(),
border_width: style.rail.border_width,
border_color: style.rail.border_color,
},
style.rail.rail_colors.0,
style.rail.colors.0,
);

renderer.fill_quad(
Expand Down
10 changes: 8 additions & 2 deletions style/src/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ pub struct Appearance {
#[derive(Debug, Clone, Copy)]
pub struct Rail {
/// The colors of the rail of the slider.
pub rail_colors: (Color, Color),
pub colors: (Color, Color),
/// The height of a slider rail and the width of a vertical slider.
pub rail_size: f32,
pub size: f32,
/// The border radius of the slider.
pub border_radius: f32,
/// The border width of the slider.
pub border_width: f32,
/// The border [`Color`] of the slider.
pub border_color: Color,
}

/// The appearance of the handle of a slider.
Expand Down
7 changes: 5 additions & 2 deletions style/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,14 @@ impl slider::StyleSheet for Theme {

slider::Appearance {
rail: slider::Rail {
rail_colors: (
colors: (
palette.primary.base.color,
palette.primary.base.color,
),
rail_size: 2.0,
size: 2.0,
border_radius: 0.0,
border_width: 0.0,
border_color: Color::TRANSPARENT,
},
handle: slider::Handle {
color: palette.background.base.color,
Expand Down

0 comments on commit 1767fbe

Please sign in to comment.