mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-02-02 17:44:42 -05:00
Change how scrolling works, add home/end (#1212)
Conflicts fixed by gull
This commit is contained in:
parent
ceaa115025
commit
ca7840557b
@ -137,6 +137,16 @@ uint32_t TextViewer::offset() const {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextViewer::cursor_home() {
|
||||||
|
cursor_.col = 0;
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextViewer::cursor_end() {
|
||||||
|
cursor_.col = line_length() - 1;
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
uint16_t TextViewer::line_length() {
|
uint16_t TextViewer::line_length() {
|
||||||
return file_->line_length(cursor_.line);
|
return file_->line_length(cursor_.line);
|
||||||
}
|
}
|
||||||
@ -157,18 +167,14 @@ bool TextViewer::apply_scrolling_constraints(int16_t delta_line, int16_t delta_c
|
|||||||
++new_line;
|
++new_line;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Snap to first/last to make navigating easier.
|
// Snap to first/last line to make navigating easier.
|
||||||
if (new_line < 0 && new_col > 0) {
|
if (new_line < 0 && cursor_.line > 0) {
|
||||||
new_line = 0;
|
new_line = 0;
|
||||||
new_col = 0;
|
|
||||||
} else if (new_line >= (int32_t)file_->line_count()) {
|
} else if (new_line >= (int32_t)file_->line_count()) {
|
||||||
auto last_line = file_->line_count() - 1;
|
auto last_line = file_->line_count() - 1;
|
||||||
int32_t last_col = file_->line_length(last_line) - 1;
|
|
||||||
|
|
||||||
if (new_col < last_col) {
|
if (cursor_.line < last_line)
|
||||||
new_line = last_line;
|
new_line = last_line;
|
||||||
new_col = last_col;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (new_line < 0 || (uint32_t)new_line >= file_->line_count())
|
if (new_line < 0 || (uint32_t)new_line >= file_->line_count())
|
||||||
@ -176,7 +182,6 @@ bool TextViewer::apply_scrolling_constraints(int16_t delta_line, int16_t delta_c
|
|||||||
|
|
||||||
new_line_length = file_->line_length(new_line);
|
new_line_length = file_->line_length(new_line);
|
||||||
|
|
||||||
// TODO: don't wrap with encoder?
|
|
||||||
// Wrap or clamp column.
|
// Wrap or clamp column.
|
||||||
if (new_line_length == 0)
|
if (new_line_length == 0)
|
||||||
new_col = 0;
|
new_col = 0;
|
||||||
@ -267,9 +272,9 @@ TextEditorMenu::TextEditorMenu()
|
|||||||
add_children(
|
add_children(
|
||||||
{
|
{
|
||||||
&rect_frame,
|
&rect_frame,
|
||||||
&button_cut,
|
&button_home,
|
||||||
&button_paste,
|
&button_end,
|
||||||
&button_zoom,
|
&button_copy,
|
||||||
&button_delline,
|
&button_delline,
|
||||||
&button_edit,
|
&button_edit,
|
||||||
&button_addline,
|
&button_addline,
|
||||||
@ -318,18 +323,19 @@ TextEditorView::TextEditorView(NavigationView& nav)
|
|||||||
};
|
};
|
||||||
|
|
||||||
menu.hidden(true);
|
menu.hidden(true);
|
||||||
menu.on_cut() = [this]() {
|
menu.on_home() = [this]() {
|
||||||
show_nyi();
|
viewer.cursor_home();
|
||||||
};
|
|
||||||
menu.on_paste() = [this]() {
|
|
||||||
show_nyi();
|
|
||||||
};
|
|
||||||
menu.on_zoom() = [this]() {
|
|
||||||
viewer.toggle_font_zoom();
|
|
||||||
refresh_ui();
|
|
||||||
hide_menu(true);
|
hide_menu(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
menu.on_end() = [this]() {
|
||||||
|
viewer.cursor_end();
|
||||||
|
hide_menu(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
menu.on_copy() = [this]() {
|
||||||
|
};
|
||||||
|
|
||||||
menu.on_delete_line() = [this]() {
|
menu.on_delete_line() = [this]() {
|
||||||
prepare_for_write();
|
prepare_for_write();
|
||||||
file_->delete_line(viewer.line());
|
file_->delete_line(viewer.line());
|
||||||
@ -500,10 +506,6 @@ void TextEditorView::show_edit_line() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorView::show_nyi() {
|
|
||||||
nav_.display_modal("Soon...", "Coming soon.");
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextEditorView::show_save_prompt(std::function<void()> continuation) {
|
void TextEditorView::show_save_prompt(std::function<void()> continuation) {
|
||||||
if (!file_dirty_) {
|
if (!file_dirty_) {
|
||||||
if (continuation)
|
if (continuation)
|
||||||
|
@ -72,6 +72,9 @@ class TextViewer : public Widget {
|
|||||||
uint32_t col() const { return cursor_.col; }
|
uint32_t col() const { return cursor_.col; }
|
||||||
uint32_t offset() const;
|
uint32_t offset() const;
|
||||||
|
|
||||||
|
void cursor_home();
|
||||||
|
void cursor_end();
|
||||||
|
|
||||||
// Gets the length of the current line.
|
// Gets the length of the current line.
|
||||||
uint16_t line_length();
|
uint16_t line_length();
|
||||||
|
|
||||||
@ -125,14 +128,12 @@ class TextEditorMenu : public View {
|
|||||||
void on_show() override;
|
void on_show() override;
|
||||||
void on_hide() override;
|
void on_hide() override;
|
||||||
|
|
||||||
std::function<void()>& on_cut() { return button_cut.on_select; }
|
std::function<void()>& on_home() { return button_home.on_select; }
|
||||||
std::function<void()>& on_paste() { return button_paste.on_select; }
|
std::function<void()>& on_end() { return button_end.on_select; }
|
||||||
std::function<void()>& on_zoom() { return button_zoom.on_select; }
|
std::function<void()>& on_copy() { return button_copy.on_select; }
|
||||||
|
|
||||||
std::function<void()>& on_delete_line() { return button_delline.on_select; }
|
std::function<void()>& on_delete_line() { return button_delline.on_select; }
|
||||||
std::function<void()>& on_edit_line() { return button_edit.on_select; }
|
std::function<void()>& on_edit_line() { return button_edit.on_select; }
|
||||||
std::function<void()>& on_add_line() { return button_addline.on_select; }
|
std::function<void()>& on_add_line() { return button_addline.on_select; }
|
||||||
|
|
||||||
std::function<void()>& on_open() { return button_open.on_select; }
|
std::function<void()>& on_open() { return button_open.on_select; }
|
||||||
std::function<void()>& on_save() { return button_save.on_select; }
|
std::function<void()>& on_save() { return button_save.on_select; }
|
||||||
std::function<void()>& on_exit() { return button_exit.on_select; }
|
std::function<void()>& on_exit() { return button_exit.on_select; }
|
||||||
@ -144,16 +145,16 @@ class TextEditorMenu : public View {
|
|||||||
{0 * 8, 0 * 8, 23 * 8, 23 * 8},
|
{0 * 8, 0 * 8, 23 * 8, 23 * 8},
|
||||||
Color::dark_grey()};
|
Color::dark_grey()};
|
||||||
|
|
||||||
NewButton button_cut{
|
NewButton button_home{
|
||||||
{1 * 8, 1 * 8, 7 * 8, 7 * 8},
|
{1 * 8, 1 * 8, 7 * 8, 7 * 8},
|
||||||
"Cut",
|
"Home",
|
||||||
&bitmap_icon_cut,
|
&bitmap_arrow_left,
|
||||||
Color::dark_grey()};
|
Color::dark_grey()};
|
||||||
|
|
||||||
NewButton button_paste{
|
NewButton button_end{
|
||||||
{8 * 8, 1 * 8, 7 * 8, 7 * 8},
|
{8 * 8, 1 * 8, 7 * 8, 7 * 8},
|
||||||
"Paste",
|
"End",
|
||||||
&bitmap_icon_paste,
|
&bitmap_arrow_right,
|
||||||
Color::dark_grey()};
|
Color::dark_grey()};
|
||||||
|
|
||||||
NewButton button_zoom{
|
NewButton button_zoom{
|
||||||
@ -225,7 +226,6 @@ class TextEditorView : public View {
|
|||||||
void hide_menu(bool hidden = true);
|
void hide_menu(bool hidden = true);
|
||||||
void show_file_picker(bool immediate = true);
|
void show_file_picker(bool immediate = true);
|
||||||
void show_edit_line();
|
void show_edit_line();
|
||||||
void show_nyi();
|
|
||||||
void show_save_prompt(std::function<void()> continuation);
|
void show_save_prompt(std::function<void()> continuation);
|
||||||
|
|
||||||
void prepare_for_write();
|
void prepare_for_write();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user