Fix arrow keys in gallery
This commit is contained in:
parent
081156670e
commit
f54f2efa6a
1 changed files with 146 additions and 120 deletions
266
src/tab.rs
266
src/tab.rs
|
|
@ -2288,143 +2288,169 @@ impl Tab {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::ItemDown => {
|
Message::ItemDown => {
|
||||||
if let Some((row, col)) = self.select_focus_pos_opt().or(self.select_last_pos_opt())
|
if self.gallery {
|
||||||
{
|
for command in self.update(Message::GalleryNext, modifiers) {
|
||||||
if self.select_focus.is_none() {
|
commands.push(command);
|
||||||
// Select last item in current selection to focus it.
|
|
||||||
self.select_position(row, col, mod_shift);
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: Shift modifier should select items in between
|
|
||||||
// Try to select item in next row
|
|
||||||
if !self.select_position(row + 1, col, mod_shift) {
|
|
||||||
// Ensure current item is still selected if there are no other items
|
|
||||||
self.select_position(row, col, mod_shift);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Select first item
|
if let Some((row, col)) =
|
||||||
//TODO: select first in scroll
|
self.select_focus_pos_opt().or(self.select_last_pos_opt())
|
||||||
self.select_position(0, 0, mod_shift);
|
{
|
||||||
}
|
if self.select_focus.is_none() {
|
||||||
if let Some(offset) = self.select_focus_scroll() {
|
// Select last item in current selection to focus it.
|
||||||
commands.push(Command::Iced(scrollable::scroll_to(
|
self.select_position(row, col, mod_shift);
|
||||||
self.scrollable_id.clone(),
|
}
|
||||||
offset,
|
|
||||||
)));
|
//TODO: Shift modifier should select items in between
|
||||||
}
|
// Try to select item in next row
|
||||||
if let Some(id) = self.select_focus_id() {
|
if !self.select_position(row + 1, col, mod_shift) {
|
||||||
commands.push(Command::Iced(widget::button::focus(id)));
|
// Ensure current item is still selected if there are no other items
|
||||||
|
self.select_position(row, col, mod_shift);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Select first item
|
||||||
|
//TODO: select first in scroll
|
||||||
|
self.select_position(0, 0, mod_shift);
|
||||||
|
}
|
||||||
|
if let Some(offset) = self.select_focus_scroll() {
|
||||||
|
commands.push(Command::Iced(scrollable::scroll_to(
|
||||||
|
self.scrollable_id.clone(),
|
||||||
|
offset,
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
if let Some(id) = self.select_focus_id() {
|
||||||
|
commands.push(Command::Iced(widget::button::focus(id)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::ItemLeft => {
|
Message::ItemLeft => {
|
||||||
if let Some((row, col)) =
|
if self.gallery {
|
||||||
self.select_focus_pos_opt().or(self.select_first_pos_opt())
|
for command in self.update(Message::GalleryPrevious, modifiers) {
|
||||||
{
|
commands.push(command);
|
||||||
if self.select_focus.is_none() {
|
|
||||||
// Select first item in current selection to focus it.
|
|
||||||
self.select_position(row, col, mod_shift);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to select previous item in current row
|
|
||||||
if !col
|
|
||||||
.checked_sub(1)
|
|
||||||
.map_or(false, |col| self.select_position(row, col, mod_shift))
|
|
||||||
{
|
|
||||||
// Try to select last item in previous row
|
|
||||||
if !row.checked_sub(1).map_or(false, |row| {
|
|
||||||
let mut col = 0;
|
|
||||||
if let Some(ref items) = self.items_opt {
|
|
||||||
for item in items.iter() {
|
|
||||||
match item.pos_opt.get() {
|
|
||||||
Some((item_row, item_col)) if item_row == row => {
|
|
||||||
col = col.max(item_col);
|
|
||||||
}
|
|
||||||
_ => continue,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.select_position(row, col, mod_shift)
|
|
||||||
}) {
|
|
||||||
// Ensure current item is still selected if there are no other items
|
|
||||||
self.select_position(row, col, mod_shift);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Select first item
|
if let Some((row, col)) =
|
||||||
//TODO: select first in scroll
|
self.select_focus_pos_opt().or(self.select_first_pos_opt())
|
||||||
self.select_position(0, 0, mod_shift);
|
{
|
||||||
}
|
if self.select_focus.is_none() {
|
||||||
if let Some(offset) = self.select_focus_scroll() {
|
// Select first item in current selection to focus it.
|
||||||
commands.push(Command::Iced(scrollable::scroll_to(
|
self.select_position(row, col, mod_shift);
|
||||||
self.scrollable_id.clone(),
|
}
|
||||||
offset,
|
|
||||||
)));
|
// Try to select previous item in current row
|
||||||
}
|
if !col
|
||||||
if let Some(id) = self.select_focus_id() {
|
.checked_sub(1)
|
||||||
commands.push(Command::Iced(widget::button::focus(id)));
|
.map_or(false, |col| self.select_position(row, col, mod_shift))
|
||||||
|
{
|
||||||
|
// Try to select last item in previous row
|
||||||
|
if !row.checked_sub(1).map_or(false, |row| {
|
||||||
|
let mut col = 0;
|
||||||
|
if let Some(ref items) = self.items_opt {
|
||||||
|
for item in items.iter() {
|
||||||
|
match item.pos_opt.get() {
|
||||||
|
Some((item_row, item_col)) if item_row == row => {
|
||||||
|
col = col.max(item_col);
|
||||||
|
}
|
||||||
|
_ => continue,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.select_position(row, col, mod_shift)
|
||||||
|
}) {
|
||||||
|
// Ensure current item is still selected if there are no other items
|
||||||
|
self.select_position(row, col, mod_shift);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Select first item
|
||||||
|
//TODO: select first in scroll
|
||||||
|
self.select_position(0, 0, mod_shift);
|
||||||
|
}
|
||||||
|
if let Some(offset) = self.select_focus_scroll() {
|
||||||
|
commands.push(Command::Iced(scrollable::scroll_to(
|
||||||
|
self.scrollable_id.clone(),
|
||||||
|
offset,
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
if let Some(id) = self.select_focus_id() {
|
||||||
|
commands.push(Command::Iced(widget::button::focus(id)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::ItemRight => {
|
Message::ItemRight => {
|
||||||
if let Some((row, col)) = self.select_focus_pos_opt().or(self.select_last_pos_opt())
|
if self.gallery {
|
||||||
{
|
for command in self.update(Message::GalleryNext, modifiers) {
|
||||||
if self.select_focus.is_none() {
|
commands.push(command);
|
||||||
// Select last item in current selection to focus it.
|
|
||||||
self.select_position(row, col, mod_shift);
|
|
||||||
}
|
|
||||||
// Try to select next item in current row
|
|
||||||
if !self.select_position(row, col + 1, mod_shift) {
|
|
||||||
// Try to select first item in next row
|
|
||||||
if !self.select_position(row + 1, 0, mod_shift) {
|
|
||||||
// Ensure current item is still selected if there are no other items
|
|
||||||
self.select_position(row, col, mod_shift);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Select first item
|
if let Some((row, col)) =
|
||||||
//TODO: select first in scroll
|
self.select_focus_pos_opt().or(self.select_last_pos_opt())
|
||||||
self.select_position(0, 0, mod_shift);
|
{
|
||||||
}
|
if self.select_focus.is_none() {
|
||||||
if let Some(offset) = self.select_focus_scroll() {
|
// Select last item in current selection to focus it.
|
||||||
commands.push(Command::Iced(scrollable::scroll_to(
|
self.select_position(row, col, mod_shift);
|
||||||
self.scrollable_id.clone(),
|
}
|
||||||
offset,
|
// Try to select next item in current row
|
||||||
)));
|
if !self.select_position(row, col + 1, mod_shift) {
|
||||||
}
|
// Try to select first item in next row
|
||||||
if let Some(id) = self.select_focus_id() {
|
if !self.select_position(row + 1, 0, mod_shift) {
|
||||||
commands.push(Command::Iced(widget::button::focus(id)));
|
// Ensure current item is still selected if there are no other items
|
||||||
|
self.select_position(row, col, mod_shift);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Select first item
|
||||||
|
//TODO: select first in scroll
|
||||||
|
self.select_position(0, 0, mod_shift);
|
||||||
|
}
|
||||||
|
if let Some(offset) = self.select_focus_scroll() {
|
||||||
|
commands.push(Command::Iced(scrollable::scroll_to(
|
||||||
|
self.scrollable_id.clone(),
|
||||||
|
offset,
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
if let Some(id) = self.select_focus_id() {
|
||||||
|
commands.push(Command::Iced(widget::button::focus(id)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::ItemUp => {
|
Message::ItemUp => {
|
||||||
if let Some((row, col)) =
|
if self.gallery {
|
||||||
self.select_focus_pos_opt().or(self.select_first_pos_opt())
|
for command in self.update(Message::GalleryPrevious, modifiers) {
|
||||||
{
|
commands.push(command);
|
||||||
if self.select_focus.is_none() {
|
|
||||||
// Select first item in current selection to focus it.
|
|
||||||
self.select_position(row, col, mod_shift);
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: Shift modifier should select items in between
|
|
||||||
// Try to select item in last row
|
|
||||||
if !row
|
|
||||||
.checked_sub(1)
|
|
||||||
.map_or(false, |row| self.select_position(row, col, mod_shift))
|
|
||||||
{
|
|
||||||
// Ensure current item is still selected if there are no other items
|
|
||||||
self.select_position(row, col, mod_shift);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Select first item
|
if let Some((row, col)) =
|
||||||
//TODO: select first in scroll
|
self.select_focus_pos_opt().or(self.select_first_pos_opt())
|
||||||
self.select_position(0, 0, mod_shift);
|
{
|
||||||
}
|
if self.select_focus.is_none() {
|
||||||
if let Some(offset) = self.select_focus_scroll() {
|
// Select first item in current selection to focus it.
|
||||||
commands.push(Command::Iced(scrollable::scroll_to(
|
self.select_position(row, col, mod_shift);
|
||||||
self.scrollable_id.clone(),
|
}
|
||||||
offset,
|
|
||||||
)));
|
//TODO: Shift modifier should select items in between
|
||||||
}
|
// Try to select item in last row
|
||||||
if let Some(id) = self.select_focus_id() {
|
if !row
|
||||||
commands.push(Command::Iced(widget::button::focus(id)));
|
.checked_sub(1)
|
||||||
|
.map_or(false, |row| self.select_position(row, col, mod_shift))
|
||||||
|
{
|
||||||
|
// Ensure current item is still selected if there are no other items
|
||||||
|
self.select_position(row, col, mod_shift);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Select first item
|
||||||
|
//TODO: select first in scroll
|
||||||
|
self.select_position(0, 0, mod_shift);
|
||||||
|
}
|
||||||
|
if let Some(offset) = self.select_focus_scroll() {
|
||||||
|
commands.push(Command::Iced(scrollable::scroll_to(
|
||||||
|
self.scrollable_id.clone(),
|
||||||
|
offset,
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
if let Some(id) = self.select_focus_id() {
|
||||||
|
commands.push(Command::Iced(widget::button::focus(id)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::Location(location) => {
|
Message::Location(location) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue