Implement font
method for ComboBox
This commit is contained in:
parent
1c12bad866
commit
69ac47f463
@ -43,8 +43,9 @@ where
|
|||||||
cursor_position: Point,
|
cursor_position: Point,
|
||||||
options: &[T],
|
options: &[T],
|
||||||
hovered_option: Option<usize>,
|
hovered_option: Option<usize>,
|
||||||
text_size: u16,
|
|
||||||
padding: u16,
|
padding: u16,
|
||||||
|
text_size: u16,
|
||||||
|
font: Font,
|
||||||
style: &Style,
|
style: &Style,
|
||||||
) -> Self::Output {
|
) -> Self::Output {
|
||||||
use std::f32;
|
use std::f32;
|
||||||
@ -83,7 +84,7 @@ where
|
|||||||
..bounds
|
..bounds
|
||||||
},
|
},
|
||||||
size: f32::from(text_size),
|
size: f32::from(text_size),
|
||||||
font: Font::Default,
|
font,
|
||||||
color: if is_selected {
|
color: if is_selected {
|
||||||
style.selected_text_color
|
style.selected_text_color
|
||||||
} else {
|
} else {
|
||||||
|
@ -29,8 +29,9 @@ where
|
|||||||
bounds: Rectangle,
|
bounds: Rectangle,
|
||||||
cursor_position: Point,
|
cursor_position: Point,
|
||||||
selected: Option<String>,
|
selected: Option<String>,
|
||||||
text_size: u16,
|
|
||||||
padding: u16,
|
padding: u16,
|
||||||
|
text_size: u16,
|
||||||
|
font: Font,
|
||||||
style: &Box<dyn StyleSheet>,
|
style: &Box<dyn StyleSheet>,
|
||||||
) -> Self::Output {
|
) -> Self::Output {
|
||||||
let is_mouse_over = bounds.contains(cursor_position);
|
let is_mouse_over = bounds.contains(cursor_position);
|
||||||
@ -69,7 +70,7 @@ where
|
|||||||
let label = Primitive::Text {
|
let label = Primitive::Text {
|
||||||
content: label,
|
content: label,
|
||||||
size: f32::from(text_size),
|
size: f32::from(text_size),
|
||||||
font: Font::Default,
|
font,
|
||||||
color: style.text_color,
|
color: style.text_color,
|
||||||
bounds: Rectangle {
|
bounds: Rectangle {
|
||||||
x: bounds.x + f32::from(padding),
|
x: bounds.x + f32::from(padding),
|
||||||
|
@ -11,6 +11,7 @@ pub struct Menu<'a, T, Message, Renderer: self::Renderer> {
|
|||||||
width: u16,
|
width: u16,
|
||||||
padding: u16,
|
padding: u16,
|
||||||
text_size: Option<u16>,
|
text_size: Option<u16>,
|
||||||
|
font: Renderer::Font,
|
||||||
style: <Renderer as self::Renderer>::Style,
|
style: <Renderer as self::Renderer>::Style,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,6 +33,7 @@ where
|
|||||||
width: 0,
|
width: 0,
|
||||||
padding: 0,
|
padding: 0,
|
||||||
text_size: None,
|
text_size: None,
|
||||||
|
font: Default::default(),
|
||||||
style: Default::default(),
|
style: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -51,6 +53,11 @@ where
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn font(mut self, font: Renderer::Font) -> Self {
|
||||||
|
self.font = font;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn style(
|
pub fn style(
|
||||||
mut self,
|
mut self,
|
||||||
style: impl Into<<Renderer as self::Renderer>::Style>,
|
style: impl Into<<Renderer as self::Renderer>::Style>,
|
||||||
@ -115,20 +122,21 @@ where
|
|||||||
on_selected,
|
on_selected,
|
||||||
width,
|
width,
|
||||||
padding,
|
padding,
|
||||||
|
font,
|
||||||
text_size,
|
text_size,
|
||||||
style,
|
style,
|
||||||
} = menu;
|
} = menu;
|
||||||
|
|
||||||
let container = Container::new(
|
let container =
|
||||||
Scrollable::new(&mut state.scrollable).push(List::new(
|
Container::new(Scrollable::new(&mut state.scrollable).push(List {
|
||||||
options,
|
options,
|
||||||
&mut state.hovered_option,
|
hovered_option: &mut state.hovered_option,
|
||||||
on_selected,
|
on_selected,
|
||||||
|
font,
|
||||||
text_size,
|
text_size,
|
||||||
padding,
|
padding,
|
||||||
style.clone(),
|
style: style.clone(),
|
||||||
)),
|
}))
|
||||||
)
|
|
||||||
.padding(1);
|
.padding(1);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
@ -246,29 +254,10 @@ struct List<'a, T, Message, Renderer: self::Renderer> {
|
|||||||
options: &'a [T],
|
options: &'a [T],
|
||||||
hovered_option: &'a mut Option<usize>,
|
hovered_option: &'a mut Option<usize>,
|
||||||
on_selected: &'a dyn Fn(T) -> Message,
|
on_selected: &'a dyn Fn(T) -> Message,
|
||||||
text_size: Option<u16>,
|
|
||||||
padding: u16,
|
padding: u16,
|
||||||
style: <Renderer as self::Renderer>::Style,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, T, Message, Renderer: self::Renderer> List<'a, T, Message, Renderer> {
|
|
||||||
pub fn new(
|
|
||||||
options: &'a [T],
|
|
||||||
hovered_option: &'a mut Option<usize>,
|
|
||||||
on_selected: &'a dyn Fn(T) -> Message,
|
|
||||||
text_size: Option<u16>,
|
text_size: Option<u16>,
|
||||||
padding: u16,
|
font: Renderer::Font,
|
||||||
style: <Renderer as self::Renderer>::Style,
|
style: <Renderer as self::Renderer>::Style,
|
||||||
) -> Self {
|
|
||||||
List {
|
|
||||||
options,
|
|
||||||
hovered_option,
|
|
||||||
on_selected,
|
|
||||||
text_size,
|
|
||||||
padding,
|
|
||||||
style,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T, Message, Renderer: self::Renderer> Widget<'a, Message, Renderer>
|
impl<'a, T, Message, Renderer: self::Renderer> Widget<'a, Message, Renderer>
|
||||||
@ -370,8 +359,9 @@ where
|
|||||||
cursor_position,
|
cursor_position,
|
||||||
self.options,
|
self.options,
|
||||||
*self.hovered_option,
|
*self.hovered_option,
|
||||||
self.text_size.unwrap_or(renderer.default_size()),
|
|
||||||
self.padding,
|
self.padding,
|
||||||
|
self.text_size.unwrap_or(renderer.default_size()),
|
||||||
|
self.font,
|
||||||
&self.style,
|
&self.style,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -396,8 +386,9 @@ pub trait Renderer:
|
|||||||
cursor_position: Point,
|
cursor_position: Point,
|
||||||
options: &[T],
|
options: &[T],
|
||||||
hovered_option: Option<usize>,
|
hovered_option: Option<usize>,
|
||||||
text_size: u16,
|
|
||||||
padding: u16,
|
padding: u16,
|
||||||
|
text_size: u16,
|
||||||
|
font: Self::Font,
|
||||||
style: &<Self as Renderer>::Style,
|
style: &<Self as Renderer>::Style,
|
||||||
) -> Self::Output;
|
) -> Self::Output;
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ where
|
|||||||
width: Length,
|
width: Length,
|
||||||
padding: u16,
|
padding: u16,
|
||||||
text_size: Option<u16>,
|
text_size: Option<u16>,
|
||||||
|
font: Renderer::Font,
|
||||||
style: <Renderer as self::Renderer>::Style,
|
style: <Renderer as self::Renderer>::Style,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +46,8 @@ where
|
|||||||
width: Length::Shrink,
|
width: Length::Shrink,
|
||||||
text_size: None,
|
text_size: None,
|
||||||
padding: Renderer::DEFAULT_PADDING,
|
padding: Renderer::DEFAULT_PADDING,
|
||||||
style: <Renderer as self::Renderer>::Style::default(),
|
font: Default::default(),
|
||||||
|
style: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,6 +72,11 @@ where
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn font(mut self, font: Renderer::Font) -> Self {
|
||||||
|
self.font = font;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets the style of the [`ComboBox`].
|
/// Sets the style of the [`ComboBox`].
|
||||||
///
|
///
|
||||||
/// [`ComboBox`]: struct.ComboBox.html
|
/// [`ComboBox`]: struct.ComboBox.html
|
||||||
@ -200,8 +207,9 @@ where
|
|||||||
layout.bounds(),
|
layout.bounds(),
|
||||||
cursor_position,
|
cursor_position,
|
||||||
self.selected.as_ref().map(ToString::to_string),
|
self.selected.as_ref().map(ToString::to_string),
|
||||||
self.text_size.unwrap_or(renderer.default_size()),
|
|
||||||
self.padding,
|
self.padding,
|
||||||
|
self.text_size.unwrap_or(renderer.default_size()),
|
||||||
|
self.font,
|
||||||
&self.style,
|
&self.style,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -244,8 +252,9 @@ pub trait Renderer: text::Renderer + menu::Renderer {
|
|||||||
bounds: Rectangle,
|
bounds: Rectangle,
|
||||||
cursor_position: Point,
|
cursor_position: Point,
|
||||||
selected: Option<String>,
|
selected: Option<String>,
|
||||||
text_size: u16,
|
|
||||||
padding: u16,
|
padding: u16,
|
||||||
|
text_size: u16,
|
||||||
|
font: Self::Font,
|
||||||
style: &<Self as Renderer>::Style,
|
style: &<Self as Renderer>::Style,
|
||||||
) -> Self::Output;
|
) -> Self::Output;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user