fix(discovery): keep version popup size stable
This commit is contained in:
1 parent
5e3699b64d
commit
c1af0f1b51
2 files changed
+3
-26
No files matched your search
@@ -44,15 +44,6 @@ fn discovery_version_rows_only_show_the_version_number() {
|
||||
assert_eq!(discovery_version_label(&version), "3.2.4-fabric-26.1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn discovery_version_popup_uses_compact_heights() {
|
||||
assert_eq!(version_popup_height(1, false, false, false), 6);
|
||||
assert_eq!(version_popup_height(100, false, false, false), 18);
|
||||
assert_eq!(version_popup_height(1, true, false, false), 8);
|
||||
assert_eq!(version_popup_height(0, false, true, false), 5);
|
||||
assert_eq!(version_popup_height(0, false, false, true), 8);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn discovery_version_popup_renders_over_a_project_page() {
|
||||
use crate::instance::ContentKind;
|
||||
|
||||
@@ -20,6 +20,8 @@ use crate::tui::widgets::styled_title;
|
||||
type ContentScanner =
|
||||
fn(&std::path::Path, &str, bool) -> crate::instance::content::entry::ContentEntry;
|
||||
|
||||
const VERSION_POPUP_HEIGHT: u16 = 18;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct DownloadableTab {
|
||||
directory: &'static str,
|
||||
@@ -614,15 +616,9 @@ fn render_version_popup(frame: &mut Frame, area: Rect, state: &DiscoveryState) {
|
||||
let Some(popup) = state.version_popup.as_ref() else {
|
||||
return;
|
||||
};
|
||||
let desired_height = version_popup_height(
|
||||
popup.versions.len(),
|
||||
popup.confirming,
|
||||
popup.loading || popup.installing,
|
||||
popup.error.is_some(),
|
||||
);
|
||||
let popup_area = area.centered(
|
||||
Constraint::Percentage(50),
|
||||
Constraint::Length(desired_height.min(area.height.saturating_sub(2))),
|
||||
Constraint::Length(VERSION_POPUP_HEIGHT.min(area.height.saturating_sub(2))),
|
||||
);
|
||||
let theme = THEME.as_ref();
|
||||
let title = popup.title();
|
||||
@@ -731,16 +727,6 @@ fn render_version_popup(frame: &mut Frame, area: Rect, state: &DiscoveryState) {
|
||||
frame.render_widget(popup, popup_area);
|
||||
}
|
||||
|
||||
fn version_popup_height(version_count: usize, confirming: bool, compact: bool, error: bool) -> u16 {
|
||||
if confirming || error {
|
||||
8
|
||||
} else if compact {
|
||||
5
|
||||
} else {
|
||||
(version_count as u16).saturating_add(2).clamp(6, 18)
|
||||
}
|
||||
}
|
||||
|
||||
fn confirmation_values(values: &[String]) -> String {
|
||||
if values.is_empty() {
|
||||
"Unknown".to_owned()
|
||||
|
||||
Reference in new issue
Block a user