Rename pick_list::AccessoryContent to Handle
... and rename `Default` variant to `Arrow`.
This commit is contained in:
parent
fe5ab1ee87
commit
39f49186ce
4 changed files with 34 additions and 39 deletions
|
|
@ -20,56 +20,56 @@ use std::borrow::Cow;
|
||||||
|
|
||||||
pub use iced_style::pick_list::{Appearance, StyleSheet};
|
pub use iced_style::pick_list::{Appearance, StyleSheet};
|
||||||
|
|
||||||
/// The content to the right side of the [`PickList`].
|
/// The handle to the right side of the [`PickList`].
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum AccessoryContent<Renderer>
|
pub enum Handle<Renderer>
|
||||||
where
|
where
|
||||||
Renderer: text::Renderer,
|
Renderer: text::Renderer,
|
||||||
{
|
{
|
||||||
/// Default accessory content.
|
/// Displays an arrow icon (▼).
|
||||||
Default {
|
///
|
||||||
|
/// This is the default.
|
||||||
|
Arrow {
|
||||||
/// Font size of the content.
|
/// Font size of the content.
|
||||||
size: Option<u16>,
|
size: Option<u16>,
|
||||||
},
|
},
|
||||||
/// Custom accessory content.
|
/// A custom handle.
|
||||||
Custom {
|
Custom {
|
||||||
/// Font which will be used in the accessory content.
|
/// Font that will be used to display the `text`,
|
||||||
font: Renderer::Font,
|
font: Renderer::Font,
|
||||||
/// Content which will be shown.
|
/// Text that will be shown.
|
||||||
content: String,
|
text: String,
|
||||||
/// Font size of the content.
|
/// Font size of the content.
|
||||||
size: Option<u16>,
|
size: Option<u16>,
|
||||||
},
|
},
|
||||||
/// No accessory content will be shown.
|
/// No handle will be shown.
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Renderer> Default for AccessoryContent<Renderer>
|
impl<Renderer> Default for Handle<Renderer>
|
||||||
where
|
where
|
||||||
Renderer: text::Renderer,
|
Renderer: text::Renderer,
|
||||||
{
|
{
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::Default { size: None }
|
Self::Arrow { size: None }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Renderer> AccessoryContent<Renderer>
|
impl<Renderer> Handle<Renderer>
|
||||||
where
|
where
|
||||||
Renderer: text::Renderer,
|
Renderer: text::Renderer,
|
||||||
{
|
{
|
||||||
fn content(&self) -> Option<(Renderer::Font, String, Option<u16>)> {
|
fn content(&self) -> Option<(Renderer::Font, String, Option<u16>)> {
|
||||||
match self {
|
match self {
|
||||||
AccessoryContent::Default { size } => Some((
|
Self::Arrow { size } => Some((
|
||||||
Renderer::ICON_FONT,
|
Renderer::ICON_FONT,
|
||||||
Renderer::ARROW_DOWN_ICON.to_string(),
|
Renderer::ARROW_DOWN_ICON.to_string(),
|
||||||
*size,
|
*size,
|
||||||
)),
|
)),
|
||||||
AccessoryContent::Custom {
|
Self::Custom { font, text, size } => {
|
||||||
font,
|
Some((font.clone(), text.clone(), *size))
|
||||||
content,
|
}
|
||||||
size,
|
Self::None => None,
|
||||||
} => Some((font.clone(), content.clone(), *size)),
|
|
||||||
AccessoryContent::None => None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -90,7 +90,7 @@ where
|
||||||
padding: Padding,
|
padding: Padding,
|
||||||
text_size: Option<u16>,
|
text_size: Option<u16>,
|
||||||
font: Renderer::Font,
|
font: Renderer::Font,
|
||||||
accessory_content: AccessoryContent<Renderer>,
|
handle: Handle<Renderer>,
|
||||||
style: <Renderer::Theme as StyleSheet>::Style,
|
style: <Renderer::Theme as StyleSheet>::Style,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -125,7 +125,7 @@ where
|
||||||
padding: Self::DEFAULT_PADDING,
|
padding: Self::DEFAULT_PADDING,
|
||||||
text_size: None,
|
text_size: None,
|
||||||
font: Default::default(),
|
font: Default::default(),
|
||||||
accessory_content: Default::default(),
|
handle: Default::default(),
|
||||||
style: Default::default(),
|
style: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -160,12 +160,9 @@ where
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the [`AccessoryContent`] of the [`PickList`].
|
/// Sets the [`Handle`] of the [`PickList`].
|
||||||
pub fn accessory_content(
|
pub fn handle(mut self, handle: Handle<Renderer>) -> Self {
|
||||||
mut self,
|
self.handle = handle;
|
||||||
accessory_content: AccessoryContent<Renderer>,
|
|
||||||
) -> Self {
|
|
||||||
self.accessory_content = accessory_content;
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -279,7 +276,7 @@ where
|
||||||
&self.font,
|
&self.font,
|
||||||
self.placeholder.as_deref(),
|
self.placeholder.as_deref(),
|
||||||
self.selected.as_ref(),
|
self.selected.as_ref(),
|
||||||
&self.accessory_content,
|
&self.handle,
|
||||||
&self.style,
|
&self.style,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -581,7 +578,7 @@ pub fn draw<T, Renderer>(
|
||||||
font: &Renderer::Font,
|
font: &Renderer::Font,
|
||||||
placeholder: Option<&str>,
|
placeholder: Option<&str>,
|
||||||
selected: Option<&T>,
|
selected: Option<&T>,
|
||||||
accessory_content: &AccessoryContent<Renderer>,
|
handle: &Handle<Renderer>,
|
||||||
style: &<Renderer::Theme as StyleSheet>::Style,
|
style: &<Renderer::Theme as StyleSheet>::Style,
|
||||||
) where
|
) where
|
||||||
Renderer: text::Renderer,
|
Renderer: text::Renderer,
|
||||||
|
|
@ -608,14 +605,14 @@ pub fn draw<T, Renderer>(
|
||||||
style.background,
|
style.background,
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some((font, content, size)) = accessory_content.content() {
|
if let Some((font, text, size)) = handle.content() {
|
||||||
let size = f32::from(size.unwrap_or_else(|| renderer.default_size()));
|
let size = f32::from(size.unwrap_or_else(|| renderer.default_size()));
|
||||||
|
|
||||||
renderer.fill_text(Text {
|
renderer.fill_text(Text {
|
||||||
content: &content,
|
content: &text,
|
||||||
size,
|
size,
|
||||||
font,
|
font,
|
||||||
color: style.accessory_content_color,
|
color: style.handle_color,
|
||||||
bounds: Rectangle {
|
bounds: Rectangle {
|
||||||
x: bounds.x + bounds.width - f32::from(padding.horizontal()),
|
x: bounds.x + bounds.width - f32::from(padding.horizontal()),
|
||||||
y: bounds.center_y() - size / 2.0,
|
y: bounds.center_y() - size / 2.0,
|
||||||
|
|
|
||||||
|
|
@ -80,9 +80,7 @@ pub mod pane_grid {
|
||||||
|
|
||||||
pub mod pick_list {
|
pub mod pick_list {
|
||||||
//! Display a dropdown list of selectable values.
|
//! Display a dropdown list of selectable values.
|
||||||
pub use iced_native::widget::pick_list::{
|
pub use iced_native::widget::pick_list::{Appearance, Handle, StyleSheet};
|
||||||
AccessoryContent, Appearance, StyleSheet,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// A widget allowing the selection of a single value from a list of options.
|
/// A widget allowing the selection of a single value from a list of options.
|
||||||
pub type PickList<'a, T, Message, Renderer = crate::Renderer> =
|
pub type PickList<'a, T, Message, Renderer = crate::Renderer> =
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ pub struct Appearance {
|
||||||
pub text_color: Color,
|
pub text_color: Color,
|
||||||
/// The placeholder [`Color`] of the pick list.
|
/// The placeholder [`Color`] of the pick list.
|
||||||
pub placeholder_color: Color,
|
pub placeholder_color: Color,
|
||||||
/// The accessory content [`Color`] of the pick list.
|
/// The handle [`Color`] of the pick list.
|
||||||
pub accessory_content_color: Color,
|
pub handle_color: Color,
|
||||||
/// The [`Background`] of the pick list.
|
/// The [`Background`] of the pick list.
|
||||||
pub background: Background,
|
pub background: Background,
|
||||||
/// The border radius of the pick list.
|
/// The border radius of the pick list.
|
||||||
|
|
|
||||||
|
|
@ -534,7 +534,7 @@ impl pick_list::StyleSheet for Theme {
|
||||||
text_color: palette.background.weak.text,
|
text_color: palette.background.weak.text,
|
||||||
background: palette.background.weak.color.into(),
|
background: palette.background.weak.color.into(),
|
||||||
placeholder_color: palette.background.strong.color,
|
placeholder_color: palette.background.strong.color,
|
||||||
accessory_content_color: palette.background.weak.text,
|
handle_color: palette.background.weak.text,
|
||||||
border_radius: 2.0,
|
border_radius: 2.0,
|
||||||
border_width: 1.0,
|
border_width: 1.0,
|
||||||
border_color: palette.background.strong.color,
|
border_color: palette.background.strong.color,
|
||||||
|
|
@ -553,7 +553,7 @@ impl pick_list::StyleSheet for Theme {
|
||||||
text_color: palette.background.weak.text,
|
text_color: palette.background.weak.text,
|
||||||
background: palette.background.weak.color.into(),
|
background: palette.background.weak.color.into(),
|
||||||
placeholder_color: palette.background.strong.color,
|
placeholder_color: palette.background.strong.color,
|
||||||
accessory_content_color: palette.background.weak.text,
|
handle_color: palette.background.weak.text,
|
||||||
border_radius: 2.0,
|
border_radius: 2.0,
|
||||||
border_width: 1.0,
|
border_width: 1.0,
|
||||||
border_color: palette.primary.strong.color,
|
border_color: palette.primary.strong.color,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue