From 639b8425d9dd4d3880aa2af13f6f77624a512165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20=C2=B7=20Misaki=20Masa?= Date: Wed, 16 Aug 2023 16:41:18 +0800 Subject: [PATCH] fix: wrong height of `Select` component (#65) --- core/src/select/option.rs | 6 ++++-- core/src/select/select.rs | 4 +--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/select/option.rs b/core/src/select/option.rs index da1c8a25..eaf41037 100644 --- a/core/src/select/option.rs +++ b/core/src/select/option.rs @@ -10,20 +10,22 @@ pub struct SelectOpt { impl SelectOpt { pub fn top(title: &str, items: Vec) -> Self { + let height = 2 + items.len().min(/* TODO: hardcode */ 5) as u16; Self { title: title.to_owned(), items, - position: Position::Top(/* TODO: hardcode */ Rect { x: 0, y: 2, width: 50, height: 3 }), + position: Position::Top(/* TODO: hardcode */ Rect { x: 0, y: 2, width: 50, height }), } } pub fn hovered(title: &str, items: Vec) -> Self { + let height = 2 + items.len().min(/* TODO: hardcode */ 5) as u16; Self { title: title.to_owned(), items, position: Position::Hovered( // TODO: hardcode - Rect { x: 0, y: 1, width: 50, height: 3 }, + Rect { x: 0, y: 1, width: 50, height }, ), } } diff --git a/core/src/select/select.rs b/core/src/select/select.rs index 92dadbcf..ca9a1626 100644 --- a/core/src/select/select.rs +++ b/core/src/select/select.rs @@ -76,9 +76,7 @@ impl Select { } #[inline] - pub fn limit(&self) -> usize { - self.items.len().min(tty_size().ws_row.saturating_sub(SELECT_PADDING).min(5) as usize) - } + pub fn limit(&self) -> usize { self.items.len().min(5) } } impl Select {