Adjust file finder width configuration (#20819)
Follow up to: https://github.com/zed-industries/zed/pull/18682 This PR tweaks the setting value, so it's clear we're referring to `max-width`, meaning the width will change up to a specific value depending on the available window size. Then, it also makes `Small` the default value, which, in practice, makes the modal size the same as it was before the original PR linked above. Release Notes: - N/A --------- Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
This commit is contained in:
parent
d265e44209
commit
37899187c6
4 changed files with 44 additions and 59 deletions
|
@ -2,13 +2,11 @@ use anyhow::Result;
|
|||
use schemars::JsonSchema;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use settings::{Settings, SettingsSources};
|
||||
use std::cmp;
|
||||
use ui::Pixels;
|
||||
|
||||
#[derive(Deserialize, Debug, Clone, Copy, PartialEq)]
|
||||
pub struct FileFinderSettings {
|
||||
pub file_icons: bool,
|
||||
pub modal_width: FileFinderWidth,
|
||||
pub modal_max_width: Option<FileFinderWidth>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
|
||||
|
@ -17,10 +15,10 @@ pub struct FileFinderSettingsContent {
|
|||
///
|
||||
/// Default: true
|
||||
pub file_icons: Option<bool>,
|
||||
/// The width of the file finder modal.
|
||||
/// Determines how much space the file finder can take up in relation to the available window width.
|
||||
///
|
||||
/// Default: "medium"
|
||||
pub modal_width: Option<FileFinderWidth>,
|
||||
/// Default: small
|
||||
pub modal_max_width: Option<FileFinderWidth>,
|
||||
}
|
||||
|
||||
impl Settings for FileFinderSettings {
|
||||
|
@ -36,40 +34,10 @@ impl Settings for FileFinderSettings {
|
|||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Default, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum FileFinderWidth {
|
||||
Small,
|
||||
#[default]
|
||||
Small,
|
||||
Medium,
|
||||
Large,
|
||||
XLarge,
|
||||
Full,
|
||||
}
|
||||
|
||||
impl FileFinderWidth {
|
||||
const MIN_MODAL_WIDTH_PX: f32 = 384.;
|
||||
|
||||
pub fn padding_px(&self) -> Pixels {
|
||||
let padding_val = match self {
|
||||
FileFinderWidth::Small => 1280.,
|
||||
FileFinderWidth::Medium => 1024.,
|
||||
FileFinderWidth::Large => 768.,
|
||||
FileFinderWidth::XLarge => 512.,
|
||||
FileFinderWidth::Full => 0.,
|
||||
};
|
||||
|
||||
Pixels(padding_val)
|
||||
}
|
||||
|
||||
pub fn calc_width(&self, window_width: Pixels) -> Pixels {
|
||||
if self == &FileFinderWidth::Full {
|
||||
return window_width;
|
||||
}
|
||||
|
||||
let min_modal_width_px = Pixels(FileFinderWidth::MIN_MODAL_WIDTH_PX);
|
||||
|
||||
let padding_px = self.padding_px();
|
||||
let width_val = window_width - padding_px;
|
||||
let finder_width = cmp::max(min_modal_width_px, width_val);
|
||||
|
||||
finder_width
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue