pub fn textbox(&mut self, title: &str) -> &str {
        let id = Id::from_str(title, CompType::Textbox, &self.salt);
        let pos = self.caret;

        let (width, height, pressed) = self.button_internal("", id);
        if pressed {
            if self.focused == Some(id) {
            } else {
                self.focused = Some(id);
                self.caret_blink_time = 0.0;

                let TextboxInfo { ref mut text, ref mut caret } = *self.textbox_map.entry(id).or_insert(Default::default());
                *caret = text.len();
            }

            // Place caret at correct location
            let click_pos = self.mouse_pos.x - pos.x - self.style.padding.x/2.0;
            let TextboxInfo { ref mut text, ref mut caret } = *self.textbox_map.entry(id).or_insert(Default::default());
            let (visible_range, _) = self.font.font().visible_area(&text, self.style.font_size, width - self.style.padding.x, *caret);
            if let Some(clicked) = self.font.font().hovered_char(&text[visible_range.clone()], self.style.font_size, click_pos) {
                *caret = visible_range.start + clicked;
            } else {
                *caret = text.len();
            }
        }

        // Editing
        if self.focused == Some(id) {
            let TextboxInfo { ref mut text, ref mut caret } = *self.textbox_map.entry(id).or_insert(Default::default());

            if self.move_left && *caret > 0 {
                *caret -= 1;
                // Align to char boundary
                while !text.is_char_boundary(*caret) && *caret > 0 { *caret -= 1; }
                self.caret_blink_time = 0.0;
            }
            if self.move_right {
                *caret += 1;
                if *caret > text.len() {
                    *caret = text.len();
                } else {
                    // Align to char boundary
                    while !text.is_char_boundary(*caret) && *caret < text.len() { *caret += 1; }
                }
                self.caret_blink_time = 0.0;
            }

            text.reserve(self.typed.len());
            for c in self.typed.chars() {
                match c {
                    // Backspace
                    '\x08' => {
                        if *caret == text.len() {
                            if let Some(removed) = text.pop() {
                                *caret -= removed.len_utf8();
                            }
                        } else if *caret > 0 {
                            let mut remove_index = *caret - 1;
                            while !text.is_char_boundary(remove_index) && remove_index > 0 { remove_index -= 1 }
                            let removed = text.remove(remove_index);
                            *caret -= removed.len_utf8();
                        }
                    }, 
                    // Delete
                    '\x7f' => {
                        if *caret < text.len() {
                            text.remove(*caret);
                        }
                    },
                    // Ignore all other control characters
                    e if e <= '\x1f' => {}, 
                    _ => {
                        text.insert(*caret, c);
                        *caret += c.len_utf8();
                    },
                }

                self.caret_blink_time = 0.0;
            }
        }

        // Drawing
        if let Some(&TextboxInfo { ref text, ref caret }) = self.textbox_map.get(&id) {
            let caret = if self.focused == Some(id) { *caret } else { text.len() };

            let (visible_range, draw_caret_pos) =
                self.font.font().visible_area(&text, self.style.font_size,
                                              width - self.style.padding.x,
                                              caret);
            let slice = &text[visible_range];

            // Draw text
            let text_pos = {
                let text_start = self.style.padding.y/2.0 - self.font.font().descent(self.style.font_size);
                pos + Vec2::new(self.style.padding.x/2.0, height - text_start)
            };
            self.font.cache(slice, self.style.font_size, text_pos, self.style.text_color);

            // Draw caret
            if self.focused == Some(id) && self.caret_blink_time % (2.0*CARET_BLINK_RATE) < CARET_BLINK_RATE {
                quad(&mut self.draw_data,
                     pos + Vec2::new(draw_caret_pos + self.style.padding.x/2.0 - self.style.caret_width/2.0, self.style.padding.y/4.0),
                     Vec2::new(self.style.caret_width/2.0, height - self.style.padding.y/2.0),
                     self.style.caret_color);
            }

            &text
        } else {
            ""
        }
    }
/// Creates a new textbox. The title will not be displayed, but should be a unique identifier
/// for this textbox.
Creates a new textbox. The title will not be displayed, but should be a unique identifier
for this textbox.
Creates a new textbox . The title will not be displayed but should be a unique identifier for this textbox .
pub fn textbox(&mut self, title: &str) -> &str {
        let id = Id::from_str(title, CompType::Textbox, &self.salt);
        let pos = self.caret;
        let (width, height, pressed) = self.button_internal("", id);
        if pressed {
            if self.focused == Some(id) {
            } else {
                self.focused = Some(id);
                self.caret_blink_time = 0.0;
                let TextboxInfo { ref mut text, ref mut caret } = *self.textbox_map.entry(id).or_insert(Default::default());
                *caret = text.len();
            }
            // Place caret at correct location
            let click_pos = self.mouse_pos.x - pos.x - self.style.padding.x/2.0;
            let TextboxInfo { ref mut text, ref mut caret } = *self.textbox_map.entry(id).or_insert(Default::default());
            let (visible_range, _) = self.font.font().visible_area(&text, self.style.font_size, width - self.style.padding.x, *caret);
            if let Some(clicked) = self.font.font().hovered_char(&text[visible_range.clone()], self.style.font_size, click_pos) {
                *caret = visible_range.start + clicked;
            } else {
                *caret = text.len();
            }
        }
        // Editing
        if self.focused == Some(id) {
            let TextboxInfo { ref mut text, ref mut caret } = *self.textbox_map.entry(id).or_insert(Default::default());
            if self.move_left && *caret > 0 {
                *caret -= 1;
                // Align to char boundary
                while !text.is_char_boundary(*caret) && *caret > 0 { *caret -= 1; }
                self.caret_blink_time = 0.0;
            }
            if self.move_right {
                *caret += 1;
                if *caret > text.len() {
                    *caret = text.len();
                } else {
                    // Align to char boundary
                    while !text.is_char_boundary(*caret) && *caret < text.len() { *caret += 1; }
                }
                self.caret_blink_time = 0.0;
            }
            text.reserve(self.typed.len());
            for c in self.typed.chars() {
                match c {
                    // Backspace
                    '\x08' => {
                        if *caret == text.len() {
                            if let Some(removed) = text.pop() {
                                *caret -= removed.len_utf8();
                            }
                        } else if *caret > 0 {
                            let mut remove_index = *caret - 1;
                            while !text.is_char_boundary(remove_index) && remove_index > 0 { remove_index -= 1 }
                            let removed = text.remove(remove_index);
                            *caret -= removed.len_utf8();
                        }
                    }, 
                    // Delete
                    '\x7f' => {
                        if *caret < text.len() {
                            text.remove(*caret);
                        }
                    },
                    // Ignore all other control characters
                    e if e <= '\x1f' => {}, 
                    _ => {
                        text.insert(*caret, c);
                        *caret += c.len_utf8();
                    },
                }
                self.caret_blink_time = 0.0;
            }
        }
        // Drawing
        if let Some(&TextboxInfo { ref text, ref caret }) = self.textbox_map.get(&id) {
            let caret = if self.focused == Some(id) { *caret } else { text.len() };
            let (visible_range, draw_caret_pos) =
                self.font.font().visible_area(&text, self.style.font_size,
                                              width - self.style.padding.x,
                                              caret);
            let slice = &text[visible_range];
            // Draw text
            let text_pos = {
                let text_start = self.style.padding.y/2.0 - self.font.font().descent(self.style.font_size);
                pos + Vec2::new(self.style.padding.x/2.0, height - text_start)
            };
            self.font.cache(slice, self.style.font_size, text_pos, self.style.text_color);
            // Draw caret
            if self.focused == Some(id) && self.caret_blink_time % (2.0*CARET_BLINK_RATE) < CARET_BLINK_RATE {
                quad(&mut self.draw_data,
                     pos + Vec2::new(draw_caret_pos + self.style.padding.x/2.0 - self.style.caret_width/2.0, self.style.padding.y/4.0),
                     Vec2::new(self.style.caret_width/2.0, height - self.style.padding.y/2.0),
                     self.style.caret_color);
            }
            &text
        } else {
            ""
        }
    }
pub fn textbox ( & mut self , title : & str ) -> & str { let id = Id :: from_str ( title , CompType :: Textbox , & self . salt ) ; let pos = self . caret ; let ( width , height , pressed ) = self . button_internal ( " " , id ) ; if pressed { if self . focused == Some ( id ) { } else { self . focused = Some ( id ) ; self . caret_blink_time = 0.0 ; let TextboxInfo { ref mut text , ref mut caret } = * self . textbox_map . entry ( id ) . or_insert ( Default :: default ( ) ) ; * caret = text . len ( ) ; } // Place caret at correct location let click_pos = self . mouse_pos . x - pos . x - self . style . padding . x / 2.0 ; let TextboxInfo { ref mut text , ref mut caret } = * self . textbox_map . entry ( id ) . or_insert ( Default :: default ( ) ) ; let ( visible_range , _ ) = self . font . font ( ) . visible_area ( & text , self . style . font_size , width - self . style . padding . x , * caret ) ; if let Some ( clicked ) = self . font . font ( ) . hovered_char ( & text [ visible_range . clone ( ) ] , self . style . font_size , click_pos ) { * caret = visible_range . start + clicked ; } else { * caret = text . len ( ) ; } } // Editing if self . focused == Some ( id ) { let TextboxInfo { ref mut text , ref mut caret } = * self . textbox_map . entry ( id ) . or_insert ( Default :: default ( ) ) ; if self . move_left && * caret > 0 { * caret -= 1 ; // Align to char boundary while ! text . is_char_boundary ( * caret ) && * caret > 0 { * caret -= 1 ; } self . caret_blink_time = 0.0 ; } if self . move_right { * caret += 1 ; if * caret > text . len ( ) { * caret = text . len ( ) ; } else { // Align to char boundary while ! text . is_char_boundary ( * caret ) && * caret < text . len ( ) { * caret += 1 ; } } self . caret_blink_time = 0.0 ; } text . reserve ( self . typed . len ( ) ) ; for c in self . typed . chars ( ) { match c { // Backspace '\x08' => { if * caret == text . len ( ) { if let Some ( removed ) = text . pop ( ) { * caret -= removed . len_utf8 ( ) ; } } else if * caret > 0 { let mut remove_index = * caret - 1 ; while ! text . is_char_boundary ( remove_index ) && remove_index > 0 { remove_index -= 1 } let removed = text . remove ( remove_index ) ; * caret -= removed . len_utf8 ( ) ; } } , // Delete '\x7f' => { if * caret < text . len ( ) { text . remove ( * caret ) ; } } , // Ignore all other control characters e if e <= '\x1f' => { } , _ => { text . insert ( * caret , c ) ; * caret += c . len_utf8 ( ) ; } , } self . caret_blink_time = 0.0 ; } } // Drawing if let Some ( & TextboxInfo { ref text , ref caret } ) = self . textbox_map . get ( & id ) { let caret = if self . focused == Some ( id ) { * caret } else { text . len ( ) } ; let ( visible_range , draw_caret_pos ) = self . font . font ( ) . visible_area ( & text , self . style . font_size , width - self . style . padding . x , caret ) ; let slice = & text [ visible_range ] ; // Draw text let text_pos = { let text_start = self . style . padding . y / 2.0 - self . font . font ( ) . descent ( self . style . font_size ) ; pos + Vec2 :: new ( self . style . padding . x / 2.0 , height - text_start ) } ; self . font . cache ( slice , self . style . font_size , text_pos , self . style . text_color ) ; // Draw caret if self . focused == Some ( id ) && self . caret_blink_time % ( 2.0 * CARET_BLINK_RATE ) < CARET_BLINK_RATE { quad ( & mut self . draw_data , pos + Vec2 :: new ( draw_caret_pos + self . style . padding . x / 2.0 - self . style . caret_width / 2.0 , self . style . padding . y / 4.0 ) , Vec2 :: new ( self . style . caret_width / 2.0 , height - self . style . padding . y / 2.0 ) , self . style . caret_color ) ; } & text } else { " " } }
Creates a new textbox.
Creates a new textbox .
&mut self
title
&str
&mut self
title
&str