widget Rule added
This commit is contained in:
parent
00d66da0ce
commit
8d68c8584e
12 changed files with 331 additions and 8 deletions
|
|
@ -15,6 +15,7 @@ pub mod pane_grid;
|
|||
pub mod pick_list;
|
||||
pub mod progress_bar;
|
||||
pub mod radio;
|
||||
pub mod rule;
|
||||
pub mod scrollable;
|
||||
pub mod slider;
|
||||
pub mod svg;
|
||||
|
|
@ -40,6 +41,8 @@ pub use progress_bar::ProgressBar;
|
|||
#[doc(no_inline)]
|
||||
pub use radio::Radio;
|
||||
#[doc(no_inline)]
|
||||
pub use rule::Rule;
|
||||
#[doc(no_inline)]
|
||||
pub use scrollable::Scrollable;
|
||||
#[doc(no_inline)]
|
||||
pub use slider::Slider;
|
||||
|
|
|
|||
89
graphics/src/widget/rule.rs
Normal file
89
graphics/src/widget/rule.rs
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
//! Display a horizontal or vertical rule for dividing content.
|
||||
|
||||
use crate::{Backend, Primitive, Renderer};
|
||||
use iced_native::mouse;
|
||||
use iced_native::rule;
|
||||
use iced_native::{Background, Color, Rectangle};
|
||||
|
||||
pub use iced_style::rule::{Style, StyleSheet};
|
||||
|
||||
/// Display a horizontal or vertical rule for dividing content.
|
||||
///
|
||||
/// This is an alias of an `iced_native` rule with an `iced_graphics::Renderer`.
|
||||
pub type Rule<Backend> = iced_native::Rule<Renderer<Backend>>;
|
||||
|
||||
impl<B> rule::Renderer for Renderer<B>
|
||||
where
|
||||
B: Backend,
|
||||
{
|
||||
type Style = Box<dyn StyleSheet>;
|
||||
|
||||
fn draw(
|
||||
&mut self,
|
||||
bounds: Rectangle,
|
||||
style_sheet: &Self::Style,
|
||||
is_horizontal: bool,
|
||||
) -> Self::Output {
|
||||
let style = style_sheet.style();
|
||||
|
||||
let line = if is_horizontal {
|
||||
let line_y = (bounds.y + (bounds.height / 2.0)
|
||||
- (style.width as f32 / 2.0))
|
||||
.round();
|
||||
|
||||
let (line_x, line_width) = if style.fill_percent >= 100 {
|
||||
(bounds.x, bounds.width)
|
||||
} else {
|
||||
let percent_width =
|
||||
(bounds.width * style.fill_percent as f32 / 100.0).round();
|
||||
(
|
||||
bounds.x + ((bounds.width - percent_width) / 2.0).round(),
|
||||
percent_width,
|
||||
)
|
||||
};
|
||||
|
||||
Primitive::Quad {
|
||||
bounds: Rectangle {
|
||||
x: line_x,
|
||||
y: line_y,
|
||||
width: line_width,
|
||||
height: style.width as f32,
|
||||
},
|
||||
background: Background::Color(style.color),
|
||||
border_radius: style.radius,
|
||||
border_width: 0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
}
|
||||
} else {
|
||||
let line_x = (bounds.x + (bounds.width / 2.0)
|
||||
- (style.width as f32 / 2.0))
|
||||
.round();
|
||||
|
||||
let (line_y, line_height) = if style.fill_percent >= 100 {
|
||||
(bounds.y, bounds.height)
|
||||
} else {
|
||||
let percent_height =
|
||||
(bounds.height * style.fill_percent as f32 / 100.0).round();
|
||||
(
|
||||
bounds.y + ((bounds.height - percent_height) / 2.0).round(),
|
||||
percent_height,
|
||||
)
|
||||
};
|
||||
|
||||
Primitive::Quad {
|
||||
bounds: Rectangle {
|
||||
x: line_x,
|
||||
y: line_y,
|
||||
width: style.width as f32,
|
||||
height: line_height,
|
||||
},
|
||||
background: Background::Color(style.color),
|
||||
border_radius: style.radius,
|
||||
border_width: 0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
}
|
||||
};
|
||||
|
||||
(line, mouse::Interaction::default())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue