Skip to content

Commit f665d69

Browse files
alocquetStephan Dilly
authored andcommitted
feat: dynamic branch popup size
1 parent b21fad7 commit f665d69

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/components/select_branch.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,20 @@ impl DrawableComponent for SelectBranchComponent {
4545
// Render a scrolllist of branches inside a box
4646

4747
if self.visible {
48-
const SIZE: (u16, u16) = (50, 20);
49-
let scroll_threshold = SIZE.1 / 3;
48+
const PERCENT_SIZE: (u16, u16) = (60, 25);
49+
const MIN_SIZE: (u16, u16) = (50, 20);
50+
51+
let area = ui::centered_rect(
52+
PERCENT_SIZE.0,
53+
PERCENT_SIZE.1,
54+
f.size(),
55+
);
56+
let area = ui::rect_min(MIN_SIZE.0, MIN_SIZE.1, area);
57+
58+
let scroll_threshold = area.height / 3;
5059
let scroll =
5160
self.selection.saturating_sub(scroll_threshold);
5261

53-
let area =
54-
ui::centered_rect_absolute(SIZE.0, SIZE.1, f.size());
55-
5662
f.render_widget(Clear, area);
5763
f.render_widget(
5864
Block::default()
@@ -275,15 +281,17 @@ impl SelectBranchComponent {
275281
theme: &SharedTheme,
276282
width_available: u16,
277283
) -> Result<Text> {
278-
const BRANCH_NAME_LENGTH: usize = 15;
279284
const COMMIT_HASH_LENGTH: usize = 8;
280285
const IS_HEAD_STAR_LENGTH: usize = 3; // "* "
281286
const THREE_DOTS_LENGTH: usize = 3; // "..."
282287

288+
// branch name = 30% of area size
289+
let branch_name_length: usize =
290+
width_available as usize * 30 / 100;
283291
// commit message takes up the remaining width
284292
let commit_message_length: usize = (width_available as usize)
285293
.saturating_sub(COMMIT_HASH_LENGTH)
286-
.saturating_sub(BRANCH_NAME_LENGTH)
294+
.saturating_sub(branch_name_length)
287295
.saturating_sub(IS_HEAD_STAR_LENGTH)
288296
.saturating_sub(THREE_DOTS_LENGTH);
289297
let mut txt = Vec::new();
@@ -301,9 +309,9 @@ impl SelectBranchComponent {
301309
}
302310

303311
let mut branch_name = displaybranch.name.clone();
304-
if branch_name.len() > BRANCH_NAME_LENGTH {
312+
if branch_name.len() > branch_name_length {
305313
branch_name.truncate(
306-
BRANCH_NAME_LENGTH
314+
branch_name_length
307315
.saturating_sub(THREE_DOTS_LENGTH),
308316
);
309317
branch_name += "...";
@@ -322,7 +330,7 @@ impl SelectBranchComponent {
322330
format!(
323331
">{:w$} ",
324332
branch_name,
325-
w = BRANCH_NAME_LENGTH
333+
w = branch_name_length
326334
),
327335
theme.commit_author(true),
328336
),
@@ -348,7 +356,7 @@ impl SelectBranchComponent {
348356
format!(
349357
" {:w$} ",
350358
branch_name,
351-
w = BRANCH_NAME_LENGTH
359+
w = branch_name_length
352360
),
353361
theme.commit_author(false),
354362
),

0 commit comments

Comments
 (0)