Skip to content

Commit 5f7d673

Browse files
authored
Merge pull request #1427 from squidowl/issue/1426
Add configurable preview dimensions and limit card description height
2 parents ca7dd78 + 47bbfc8 commit 5f7d673

File tree

5 files changed

+114
-15
lines changed

5 files changed

+114
-15
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ Added:
55
- Settings to disable (selectively, or for the entire server) confirmation of delivery for sent messages
66
- Setting to adjust inner spacing and outer padding for panes (`pane.gap.inner`, `pane.gap.outer`)
77
- Setting to style unread query buffers as highlights in the sidebar (`sidebar.unread_indicator.query_as_highlight`)
8+
- Settings to configure card and imagge preview dimensions
89

910
Fixed:
1011

1112
- Buffer not showing history until resize
1213
- Previews are fetched through the same proxy as the server (or default proxy) for HTTP/SOCKS5 proxies
1314
- No longer highlight nickname mentions in sent messages in certain scenarios
1415
- Filters applied to one server will no longer hide query panes for other servers
16+
- Card preview description text is now limited in height to prevent excessive text display
1517

1618
Changed:
1719

book/src/configuration/preview/card.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ Specific card preview settings.
77
- [Configuration](#configuration)
88
- [show\_image](#show_image)
99
- [round\_image\_corners](#round_image_corners)
10+
- [max\_width](#max_width)
11+
- [description\_max\_height](#description_max_height)
12+
- [image\_max\_height](#image_max_height)
1013
- [include](#include)
1114
- [exclude](#exclude)
1215

@@ -46,6 +49,45 @@ Round the corners of the image in the card preview (if shown).
4649
round_image_corners = true
4750
```
4851

52+
### max_width
53+
54+
Maximum width of the card in pixels.
55+
56+
```toml
57+
# Type: number
58+
# Values: any positive number
59+
# Default: 400.0
60+
61+
[preview.card]
62+
max_width = 400.0
63+
```
64+
65+
### description_max_height
66+
67+
Maximum height of the description text in pixels.
68+
69+
```toml
70+
# Type: number
71+
# Values: any positive number
72+
# Default: 100.0
73+
74+
[preview.card]
75+
description_max_height = 100.0
76+
```
77+
78+
### image_max_height
79+
80+
Maximum height of the image in the card preview in pixels.
81+
82+
```toml
83+
# Type: number
84+
# Values: any positive number
85+
# Default: 200.0
86+
87+
[preview.card]
88+
image_max_height = 200.0
89+
```
90+
4991
### exclude
5092

5193
[Exclusion conditions](/configuration/conditions.md) for when card previews will

book/src/configuration/preview/image.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Specific image preview settings.
77
- [Configuration](#configuration)
88
- [action](#action)
99
- [round\_corners](#round_corners)
10+
- [max\_width](#max_width)
11+
- [max\_height](#max_height)
1012
- [include](#include)
1113
- [exclude](#exclude)
1214

@@ -46,6 +48,32 @@ Round the corners of the image.
4648
round_corners = true
4749
```
4850

51+
### max_width
52+
53+
Maximum width of the image in pixels.
54+
55+
```toml
56+
# Type: number
57+
# Values: any positive number
58+
# Default: 550.0
59+
60+
[preview.image]
61+
max_width = 550.0
62+
```
63+
64+
### max_height
65+
66+
Maximum height of the image in pixels.
67+
68+
```toml
69+
# Type: number
70+
# Values: any positive number
71+
# Default: 350.0
72+
73+
[preview.image]
74+
max_height = 350.0
75+
```
76+
4977
### exclude
5078

5179
[Exclusion conditions](/configuration/conditions.md) for when image previews

data/src/config/preview.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ pub struct Card {
168168
pub include: Option<Inclusivities>,
169169
pub show_image: bool,
170170
pub round_image_corners: bool,
171+
/// Maximum width of the card in pixels
172+
pub max_width: f32,
173+
/// Maximum height of the description in pixels
174+
pub description_max_height: f32,
175+
/// Maximum height of the image in pixels
176+
pub image_max_height: f32,
171177
}
172178

173179
impl Default for Card {
@@ -177,6 +183,9 @@ impl Default for Card {
177183
include: None,
178184
show_image: true,
179185
round_image_corners: true,
186+
max_width: 400.0,
187+
description_max_height: 100.0,
188+
image_max_height: 200.0,
180189
}
181190
}
182191
}
@@ -223,6 +232,10 @@ pub struct Image {
223232
pub exclude: Option<Inclusivities>,
224233
pub include: Option<Inclusivities>,
225234
pub round_corners: bool,
235+
/// Maximum width of the image in pixels
236+
pub max_width: f32,
237+
/// Maximum height of the image in pixels
238+
pub max_height: f32,
226239
}
227240

228241
impl Default for Image {
@@ -232,6 +245,8 @@ impl Default for Image {
232245
exclude: None,
233246
include: None,
234247
round_corners: true,
248+
max_width: 550.0,
249+
max_height: 350.0,
235250
}
236251
}
237252
}

src/buffer/scroll_view.rs

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,13 +1481,20 @@ fn preview_row<'a>(
14811481
.map(font::get)
14821482
),
14831483
description.as_ref().map(|description| {
1484-
text(description)
1485-
.shaping(text::Shaping::Advanced)
1486-
.style(theme::text::secondary)
1487-
.font_maybe(
1488-
theme::font_style::secondary(theme)
1489-
.map(font::get),
1490-
)
1484+
container(
1485+
text(description)
1486+
.shaping(text::Shaping::Advanced)
1487+
.wrapping(text::Wrapping::WordOrGlyph)
1488+
.style(theme::text::secondary)
1489+
.font_maybe(
1490+
theme::font_style::secondary(theme)
1491+
.map(font::get),
1492+
),
1493+
)
1494+
.clip(false)
1495+
.max_height(
1496+
config.preview.card.description_max_height,
1497+
)
14911498
}),
14921499
config.preview.card.show_image.then_some(
14931500
container(
@@ -1505,11 +1512,12 @@ fn preview_row<'a>(
15051512
)
15061513
.content_fit(ContentFit::ScaleDown)
15071514
)
1508-
.max_height(200)
1515+
.padding(Padding::default().top(8))
1516+
.max_height(config.preview.card.image_max_height)
15091517
),
15101518
]
15111519
.spacing(8)
1512-
.max_width(400),
1520+
.max_width(config.preview.card.max_width),
15131521
)
15141522
.padding(8),
15151523
)
@@ -1528,8 +1536,8 @@ fn preview_row<'a>(
15281536
})
15291537
.content_fit(ContentFit::ScaleDown),
15301538
)
1531-
.max_width(550)
1532-
.max_height(350),
1539+
.max_width(config.preview.image.max_width)
1540+
.max_height(config.preview.image.max_height),
15331541
)
15341542
.on_press(match config.preview.image.action {
15351543
data::config::preview::ImageAction::OpenUrl => {
@@ -1550,9 +1558,12 @@ fn preview_row<'a>(
15501558
.map(|timestamp| {
15511559
selectable_text(" ".repeat(timestamp.chars().count()))
15521560
});
1561+
let space = selectable_text(" ");
15531562

15541563
let aligned_content = match &config.buffer.nickname.alignment {
1555-
data::buffer::Alignment::Left => row![timestamp_gap, content].into(),
1564+
data::buffer::Alignment::Left => {
1565+
row![timestamp_gap, space, content].into()
1566+
}
15561567
data::buffer::Alignment::Right => {
15571568
let prefixes = message.target.prefixes().map_or(
15581569
right_aligned_width.and_then(|_| {
@@ -1581,7 +1592,6 @@ fn preview_row<'a>(
15811592
},
15821593
);
15831594

1584-
let space = selectable_text(" ");
15851595
let with_access_levels = config.buffer.nickname.show_access_levels;
15861596
let truncate = config.buffer.nickname.truncate;
15871597

@@ -1610,9 +1620,11 @@ fn preview_row<'a>(
16101620
};
16111621

16121622
let timestamp_nickname_row =
1613-
row![timestamp_gap, prefixes, nick, space,];
1623+
row![timestamp_gap, space, prefixes, nick];
1624+
1625+
let space = selectable_text(" ");
16141626

1615-
row![timestamp_nickname_row, content].into()
1627+
row![timestamp_nickname_row, space, content].into()
16161628
}
16171629
data::buffer::Alignment::Top => content,
16181630
};

0 commit comments

Comments
 (0)