Commit 172d66adb3
Unregistered key
Layout: unified · split
docs/iamb.5 +2
| @@ -821,6 +821,8 @@ there are several subsections for specific UI areas: | |||
| 821 | .Bl -tag -width Ds | 821 | .Bl -tag -width Ds |
| 822 | .It Sy default | 822 | .It Sy default |
| 823 | The base, default style that everything else should inherit. | 823 | The base, default style that everything else should inherit. |
| 824 | .It Sy selected | ||
| 825 | Additional options for how to style selected items in lists and timelines. | ||
| 824 | .It Sy cmdbar | 826 | .It Sy cmdbar |
| 825 | For controlling how the text in the command bar is styled. | 827 | For controlling how the text in the command bar is styled. |
| 826 | .Bl -tag -width Ds | 828 | .Bl -tag -width Ds |
src/config/theme.rs +20
| @@ -12,6 +12,7 @@ use crate::prelude::*; | |||
| 12 | 12 | ||
| 13 | pub fn default_theme() -> Theme { | 13 | pub fn default_theme() -> Theme { |
| 14 | Theme { | 14 | Theme { |
| 15 | selected: Stylable::with_modifiers(StyleModifier::REVERSED), | ||
| 15 | messages: ThemeMessages { | 16 | messages: ThemeMessages { |
| 16 | blockquote: LineStylable { | 17 | blockquote: LineStylable { |
| 17 | line: Some(LineName::Thick), | 18 | line: Some(LineName::Thick), |
| @@ -384,6 +385,10 @@ pub struct Theme { | |||
| 384 | #[serde(default)] | 385 | #[serde(default)] |
| 385 | default: Stylable, | 386 | default: Stylable, |
| 386 | 387 | ||
| 388 | /// Default styling to layer on top of selected list items. | ||
| 389 | #[serde(default)] | ||
| 390 | selected: Stylable, | ||
| 391 | |||
| 387 | /// Configuration for styling the command bar. | 392 | /// Configuration for styling the command bar. |
| 388 | #[serde(default)] | 393 | #[serde(default)] |
| 389 | cmdbar: ThemeCommandBar, | 394 | cmdbar: ThemeCommandBar, |
| @@ -429,6 +434,7 @@ impl Theme { | |||
| 429 | pub fn merge(self, other: Self) -> Self { | 434 | pub fn merge(self, other: Self) -> Self { |
| 430 | Self { | 435 | Self { |
| 431 | default: self.default.merge(other.default), | 436 | default: self.default.merge(other.default), |
| 437 | selected: self.selected.merge(other.selected), | ||
| 432 | cmdbar: self.cmdbar.merge(other.cmdbar), | 438 | cmdbar: self.cmdbar.merge(other.cmdbar), |
| 433 | encryption: self.encryption.merge(other.encryption), | 439 | encryption: self.encryption.merge(other.encryption), |
| 434 | msgbar: self.msgbar.merge(other.msgbar), | 440 | msgbar: self.msgbar.merge(other.msgbar), |
| @@ -447,6 +453,7 @@ impl Theme { | |||
| 447 | 453 | ||
| 448 | ThemeValues { | 454 | ThemeValues { |
| 449 | default: base, | 455 | default: base, |
| 456 | selected: Style::from(self.selected), | ||
| 450 | cmdbar: self.cmdbar.values(base), | 457 | cmdbar: self.cmdbar.values(base), |
| 451 | encryption: self.encryption.values(base), | 458 | encryption: self.encryption.values(base), |
| 452 | msgbar: self.msgbar.values(base), | 459 | msgbar: self.msgbar.values(base), |
| @@ -466,6 +473,9 @@ pub struct ThemeValues { | |||
| 466 | /// Styling to use when nothing more specific applies. | 473 | /// Styling to use when nothing more specific applies. |
| 467 | pub default: Style, | 474 | pub default: Style, |
| 468 | 475 | ||
| 476 | /// Styling to patch on top of selected list items. | ||
| 477 | pub selected: Style, | ||
| 478 | |||
| 469 | /// Styling for the command bar. | 479 | /// Styling for the command bar. |
| 470 | pub cmdbar: ThemeCommandBarValues, | 480 | pub cmdbar: ThemeCommandBarValues, |
| 471 | 481 | ||
| @@ -497,6 +507,16 @@ pub struct ThemeValues { | |||
| 497 | pub completion: ThemeCompletionValues, | 507 | pub completion: ThemeCompletionValues, |
| 498 | } | 508 | } |
| 499 | 509 | ||
| 510 | impl ThemeValues { | ||
| 511 | pub fn selected(&self, style: Style, selected: bool) -> Style { | ||
| 512 | if selected { | ||
| 513 | style.patch(self.selected) | ||
| 514 | } else { | ||
| 515 | style | ||
| 516 | } | ||
| 517 | } | ||
| 518 | } | ||
| 519 | |||
| 500 | #[derive(Clone, Debug, Default, Deserialize)] | 520 | #[derive(Clone, Debug, Default, Deserialize)] |
| 501 | struct ThemeMessages { | 521 | struct ThemeMessages { |
| 502 | #[serde(default)] | 522 | #[serde(default)] |
src/message/mod.rs +6 −4
| @@ -1103,10 +1103,6 @@ impl Message { | |||
| 1103 | fn get_render_style(&self, selected: bool, settings: &ApplicationSettings) -> Style { | 1103 | fn get_render_style(&self, selected: bool, settings: &ApplicationSettings) -> Style { |
| 1104 | let mut style = self.event.message_style(settings); | 1104 | let mut style = self.event.message_style(settings); |
| 1105 | 1105 | ||
| 1106 | if selected { | ||
| 1107 | style = style.add_modifier(StyleModifier::REVERSED) | ||
| 1108 | } | ||
| 1109 | |||
| 1110 | if matches!(self.event, MessageEvent::Local(..)) { | 1106 | if matches!(self.event, MessageEvent::Local(..)) { |
| 1111 | style = style.add_modifier(StyleModifier::ITALIC); | 1107 | style = style.add_modifier(StyleModifier::ITALIC); |
| 1112 | } | 1108 | } |
| @@ -1116,6 +1112,12 @@ impl Message { | |||
| 1116 | style = style.fg(color); | 1112 | style = style.fg(color); |
| 1117 | } | 1113 | } |
| 1118 | 1114 | ||
| 1115 | if selected { | ||
| 1116 | // Apply last, so that if the user or theme specified selected colors | ||
| 1117 | // for selected messages then it will get put on top of the user color: | ||
| 1118 | style = style.patch(settings.theme.selected); | ||
| 1119 | } | ||
| 1120 | |||
| 1119 | return style; | 1121 | return style; |
| 1120 | } | 1122 | } |
| 1121 | 1123 | ||
src/windows/mod.rs +4 −17
| @@ -48,15 +48,6 @@ pub mod welcome; | |||
| 48 | const MEMBER_FETCH_DEBOUNCE: Duration = Duration::from_secs(5); | 48 | const MEMBER_FETCH_DEBOUNCE: Duration = Duration::from_secs(5); |
| 49 | const ROOM_PREVIEW_DEBOUNCE: Duration = Duration::from_secs(15); | 49 | const ROOM_PREVIEW_DEBOUNCE: Duration = Duration::from_secs(15); |
| 50 | 50 | ||
| 51 | #[inline] | ||
| 52 | pub fn selected_style(selected: bool, style: Style) -> Style { | ||
| 53 | if selected { | ||
| 54 | style.add_modifier(StyleModifier::REVERSED) | ||
| 55 | } else { | ||
| 56 | style | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | /// Returns the number span with width 4 and the style for name and tags. | 51 | /// Returns the number span with width 4 and the style for name and tags. |
| 61 | fn unreads_and_style( | 52 | fn unreads_and_style( |
| 62 | unread: &UnreadInfo, | 53 | unread: &UnreadInfo, |
| @@ -1599,7 +1590,7 @@ impl ListItem<IambInfo> for GenericRoomItem { | |||
| 1599 | let order = store.application.settings.tunables.room_labels.as_slice(); | 1590 | let order = store.application.settings.tunables.room_labels.as_slice(); |
| 1600 | 1591 | ||
| 1601 | let (unreads, name_style, tags_style) = unreads_and_style(&self.unread, &theme.rooms); | 1592 | let (unreads, name_style, tags_style) = unreads_and_style(&self.unread, &theme.rooms); |
| 1602 | let name_style = selected_style(selected, name_style); | 1593 | let name_style = theme.selected(name_style, selected); |
| 1603 | let tags_style = if selected { name_style } else { tags_style }; | 1594 | let tags_style = if selected { name_style } else { tags_style }; |
| 1604 | 1595 | ||
| 1605 | let (name, labels) = self.name_and_labels(name_style, tags_style, order); | 1596 | let (name, labels) = self.name_and_labels(name_style, tags_style, order); |
| @@ -1678,12 +1669,12 @@ impl ListItem<IambInfo> for MemberItem { | |||
| 1678 | let theme = &store.application.settings.theme; | 1669 | let theme = &store.application.settings.theme; |
| 1679 | 1670 | ||
| 1680 | let (color, name) = store.application.settings.get_user_overrides(self.member.user_id()); | 1671 | let (color, name) = store.application.settings.get_user_overrides(self.member.user_id()); |
| 1681 | let user_style = theme.users.style(user_id.as_str(), color); | 1672 | let user_style = theme.selected(theme.users.style(user_id.as_str(), color), selected); |
| 1682 | let color = user_style.fg.unwrap_or(Color::Reset); | 1673 | let color = user_style.fg.unwrap_or(Color::Reset); |
| 1683 | 1674 | ||
| 1684 | let style = if selected { | 1675 | let style = if selected { |
| 1685 | // Ensure the whole item has the same color as `user_style` when it's selected: | 1676 | // Ensure the whole item has the same color as `user_style` when it's selected: |
| 1686 | theme.default.fg(color).add_modifier(StyleModifier::REVERSED) | 1677 | theme.default.fg(color).patch(theme.selected) |
| 1687 | } else { | 1678 | } else { |
| 1688 | theme.default | 1679 | theme.default |
| 1689 | }; | 1680 | }; |
| @@ -1818,11 +1809,7 @@ impl ListItem<IambInfo> for PinnedItem { | |||
| 1818 | ) -> Text<'a> { | 1809 | ) -> Text<'a> { |
| 1819 | let settings = &store.application.settings; | 1810 | let settings = &store.application.settings; |
| 1820 | let style = store.application.settings.theme.default; | 1811 | let style = store.application.settings.theme.default; |
| 1821 | let style = if selected { | 1812 | let style = store.application.settings.theme.selected(style, selected); |
| 1822 | style.add_modifier(StyleModifier::REVERSED) | ||
| 1823 | } else { | ||
| 1824 | style | ||
| 1825 | }; | ||
| 1826 | 1813 | ||
| 1827 | let Some(info) = store.application.rooms.get(&self.room_id) else { | 1814 | let Some(info) = store.application.rooms.get(&self.room_id) else { |
| 1828 | return Text::styled("Unable to load room information", style); | 1815 | return Text::styled("Unable to load room information", style); |
src/windows/room/message.rs +8 −6
| @@ -6,7 +6,6 @@ use crate::prelude::*; | |||
| 6 | use crate::preview::ImageStatus; | 6 | use crate::preview::ImageStatus; |
| 7 | use crate::util::space; | 7 | use crate::util::space; |
| 8 | use crate::windows::room::chat; | 8 | use crate::windows::room::chat; |
| 9 | use crate::windows::selected_style; | ||
| 10 | 9 | ||
| 11 | /// State needed for rendering [MessageWidget]. | 10 | /// State needed for rendering [MessageWidget]. |
| 12 | pub(crate) struct MessageState { | 11 | pub(crate) struct MessageState { |
| @@ -472,8 +471,10 @@ impl ListItem<IambInfo> for MessageInfoItem { | |||
| 472 | viewctx: &ViewportContext<ListCursor>, | 471 | viewctx: &ViewportContext<ListCursor>, |
| 473 | store: &'a ProgramStore, | 472 | store: &'a ProgramStore, |
| 474 | ) -> Text<'a> { | 473 | ) -> Text<'a> { |
| 475 | let style = store.application.settings.theme.timeline.default; | 474 | let theme = &store.application.settings.theme; |
| 476 | let style = selected_style(selected, style); | 475 | let style = theme.timeline.default; |
| 476 | let style = theme.selected(style, selected); | ||
| 477 | |||
| 477 | match self { | 478 | match self { |
| 478 | MessageInfoItem::Header(room_id, user_id, timestamp) => { | 479 | MessageInfoItem::Header(room_id, user_id, timestamp) => { |
| 479 | let info = store.application.rooms.get(room_id); | 480 | let info = store.application.rooms.get(room_id); |
| @@ -502,9 +503,9 @@ impl ListItem<IambInfo> for MessageInfoItem { | |||
| 502 | } | 503 | } |
| 503 | 504 | ||
| 504 | let padding = width - user.len() - date.len(); | 505 | let padding = width - user.len() - date.len(); |
| 505 | let date_style = store.application.settings.theme.timeline.date; | 506 | let date_style = theme.timeline.date; |
| 506 | 507 | ||
| 507 | let line = Span::styled(user, style.patch(user_style)) + | 508 | let line = Span::styled(user, theme.selected(user_style, selected)) + |
| 508 | Span::raw(space(padding)) + | 509 | Span::raw(space(padding)) + |
| 509 | Span::styled(date, date_style); | 510 | Span::styled(date, date_style); |
| 510 | line.into() | 511 | line.into() |
| @@ -531,7 +532,8 @@ impl ListItem<IambInfo> for MessageInfoItem { | |||
| 531 | MessageInfoItem::User(_, room_id, user_id) => { | 532 | MessageInfoItem::User(_, room_id, user_id) => { |
| 532 | let info = store.application.rooms.get(room_id); | 533 | let info = store.application.rooms.get(room_id); |
| 533 | let user = store.application.settings.get_user_span_maybe(user_id, info); | 534 | let user = store.application.settings.get_user_span_maybe(user_id, info); |
| 534 | let user_span = Span::styled(user.content.into_owned(), style.patch(user.style)); | 535 | let user_span = |
| 536 | Span::styled(user.content.into_owned(), theme.selected(user.style, selected)); | ||
| 535 | 537 | ||
| 536 | Text::from(Span::raw("- ") + user_span) | 538 | Text::from(Span::raw("- ") + user_span) |
| 537 | }, | 539 | }, |
src/windows/verify.rs +1 −1
| @@ -144,7 +144,7 @@ impl ListItem<IambInfo> for VerifyItem { | |||
| 144 | let mut lines = vec![]; | 144 | let mut lines = vec![]; |
| 145 | let style = store.application.settings.theme.default; | 145 | let style = store.application.settings.theme.default; |
| 146 | let bold = style.bold(); | 146 | let bold = style.bold(); |
| 147 | let selected = super::selected_style(selected, style); | 147 | let selected = store.application.settings.theme.selected(style, selected); |
| 148 | 148 | ||
| 149 | let mut other_device = None; | 149 | let mut other_device = None; |
| 150 | let state = match self.request.state() { | 150 | let state = match self.request.state() { |