Merge pull request #365 from Imberflur/text-input-font

Make `Font` an associated type of `text_input::Renderer`
This commit is contained in:
Héctor Ramón 2020-05-29 23:10:14 +02:00 committed by GitHub
commit f8cb3acc48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 10 deletions

View File

@ -27,6 +27,7 @@ impl<B> text_input::Renderer for Renderer<B>
where where
B: Backend + backend::Text, B: Backend + backend::Text,
{ {
type Font = Font;
type Style = Box<dyn StyleSheet>; type Style = Box<dyn StyleSheet>;
fn default_size(&self) -> u16 { fn default_size(&self) -> u16 {

View File

@ -103,6 +103,7 @@ impl scrollable::Renderer for Null {
} }
impl text_input::Renderer for Null { impl text_input::Renderer for Null {
type Font = Font;
type Style = (); type Style = ();
fn default_size(&self) -> u16 { fn default_size(&self) -> u16 {

View File

@ -17,8 +17,8 @@ use editor::Editor;
use crate::{ use crate::{
keyboard, layout, keyboard, layout,
mouse::{self, click}, mouse::{self, click},
Clipboard, Element, Event, Font, Hasher, Layout, Length, Point, Rectangle, Clipboard, Element, Event, Hasher, Layout, Length, Point, Rectangle, Size,
Size, Widget, Widget,
}; };
use std::u32; use std::u32;
@ -53,7 +53,7 @@ pub struct TextInput<'a, Message, Renderer: self::Renderer> {
placeholder: String, placeholder: String,
value: Value, value: Value,
is_secure: bool, is_secure: bool,
font: Font, font: Renderer::Font,
width: Length, width: Length,
max_width: u32, max_width: u32,
padding: u16, padding: u16,
@ -88,7 +88,7 @@ impl<'a, Message, Renderer: self::Renderer> TextInput<'a, Message, Renderer> {
placeholder: String::from(placeholder), placeholder: String::from(placeholder),
value: Value::new(value), value: Value::new(value),
is_secure: false, is_secure: false,
font: Font::Default, font: Default::default(),
width: Length::Fill, width: Length::Fill,
max_width: u32::MAX, max_width: u32::MAX,
padding: 0, padding: 0,
@ -111,7 +111,7 @@ impl<'a, Message, Renderer: self::Renderer> TextInput<'a, Message, Renderer> {
/// ///
/// [`Text`]: struct.Text.html /// [`Text`]: struct.Text.html
/// [`Font`]: ../../struct.Font.html /// [`Font`]: ../../struct.Font.html
pub fn font(mut self, font: Font) -> Self { pub fn font(mut self, font: Renderer::Font) -> Self {
self.font = font; self.font = font;
self self
} }
@ -532,6 +532,11 @@ where
/// [`TextInput`]: struct.TextInput.html /// [`TextInput`]: struct.TextInput.html
/// [renderer]: ../../renderer/index.html /// [renderer]: ../../renderer/index.html
pub trait Renderer: crate::Renderer + Sized { pub trait Renderer: crate::Renderer + Sized {
/// The font type used for [`TextInput`].
///
/// [`TextInput`]: struct.TextInput.html
type Font: Default + Copy;
/// The style supported by this renderer. /// The style supported by this renderer.
type Style: Default; type Style: Default;
@ -543,7 +548,7 @@ pub trait Renderer: crate::Renderer + Sized {
/// Returns the width of the value of the [`TextInput`]. /// Returns the width of the value of the [`TextInput`].
/// ///
/// [`TextInput`]: struct.TextInput.html /// [`TextInput`]: struct.TextInput.html
fn measure_value(&self, value: &str, size: u16, font: Font) -> f32; fn measure_value(&self, value: &str, size: u16, font: Self::Font) -> f32;
/// Returns the current horizontal offset of the value of the /// Returns the current horizontal offset of the value of the
/// [`TextInput`]. /// [`TextInput`].
@ -556,7 +561,7 @@ pub trait Renderer: crate::Renderer + Sized {
fn offset( fn offset(
&self, &self,
text_bounds: Rectangle, text_bounds: Rectangle,
font: Font, font: Self::Font,
size: u16, size: u16,
value: &Value, value: &Value,
state: &State, state: &State,
@ -580,7 +585,7 @@ pub trait Renderer: crate::Renderer + Sized {
bounds: Rectangle, bounds: Rectangle,
text_bounds: Rectangle, text_bounds: Rectangle,
cursor_position: Point, cursor_position: Point,
font: Font, font: Self::Font,
size: u16, size: u16,
placeholder: &str, placeholder: &str,
value: &Value, value: &Value,
@ -595,7 +600,7 @@ pub trait Renderer: crate::Renderer + Sized {
fn find_cursor_position( fn find_cursor_position(
&self, &self,
text_bounds: Rectangle, text_bounds: Rectangle,
font: Font, font: Self::Font,
size: Option<u16>, size: Option<u16>,
value: &Value, value: &Value,
state: &State, state: &State,
@ -684,7 +689,7 @@ impl State {
fn find_cursor_position<Renderer: self::Renderer>( fn find_cursor_position<Renderer: self::Renderer>(
renderer: &Renderer, renderer: &Renderer,
value: &Value, value: &Value,
font: Font, font: Renderer::Font,
size: u16, size: u16,
target: f32, target: f32,
start: usize, start: usize,