Remove EditView::min_length

Uses `.fixed_width()` from `Boxable` or something like that.
This commit is contained in:
Alexandre Bury 2016-08-03 21:58:00 -07:00
parent b38995b906
commit 1052c0b74c
3 changed files with 9 additions and 24 deletions

View File

@ -12,9 +12,9 @@ fn main() {
.title("Enter your name") .title("Enter your name")
.padding((1, 1, 1, 0)) .padding((1, 1, 1, 0))
.content(EditView::new() .content(EditView::new()
.min_length(20)
.on_submit(show_popup) .on_submit(show_popup)
.with_id("name")) .with_id("name")
.fixed_width(20))
.button("Ok", |s| { .button("Ok", |s| {
let name = s.find_id::<EditView>("name") let name = s.find_id::<EditView>("name")
.unwrap() .unwrap()

View File

@ -9,18 +9,18 @@ fn main() {
.title("Please fill out this form") .title("Please fill out this form")
.button("Ok", |s| s.quit()) .button("Ok", |s| s.quit())
.content(ListView::new() .content(ListView::new()
.child("Name", EditView::new().min_length(10)) .child("Name", EditView::new().fixed_width(10))
.child("Email", .child("Email",
LinearLayout::horizontal() LinearLayout::horizontal()
.child(EditView::new() .child(EditView::new()
.min_length(15)
.disabled() .disabled()
.with_id("email1")) .with_id("email1")
.fixed_width(15))
.child(TextView::new("@")) .child(TextView::new("@"))
.child(EditView::new() .child(EditView::new()
.min_length(10)
.disabled() .disabled()
.with_id("email2"))) .with_id("email2")
.fixed_width(10)))
.child("Receive spam?", .child("Receive spam?",
Checkbox::new().on_change(|s, checked| { Checkbox::new().on_change(|s, checked| {
for name in &["email1", "email2"] { for name in &["email1", "email2"] {

View File

@ -33,9 +33,9 @@ use utils::simple_suffix_length;
/// .title("Enter your name") /// .title("Enter your name")
/// .padding((1, 1, 1, 0)) /// .padding((1, 1, 1, 0))
/// .content(EditView::new() /// .content(EditView::new()
/// .min_length(20)
/// .on_submit(show_popup) /// .on_submit(show_popup)
/// .with_id("name")) /// .with_id("name")
/// .fixed_width(20))
/// .button("Ok", |s| { /// .button("Ok", |s| {
/// let name = s.find_id::<EditView>("name") /// let name = s.find_id::<EditView>("name")
/// .unwrap() /// .unwrap()
@ -61,8 +61,6 @@ pub struct EditView {
content: Rc<String>, content: Rc<String>,
/// Cursor position in the content, in bytes. /// Cursor position in the content, in bytes.
cursor: usize, cursor: usize,
/// Minimum layout length asked to the parent.
min_length: usize,
/// Number of bytes to skip at the beginning of the content. /// Number of bytes to skip at the beginning of the content.
/// ///
@ -94,7 +92,6 @@ impl EditView {
content: Rc::new(String::new()), content: Rc::new(String::new()),
cursor: 0, cursor: 0,
offset: 0, offset: 0,
min_length: 1,
last_length: 0, // scrollable: false, last_length: 0, // scrollable: false,
on_edit: None, on_edit: None,
on_submit: None, on_submit: None,
@ -186,14 +183,6 @@ impl EditView {
self self
} }
/// Sets the minimum length for this view.
/// (This applies to the layout, not the content.)
pub fn min_length(mut self, min_length: usize) -> Self {
self.min_length = min_length;
self
}
/// Insert `ch` at the current cursor position. /// Insert `ch` at the current cursor position.
pub fn insert(&mut self, ch: char) { pub fn insert(&mut self, ch: char) {
// `make_mut` applies copy-on-write // `make_mut` applies copy-on-write
@ -303,10 +292,6 @@ impl View for EditView {
self.last_length = size.x; self.last_length = size.x;
} }
fn get_min_size(&mut self, _: Vec2) -> Vec2 {
Vec2::new(self.min_length, 1)
}
fn take_focus(&mut self, _: Direction) -> bool { fn take_focus(&mut self, _: Direction) -> bool {
self.enabled self.enabled
} }