fix: label detected default resolution
This commit is contained in:
1 parent
78ea2f0f54
commit
429e46b7b7
3 files changed
+65
-15
No files matched your search
@@ -23,10 +23,11 @@ use crate::{
|
|||||||
tui::widgets::popups::settings_controls::{
|
tui::widgets::popups::settings_controls::{
|
||||||
DisplayResolution, JavaChoice, JavaPicker, ResolutionChoice, ResolutionPickerAction,
|
DisplayResolution, JavaChoice, JavaPicker, ResolutionChoice, ResolutionPickerAction,
|
||||||
SettingsPicker, SettingsPickerAction, SettingsPickerOption, adjust_memory, auto_label,
|
SettingsPicker, SettingsPickerAction, SettingsPickerOption, adjust_memory, auto_label,
|
||||||
display_resolutions, environment_labels, handle_resolution_picker_key,
|
default_label, default_resolution, display_resolutions, environment_labels,
|
||||||
handle_text_area_input, memory_kib, parse_environment, render_memory_gauge,
|
handle_resolution_picker_key, handle_text_area_input, is_default_resolution, memory_kib,
|
||||||
render_settings_picker, resolution_choices, resolution_items, settings_text_area,
|
parse_environment, render_memory_gauge, render_settings_picker, resolution_choices,
|
||||||
tagged_row_count, tagged_value_lines, toggle_window_mode,
|
resolution_items, settings_text_area, tagged_row_count, tagged_value_lines,
|
||||||
|
toggle_window_mode,
|
||||||
},
|
},
|
||||||
tui::widgets::status_badge,
|
tui::widgets::status_badge,
|
||||||
};
|
};
|
||||||
@@ -459,8 +460,8 @@ impl State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn apply_default_resolution(&mut self) {
|
fn apply_default_resolution(&mut self) {
|
||||||
if let Some(display) = self.display_resolutions.first() {
|
if let Some(resolution) = default_resolution(&self.display_resolutions) {
|
||||||
self.config.defaults.resolution = Some((display.width, display.height));
|
self.config.defaults.resolution = Some(resolution);
|
||||||
self.save_pending = true;
|
self.save_pending = true;
|
||||||
self.error = None;
|
self.error = None;
|
||||||
} else {
|
} else {
|
||||||
@@ -1109,6 +1110,12 @@ fn global_field_line(state: &State, index: usize, label: &str) -> Line<'static>
|
|||||||
if index == 2 && state.config.ui.image_protocol == ImageProtocol::Auto && !editing {
|
if index == 2 && state.config.ui.image_protocol == ImageProtocol::Auto && !editing {
|
||||||
spans.extend([Span::raw(" "), auto_label()]);
|
spans.extend([Span::raw(" "), auto_label()]);
|
||||||
}
|
}
|
||||||
|
if index == 7
|
||||||
|
&& !editing
|
||||||
|
&& is_default_resolution(state.config.defaults.resolution, &state.display_resolutions)
|
||||||
|
{
|
||||||
|
spans.extend([Span::raw(" "), default_label()]);
|
||||||
|
}
|
||||||
if index == 10 && !editing {
|
if index == 10 && !editing {
|
||||||
spans.push(Span::raw(" "));
|
spans.push(Span::raw(" "));
|
||||||
spans.push(match state.config.content.preferred_provider {
|
spans.push(match state.config.content.preferred_provider {
|
||||||
@@ -1363,6 +1370,11 @@ mod tests {
|
|||||||
Action::Save(..)
|
Action::Save(..)
|
||||||
));
|
));
|
||||||
assert_eq!(state.config.defaults.resolution, Some((2560, 1440)));
|
assert_eq!(state.config.defaults.resolution, Some((2560, 1440)));
|
||||||
|
assert!(
|
||||||
|
global_field_line(&state, 7, field_label(7))
|
||||||
|
.to_string()
|
||||||
|
.contains("Default")
|
||||||
|
);
|
||||||
state.handle_key(&KeyEvent::from(KeyCode::Enter));
|
state.handle_key(&KeyEvent::from(KeyCode::Enter));
|
||||||
assert_eq!(state.choice_picker, Some(ChoicePicker::Resolution));
|
assert_eq!(state.choice_picker, Some(ChoicePicker::Resolution));
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
|
|||||||
@@ -31,8 +31,9 @@ use crate::{
|
|||||||
DisplayResolution, GlfwChoice, GlfwPicker, JavaChoice, JavaPicker,
|
DisplayResolution, GlfwChoice, GlfwPicker, JavaChoice, JavaPicker,
|
||||||
ResolutionChoice, ResolutionPickerAction, SettingsPicker, SettingsPickerAction,
|
ResolutionChoice, ResolutionPickerAction, SettingsPicker, SettingsPickerAction,
|
||||||
SettingsPickerBadge, SettingsPickerOption, adjust_memory, auto_label,
|
SettingsPickerBadge, SettingsPickerOption, adjust_memory, auto_label,
|
||||||
bundled_glfw_version, bundled_label as bundled_badge, display_resolutions,
|
bundled_glfw_version, bundled_label as bundled_badge, default_label,
|
||||||
environment_labels, handle_resolution_picker_key, handle_text_area_input,
|
default_resolution, display_resolutions, environment_labels,
|
||||||
|
handle_resolution_picker_key, handle_text_area_input, is_default_resolution,
|
||||||
memory_kib, parse_environment, render_memory_gauge, render_settings_picker,
|
memory_kib, parse_environment, render_memory_gauge, render_settings_picker,
|
||||||
resolution_choices, resolution_items, settings_text_area, tagged_row_count,
|
resolution_choices, resolution_items, settings_text_area, tagged_row_count,
|
||||||
tagged_value_lines, toggle_window_mode,
|
tagged_value_lines, toggle_window_mode,
|
||||||
@@ -737,12 +738,6 @@ impl State {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_resolution(&self) -> Option<(u32, u32)> {
|
|
||||||
self.display_resolutions
|
|
||||||
.first()
|
|
||||||
.map(|display| (display.width, display.height))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn apply_default_memory(&mut self) {
|
fn apply_default_memory(&mut self) {
|
||||||
let settings = SETTINGS.read();
|
let settings = SETTINGS.read();
|
||||||
if self.selected == 4 {
|
if self.selected == 4 {
|
||||||
@@ -754,7 +749,7 @@ impl State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn apply_default_resolution(&mut self) {
|
fn apply_default_resolution(&mut self) {
|
||||||
if let Some(resolution) = self.default_resolution() {
|
if let Some(resolution) = default_resolution(&self.display_resolutions) {
|
||||||
self.draft.resolution = Some(resolution);
|
self.draft.resolution = Some(resolution);
|
||||||
self.draft.inherit_resolution = false;
|
self.draft.inherit_resolution = false;
|
||||||
self.error = None;
|
self.error = None;
|
||||||
@@ -1497,6 +1492,13 @@ fn field_line(state: &State, index: usize, label: &str) -> Line<'static> {
|
|||||||
if index == 14 && state.draft.glfw_path.is_none() && !editing {
|
if index == 14 && state.draft.glfw_path.is_none() && !editing {
|
||||||
spans.extend([Span::raw(" "), bundled_badge()]);
|
spans.extend([Span::raw(" "), bundled_badge()]);
|
||||||
}
|
}
|
||||||
|
if index == 9
|
||||||
|
&& !editing
|
||||||
|
&& !state.draft.inherit_resolution
|
||||||
|
&& is_default_resolution(state.draft.resolution, &state.display_resolutions)
|
||||||
|
{
|
||||||
|
spans.extend([Span::raw(" "), default_label()]);
|
||||||
|
}
|
||||||
if (index == 8 && state.draft.inherit_window_mode)
|
if (index == 8 && state.draft.inherit_window_mode)
|
||||||
|| (index == 9 && state.draft.inherit_resolution)
|
|| (index == 9 && state.draft.inherit_resolution)
|
||||||
{
|
{
|
||||||
@@ -2003,6 +2005,11 @@ mod tests {
|
|||||||
state.draft.resolution = Some((1920, 1080));
|
state.draft.resolution = Some((1920, 1080));
|
||||||
state.handle_key(&KeyEvent::from(KeyCode::Char('d')));
|
state.handle_key(&KeyEvent::from(KeyCode::Char('d')));
|
||||||
assert_eq!(state.draft.resolution, Some((2560, 1440)));
|
assert_eq!(state.draft.resolution, Some((2560, 1440)));
|
||||||
|
assert!(
|
||||||
|
field_line(&state, 9, field_label(9))
|
||||||
|
.to_string()
|
||||||
|
.contains("Default")
|
||||||
|
);
|
||||||
state.handle_key(&KeyEvent::from(KeyCode::Enter));
|
state.handle_key(&KeyEvent::from(KeyCode::Enter));
|
||||||
assert!(!state.choice_values().iter().any(|value| value == "Default"));
|
assert!(!state.choice_values().iter().any(|value| value == "Default"));
|
||||||
assert!(!state.choice_values().iter().any(|value| value == "Custom…"));
|
assert!(!state.choice_values().iter().any(|value| value == "Custom…"));
|
||||||
|
|||||||
@@ -1047,6 +1047,10 @@ pub(crate) fn bundled_label() -> Span<'static> {
|
|||||||
status_badge("Bundled", THEME.as_ref().success())
|
status_badge("Bundled", THEME.as_ref().success())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn default_label() -> Span<'static> {
|
||||||
|
status_badge("Default", THEME.as_ref().success())
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn render_settings_picker(
|
pub(crate) fn render_settings_picker(
|
||||||
picker: &SettingsPicker,
|
picker: &SettingsPicker,
|
||||||
area: Rect,
|
area: Rect,
|
||||||
@@ -1080,6 +1084,19 @@ pub(crate) fn display_resolutions() -> Vec<DisplayResolution> {
|
|||||||
resolutions
|
resolutions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn default_resolution(displays: &[DisplayResolution]) -> Option<(u32, u32)> {
|
||||||
|
displays
|
||||||
|
.first()
|
||||||
|
.map(|display| (display.width, display.height))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn is_default_resolution(
|
||||||
|
resolution: Option<(u32, u32)>,
|
||||||
|
displays: &[DisplayResolution],
|
||||||
|
) -> bool {
|
||||||
|
default_resolution(displays).is_some_and(|default| resolution == Some(default))
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn resolution_choices(
|
pub(crate) fn resolution_choices(
|
||||||
current: Option<(u32, u32)>,
|
current: Option<(u32, u32)>,
|
||||||
displays: &[DisplayResolution],
|
displays: &[DisplayResolution],
|
||||||
@@ -1171,6 +1188,20 @@ mod tests {
|
|||||||
assert_eq!(adjust_memory("512M", false), "512M");
|
assert_eq!(adjust_memory("512M", false), "512M");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn first_detected_display_is_the_default_resolution() {
|
||||||
|
let displays = vec![DisplayResolution {
|
||||||
|
width: 1440,
|
||||||
|
height: 2560,
|
||||||
|
name: "DP-1".to_owned(),
|
||||||
|
primary: true,
|
||||||
|
}];
|
||||||
|
|
||||||
|
assert_eq!(default_resolution(&displays), Some((1440, 2560)));
|
||||||
|
assert!(is_default_resolution(Some((1440, 2560)), &displays));
|
||||||
|
assert!(!is_default_resolution(Some((854, 480)), &displays));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn java_picker_preserves_semantic_selection_when_results_arrive() {
|
fn java_picker_preserves_semantic_selection_when_results_arrive() {
|
||||||
let mut picker = JavaPicker::new();
|
let mut picker = JavaPicker::new();
|
||||||
|
|||||||
Reference in new issue
Block a user