Commit 46e081b1e4

46e081b1e4e4964eda42be91b04a7affb099a8a7

parent: 23a729e565

Unregistered key

mordquist <16607572+mordquist@users.noreply.github.com> · 2024-03-24 01:54 UTC
committer: <noreply@github.com>

Support configuring user gutter width (#223)

Layout: unified · split

docs/iamb.5.md +4
@@ -111,6 +111,10 @@ overridden as described in *PROFILES*.
111111> *protocol.font_size* is an optional list of two numbers representing font
112112> width and height in pixels.
113113
114**user_gutter_width** (type: usize)
115> Specify the width of the column where usernames are displayed in a room.
116> Usernames that are too long are truncated.
117
114118## USER OVERRIDES
115119
116120Overrides are mapped onto matrix User IDs such as _@user:matrix.org_ and are
src/config.rs +4
@@ -485,6 +485,7 @@ pub struct TunableValues {
485485 pub open_command: Option<Vec<String>>,
486486 pub notifications: Notifications,
487487 pub image_preview: Option<ImagePreviewValues>,
488 pub user_gutter_width: usize,
488489}
489490
490491#[derive(Clone, Default, Deserialize)]
@@ -507,6 +508,7 @@ pub struct Tunables {
507508 pub open_command: Option<Vec<String>>,
508509 pub notifications: Option<Notifications>,
509510 pub image_preview: Option<ImagePreview>,
511 pub user_gutter_width: Option<usize>,
510512}
511513
512514impl Tunables {
@@ -533,6 +535,7 @@ impl Tunables {
533535 open_command: self.open_command.or(other.open_command),
534536 notifications: self.notifications.or(other.notifications),
535537 image_preview: self.image_preview.or(other.image_preview),
538 user_gutter_width: self.user_gutter_width.or(other.user_gutter_width),
536539 }
537540 }
538541
@@ -555,6 +558,7 @@ impl Tunables {
555558 open_command: self.open_command,
556559 notifications: self.notifications.unwrap_or_default(),
557560 image_preview: self.image_preview.map(ImagePreview::values),
561 user_gutter_width: self.user_gutter_width.unwrap_or(30),
558562 }
559563 }
560564}
src/message/mod.rs +20 −17
@@ -120,14 +120,10 @@ const BOLD_STYLE: Style = Style {
120120 underline_color: None,
121121};
122122
123const USER_GUTTER: usize = 30;
124123const TIME_GUTTER: usize = 12;
125124const READ_GUTTER: usize = 5;
126125const MIN_MSG_LEN: usize = 30;
127126
128const USER_GUTTER_EMPTY: &str = " ";
129const USER_GUTTER_EMPTY_SPAN: Span<'static> = span_static(USER_GUTTER_EMPTY);
130
131127const TIME_GUTTER_EMPTY: &str = " ";
132128const TIME_GUTTER_EMPTY_SPAN: Span<'static> = span_static(TIME_GUTTER_EMPTY);
133129
@@ -576,10 +572,13 @@ impl<'a> MessageFormatter<'a> {
576572 text.lines.push(Line::from(vec![leading, date, trailing]));
577573 }
578574
575 let user_gutter_empty_span =
576 space_span(self.settings.tunables.user_gutter_width, Style::default());
577
579578 match self.cols {
580579 MessageColumns::Four => {
581580 let settings = self.settings;
582 let user = self.user.take().unwrap_or(USER_GUTTER_EMPTY_SPAN);
581 let user = self.user.take().unwrap_or(user_gutter_empty_span);
583582 let time = self.time.take().unwrap_or(TIME_GUTTER_EMPTY_SPAN);
584583
585584 let mut line = vec![user];
@@ -604,7 +603,7 @@ impl<'a> MessageFormatter<'a> {
604603 text.lines.push(Line::from(line))
605604 },
606605 MessageColumns::Three => {
607 let user = self.user.take().unwrap_or(USER_GUTTER_EMPTY_SPAN);
606 let user = self.user.take().unwrap_or(user_gutter_empty_span);
608607 let time = self.time.take().unwrap_or_else(|| Span::from(""));
609608
610609 let mut line = vec![user];
@@ -614,7 +613,7 @@ impl<'a> MessageFormatter<'a> {
614613 text.lines.push(Line::from(line))
615614 },
616615 MessageColumns::Two => {
617 let user = self.user.take().unwrap_or(USER_GUTTER_EMPTY_SPAN);
616 let user = self.user.take().unwrap_or(user_gutter_empty_span);
618617 let mut line = vec![user];
619618 line.extend(prev_line.spans);
620619
@@ -743,28 +742,29 @@ impl Message {
743742 Some(prev) if prev.timestamp.same_day(&self.timestamp) => None,
744743 _ => self.timestamp.show_date(),
745744 };
745 let user_gutter = settings.tunables.user_gutter_width;
746746
747 if USER_GUTTER + TIME_GUTTER + READ_GUTTER + MIN_MSG_LEN <= width &&
747 if user_gutter + TIME_GUTTER + READ_GUTTER + MIN_MSG_LEN <= width &&
748748 settings.tunables.read_receipt_display
749749 {
750750 let cols = MessageColumns::Four;
751 let fill = width - USER_GUTTER - TIME_GUTTER - READ_GUTTER;
751 let fill = width - user_gutter - TIME_GUTTER - READ_GUTTER;
752752 let user = self.show_sender(prev, true, info, settings);
753753 let time = self.timestamp.show_time();
754754 let read = info.event_receipts.get(self.event.event_id()).map(|read| read.iter());
755755
756756 MessageFormatter { settings, cols, orig, fill, user, date, time, read }
757 } else if USER_GUTTER + TIME_GUTTER + MIN_MSG_LEN <= width {
757 } else if user_gutter + TIME_GUTTER + MIN_MSG_LEN <= width {
758758 let cols = MessageColumns::Three;
759 let fill = width - USER_GUTTER - TIME_GUTTER;
759 let fill = width - user_gutter - TIME_GUTTER;
760760 let user = self.show_sender(prev, true, info, settings);
761761 let time = self.timestamp.show_time();
762762 let read = None;
763763
764764 MessageFormatter { settings, cols, orig, fill, user, date, time, read }
765 } else if USER_GUTTER + MIN_MSG_LEN <= width {
765 } else if user_gutter + MIN_MSG_LEN <= width {
766766 let cols = MessageColumns::Two;
767 let fill = width - USER_GUTTER;
767 let fill = width - user_gutter;
768768 let user = self.show_sender(prev, true, info, settings);
769769 let time = None;
770770 let read = None;
@@ -787,11 +787,13 @@ impl Message {
787787 prev: Option<&Message>,
788788 vwctx: &ViewportContext<MessageCursor>,
789789 info: &'a RoomInfo,
790 settings: &'a ApplicationSettings,
790791 ) -> Option<(&dyn Protocol, u16, u16)> {
791792 let width = vwctx.get_width();
793 let user_gutter = settings.tunables.user_gutter_width;
792794 // The x position where get_render_format would render the text.
793 let x = (if USER_GUTTER + MIN_MSG_LEN <= width {
794 USER_GUTTER
795 let x = (if user_gutter + MIN_MSG_LEN <= width {
796 user_gutter
795797 } else {
796798 0
797799 }) as u16;
@@ -1029,8 +1031,9 @@ impl Message {
10291031 }
10301032
10311033 let Span { content, style } = self.sender_span(info, settings);
1032 let ((truncated, width), _) = take_width(content, 28);
1033 let padding = 28 - width;
1034 let user_gutter = settings.tunables.user_gutter_width;
1035 let ((truncated, width), _) = take_width(content, user_gutter - 2);
1036 let padding = user_gutter - 2 - width;
10341037
10351038 let sender = if align_right {
10361039 space(padding) + &truncated + " "
src/tests.rs +1
@@ -203,6 +203,7 @@ pub fn mock_tunables() -> TunableValues {
203203 message_user_color: false,
204204 notifications: Notifications { enabled: false, show_message: None },
205205 image_preview: None,
206 user_gutter_width: 30,
206207 }
207208}
208209
src/windows/room/scrollback.rs +1 −1
@@ -1352,7 +1352,7 @@ impl<'a> StatefulWidget for Scrollback<'a> {
13521352 let txt = item.show(prev, foc && sel, &state.viewctx, info, settings);
13531353
13541354 let mut msg_preview = if picker.is_some() {
1355 item.line_preview(prev, &state.viewctx, info)
1355 item.line_preview(prev, &state.viewctx, info, settings)
13561356 } else {
13571357 None
13581358 };