Browse Source

listing: show auto-hide scrollbar in sidebar menu

Setting to turn it off is listing.show_menu_scrollbar.

Concerns #85 Accounts sidebar doesn't scroll
jmap-eventsource
Manos Pitsidianakis 1 year ago
parent
commit
8d9247e9a3
Signed by: epilys GPG Key ID: 73627C2F690DF710
  1. 5
      docs/meli.conf.5
  2. 60
      src/components/mail/listing.rs
  3. 7
      src/conf/listing.rs
  4. 5
      src/conf/overrides.rs

5
docs/meli.conf.5

@ -843,6 +843,11 @@ Sets the string to print in the mailbox tree for a leaf level where its root has
.It Ic sidebar_divider Ar char
.Pq Em optional
Sets the character to print as the divider between the accounts list and the message list.
.It Ic show_menu_scrollbar Ar boolean
.Pq Em optional
Show auto-hiding scrollbar in accounts sidebar menu.
.\" default value
.Pq Em true
.El
.Ss Examples of sidebar mailbox tree customization
The default values

60
src/components/mail/listing.rs

@ -474,6 +474,13 @@ enum MenuEntryCursor {
Mailbox(usize),
}
#[derive(PartialEq, Copy, Clone, Debug)]
enum ShowMenuScrollbar {
Never,
True,
False,
}
#[derive(Debug)]
pub struct Listing {
component: ListingComponent,
@ -484,6 +491,8 @@ pub struct Listing {
cursor_pos: (usize, MenuEntryCursor),
menu_cursor_pos: (usize, MenuEntryCursor),
menu_content: CellBuffer,
menu_scrollbar_show_timer: crate::jobs::Timer,
show_menu_scrollbar: ShowMenuScrollbar,
startup_checks_rate: RateLimit,
id: ComponentId,
theme_default: ThemeAttribute,
@ -604,6 +613,14 @@ impl Component for Listing {
fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool {
match event {
UIEvent::Timer(n) if *n == self.menu_scrollbar_show_timer.id() => {
if self.show_menu_scrollbar == ShowMenuScrollbar::True {
self.show_menu_scrollbar = ShowMenuScrollbar::False;
self.set_dirty(true);
self.menu_content.empty();
}
return true;
}
UIEvent::StartupCheck(ref f) => {
if self.component.coordinates().1 == *f {
if !self.startup_checks_rate.tick() {
@ -771,6 +788,10 @@ impl Component for Listing {
}
UIEvent::Input(Key::Left) if self.menu_visibility => {
self.focus = ListingFocus::Menu;
if self.show_menu_scrollbar != ShowMenuScrollbar::Never {
self.menu_scrollbar_show_timer.rearm();
self.show_menu_scrollbar = ShowMenuScrollbar::True;
}
self.ratio = 50;
self.set_dirty(true);
}
@ -1241,6 +1262,10 @@ impl Component for Listing {
amount -= 1;
}
}
if self.show_menu_scrollbar != ShowMenuScrollbar::Never {
self.menu_scrollbar_show_timer.rearm();
self.show_menu_scrollbar = ShowMenuScrollbar::True;
}
self.menu_content.empty();
self.set_dirty(true);
return true;
@ -1298,6 +1323,10 @@ impl Component for Listing {
} else {
return true;
}
if self.show_menu_scrollbar != ShowMenuScrollbar::Never {
self.menu_scrollbar_show_timer.rearm();
self.show_menu_scrollbar = ShowMenuScrollbar::True;
}
self.menu_content.empty();
return true;
}
@ -1347,6 +1376,10 @@ impl Component for Listing {
}
_ => return false,
}
if self.show_menu_scrollbar != ShowMenuScrollbar::Never {
self.menu_scrollbar_show_timer.rearm();
self.show_menu_scrollbar = ShowMenuScrollbar::True;
}
self.menu_content.empty();
self.set_dirty(true);
@ -1518,6 +1551,11 @@ impl Listing {
cursor_pos: (0, MenuEntryCursor::Mailbox(0)),
menu_cursor_pos: (0, MenuEntryCursor::Mailbox(0)),
menu_content: CellBuffer::new_with_context(0, 0, None, context),
menu_scrollbar_show_timer: context.job_executor.clone().create_timer(
std::time::Duration::from_secs(0),
std::time::Duration::from_millis(1200),
),
show_menu_scrollbar: ShowMenuScrollbar::Never,
startup_checks_rate: RateLimit::new(2, 1000, context.job_executor.clone()),
theme_default: conf::value(context, "theme_default"),
id: ComponentId::new_v4(),
@ -1599,6 +1637,22 @@ impl Listing {
(width - 1, std::cmp::min(skip_offset + rows, height - 1)),
),
);
if self.show_menu_scrollbar == ShowMenuScrollbar::True && total_height > rows {
ScrollBar::default().set_show_arrows(true).draw(
grid,
(
pos_inc(upper_left!(area), (width!(area), 0)),
bottom_right!(area),
),
context,
/* position */
skip_offset,
/* visible_rows */
rows,
/* length */
total_height,
);
}
context.dirty_areas.push_back(area);
}
@ -1925,6 +1979,12 @@ impl Listing {
self.menu_cursor_pos = self.cursor_pos;
/* clear menu to force redraw */
self.menu_content.empty();
if *account_settings!(context[account_hash].listing.show_menu_scrollbar) {
self.show_menu_scrollbar = ShowMenuScrollbar::True;
self.menu_scrollbar_show_timer.rearm();
} else {
self.show_menu_scrollbar = ShowMenuScrollbar::Never;
}
}
fn open_status(&mut self, account_idx: usize, context: &mut Context) {

7
src/conf/listing.rs

@ -57,6 +57,11 @@ pub struct ListingSettings {
#[serde(default = "zero_val", alias = "context-lines")]
pub context_lines: usize,
///Show auto-hiding scrollbar in accounts sidebar menu.
///Default: True
#[serde(default = "true_val")]
pub show_menu_scrollbar: bool,
/// Datetime formatting passed verbatim to strftime(3).
/// Default: %Y-%m-%d %T
#[serde(default = "none", alias = "datetime-fmt")]
@ -104,6 +109,7 @@ impl Default for ListingSettings {
fn default() -> Self {
Self {
context_lines: 0,
show_menu_scrollbar: true,
datetime_fmt: None,
recent_dates: true,
filter: None,
@ -124,6 +130,7 @@ impl DotAddressable for ListingSettings {
let tail = &path[1..];
match *field {
"context_lines" => self.context_lines.lookup(field, tail),
"show_menu_scrollbar" => self.show_menu_scrollbar.lookup(field, tail),
"datetime_fmt" => self.datetime_fmt.lookup(field, tail),
"recent_dates" => self.recent_dates.lookup(field, tail),
"filter" => self.filter.lookup(field, tail),

5
src/conf/overrides.rs

@ -102,6 +102,10 @@ pub struct ListingSettingsOverride {
#[serde(alias = "context-lines")]
#[serde(default)]
pub context_lines: Option<usize>,
#[doc = "Show auto-hiding scrollbar in accounts sidebar menu."]
#[doc = "Default: True"]
#[serde(default)]
pub show_menu_scrollbar: Option<bool>,
#[doc = " Datetime formatting passed verbatim to strftime(3)."]
#[doc = " Default: %Y-%m-%d %T"]
#[serde(alias = "datetime-fmt")]
@ -139,6 +143,7 @@ impl Default for ListingSettingsOverride {
fn default() -> Self {
ListingSettingsOverride {
context_lines: None,
show_menu_scrollbar: None,
datetime_fmt: None,
recent_dates: None,
filter: None,

Loading…
Cancel
Save