Prevent panels from getting so small they can't be resized (#3788)

This also switches to using `Pixels` instead of `f32` to store the panel
size everywhere.

Release Notes:

- N/A
This commit is contained in:
Antonio Scandurra
2023-12-22 18:37:13 +01:00
committed by GitHub
12 changed files with 70 additions and 72 deletions
+4 -4
View File
@@ -51,7 +51,7 @@ pub struct ChatPanel {
input_editor: View<MessageEditor>,
local_timezone: UtcOffset,
fs: Arc<dyn Fs>,
width: Option<f32>,
width: Option<Pixels>,
active: bool,
pending_serialization: Task<Option<()>>,
subscriptions: Vec<gpui::Subscription>,
@@ -62,7 +62,7 @@ pub struct ChatPanel {
#[derive(Serialize, Deserialize)]
struct SerializedChatPanel {
width: Option<f32>,
width: Option<Pixels>,
}
#[derive(Debug)]
@@ -584,12 +584,12 @@ impl Panel for ChatPanel {
});
}
fn size(&self, cx: &gpui::WindowContext) -> f32 {
fn size(&self, cx: &gpui::WindowContext) -> Pixels {
self.width
.unwrap_or_else(|| ChatPanelSettings::get_global(cx).default_width)
}
fn set_size(&mut self, size: Option<f32>, cx: &mut ViewContext<Self>) {
fn set_size(&mut self, size: Option<Pixels>, cx: &mut ViewContext<Self>) {
self.width = size;
self.serialize(cx);
cx.notify();
+5 -7
View File
@@ -2314,15 +2314,13 @@ impl Panel for CollabPanel {
);
}
fn size(&self, cx: &gpui::WindowContext) -> f32 {
self.width.map_or_else(
|| CollaborationPanelSettings::get_global(cx).default_width,
|width| width.0,
)
fn size(&self, cx: &gpui::WindowContext) -> Pixels {
self.width
.unwrap_or_else(|| CollaborationPanelSettings::get_global(cx).default_width)
}
fn set_size(&mut self, size: Option<f32>, cx: &mut ViewContext<Self>) {
self.width = size.map(|s| px(s));
fn set_size(&mut self, size: Option<Pixels>, cx: &mut ViewContext<Self>) {
self.width = size;
self.serialize(cx);
cx.notify();
}
+4 -4
View File
@@ -37,7 +37,7 @@ pub struct NotificationPanel {
channel_store: Model<ChannelStore>,
notification_store: Model<NotificationStore>,
fs: Arc<dyn Fs>,
width: Option<f32>,
width: Option<Pixels>,
active: bool,
notification_list: ListState,
pending_serialization: Task<Option<()>>,
@@ -51,7 +51,7 @@ pub struct NotificationPanel {
#[derive(Serialize, Deserialize)]
struct SerializedNotificationPanel {
width: Option<f32>,
width: Option<Pixels>,
}
#[derive(Debug)]
@@ -639,12 +639,12 @@ impl Panel for NotificationPanel {
);
}
fn size(&self, cx: &gpui::WindowContext) -> f32 {
fn size(&self, cx: &gpui::WindowContext) -> Pixels {
self.width
.unwrap_or_else(|| NotificationPanelSettings::get_global(cx).default_width)
}
fn set_size(&mut self, size: Option<f32>, cx: &mut ViewContext<Self>) {
fn set_size(&mut self, size: Option<Pixels>, cx: &mut ViewContext<Self>) {
self.width = size;
self.serialize(cx);
cx.notify();
+4 -3
View File
@@ -1,4 +1,5 @@
use anyhow;
use gpui::Pixels;
use schemars::JsonSchema;
use serde_derive::{Deserialize, Serialize};
use settings::Settings;
@@ -8,21 +9,21 @@ use workspace::dock::DockPosition;
pub struct CollaborationPanelSettings {
pub button: bool,
pub dock: DockPosition,
pub default_width: f32,
pub default_width: Pixels,
}
#[derive(Deserialize, Debug)]
pub struct ChatPanelSettings {
pub button: bool,
pub dock: DockPosition,
pub default_width: f32,
pub default_width: Pixels,
}
#[derive(Deserialize, Debug)]
pub struct NotificationPanelSettings {
pub button: bool,
pub dock: DockPosition,
pub default_width: f32,
pub default_width: Pixels,
}
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]