Skip to content

Commit

Permalink
Set input size change
Browse files Browse the repository at this point in the history
  • Loading branch information
d0rianb committed Jan 22, 2022
1 parent 86efd37 commit d99b7fd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/contextual_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ impl ContextualMenu {
fn set_focus(&mut self, index: isize) {
self.focus_index = index;
let item = self.get_focused_item();
if let Some(sub_menu) = &mut item.sub_menu { sub_menu.open(); }
if let Some(sub_menu) = &mut item.sub_menu {
sub_menu.open();
sub_menu.set_focus(0);
}
else if let Some(input) = &mut item.input {
match &item.action {
MenuAction::OpenWithInput => {}
Expand Down
12 changes: 5 additions & 7 deletions src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ impl Editable for Editor {
'D' => { self.select_current_word(); self.delete_selection() },
'+' | '=' => self.increase_font_size(),
'-' => self.decrease_font_size(),
'n' => self.contextual_submenu_test(),
// 'n' => self.new_file_popup(),
// 'n' => self.contextual_submenu_test(),
'n' => self.new_file_popup(),
_ => {}
}
}
Expand Down Expand Up @@ -628,12 +628,12 @@ impl Editor {
}

fn get_recent_paths(&self) -> Vec<(String, String)> {
lazy_static! { static ref NAME_REGEX: Regex = Regex::new(r"([a-zA-Z0-9_-]+).(\w+)$").unwrap(); }
lazy_static! { static ref NAME_REGEX: Regex = Regex::new(r"(\w+)/?$").unwrap(); }
let folder_yaml = self.get_prefs_key("recent_folders");
let folder: Vec<&str> = folder_yaml.as_vec().unwrap().iter().map(|f| f.as_str().unwrap()).collect();
let folder_with_names: Vec<(String, String)> = folder.iter().map(|f| {
let file_name: String = NAME_REGEX.captures(*f).unwrap().get(0).unwrap().as_str().to_string() + "/";
(file_name, String::from(*f))
(file_name, String::from(*f) + "/")
}).collect();
folder_with_names
}
Expand Down Expand Up @@ -737,9 +737,7 @@ impl Editor {
anim.start();
}
anim.update(dt);
if anim.is_ended {
*animation = Option::None;
}
if anim.is_ended { *animation = Option::None; }
}
}
}
Expand Down
14 changes: 10 additions & 4 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,22 @@ impl Input {
is_focus: false,
menu_id,
action_fn,
width: MIN_INPUT_WIDTH,
width: 0.,
height: 50.,
animation_width: Option::None
}
}

pub fn focus(&mut self) {
if self.width == 0. { self.set_width(MIN_INPUT_WIDTH); }
self.is_focus = true;
self.editor.event_sender.as_ref().unwrap().send_event(
EditorEvent::Focus(FocusElement::MenuInput(self.menu_id))
).unwrap()
}

pub fn unfocus(&mut self) {
self.set_width(0.);
self.is_focus = false;
self.editor.event_sender.as_ref().unwrap().send_event(
EditorEvent::Focus(FocusElement::Menu(self.menu_id))
Expand All @@ -124,7 +126,11 @@ impl Input {
}

pub fn set_placeholder(&mut self, text: &str) {
self.select_all();
self.delete_selection();
self.editor.lines.get_mut(0).unwrap().add_text(text);
self.move_cursor(Vector2::new(text.len() as u32, 0));
self.update_text_layout();
}

fn submit(&mut self) {
Expand All @@ -151,9 +157,9 @@ impl Input {
let width_left = self.width - self.editor.lines.first().unwrap().formatted_text_block.width();
const WIDTH_OFFSET: f32 = 25.;
if width_left < WIDTH_OFFSET {
self.set_width(self.width + width_left.abs() + WIDTH_OFFSET);
} else if width_left >= 1.5 * WIDTH_OFFSET {
self.set_width((self.width - WIDTH_OFFSET).clamp(MIN_INPUT_WIDTH, MAX_INPUT_WIDTH));
self.set_width((self.width + WIDTH_OFFSET - width_left).clamp(MIN_INPUT_WIDTH, MAX_INPUT_WIDTH));
} else if width_left >= WIDTH_OFFSET {
self.set_width((self.width - width_left + WIDTH_OFFSET).clamp(MIN_INPUT_WIDTH, MAX_INPUT_WIDTH));
}
}

Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ impl WindowHandler<EditorEvent> for EditorWindowHandler {
_ => {}
}
helper.request_redraw();

}
}

Expand Down

0 comments on commit d99b7fd

Please sign in to comment.