This PR adds a `NumericStepper` component that can be used to display a numeric value along with controls to increment, decrement, and reset the value. The `ApplicationMenu` has been updated to use the `NumericStepper` for adjusting the buffer and UI font size. Here it is in action: https://github.com/zed-industries/zed/assets/1486634/03cffe67-1256-4283-aa3d-560fffa06dad Note: Due to the way we do font adjustments, once modified the reset button will be displayed until it is clicked (or the font size adjustment is otherwise reset). Simply returning to the original value will currently not hide the reset button. Release Notes: - N/A
129 lines
6.1 KiB
Rust
129 lines
6.1 KiB
Rust
use ui::{prelude::*, ContextMenu, NumericStepper, PopoverMenu, Tooltip};
|
|
|
|
#[derive(IntoElement)]
|
|
pub struct ApplicationMenu;
|
|
|
|
impl ApplicationMenu {
|
|
pub fn new() -> Self {
|
|
Self
|
|
}
|
|
}
|
|
|
|
impl RenderOnce for ApplicationMenu {
|
|
fn render(self, _cx: &mut WindowContext) -> impl IntoElement {
|
|
PopoverMenu::new("application-menu")
|
|
.menu(move |cx| {
|
|
ContextMenu::build(cx, move |menu, _cx| {
|
|
menu.header("Workspace")
|
|
.action("Open Command Palette", Box::new(command_palette::Toggle))
|
|
.custom_row(move |cx| {
|
|
h_flex()
|
|
.gap_2()
|
|
.w_full()
|
|
.justify_between()
|
|
.cursor(gpui::CursorStyle::Arrow)
|
|
.child(Label::new("Buffer Font Size"))
|
|
.child(
|
|
NumericStepper::new(
|
|
theme::get_buffer_font_size(cx).to_string(),
|
|
|_, cx| {
|
|
cx.dispatch_action(Box::new(
|
|
zed_actions::DecreaseBufferFontSize,
|
|
))
|
|
},
|
|
|_, cx| {
|
|
cx.dispatch_action(Box::new(
|
|
zed_actions::IncreaseBufferFontSize,
|
|
))
|
|
},
|
|
)
|
|
.when(
|
|
theme::has_adjusted_buffer_font_size(cx),
|
|
|stepper| {
|
|
stepper.on_reset(|_, cx| {
|
|
cx.dispatch_action(Box::new(
|
|
zed_actions::ResetBufferFontSize,
|
|
))
|
|
})
|
|
},
|
|
),
|
|
)
|
|
.into_any_element()
|
|
})
|
|
.custom_row(move |cx| {
|
|
h_flex()
|
|
.gap_2()
|
|
.w_full()
|
|
.justify_between()
|
|
.cursor(gpui::CursorStyle::Arrow)
|
|
.child(Label::new("UI Font Size"))
|
|
.child(
|
|
NumericStepper::new(
|
|
theme::get_ui_font_size(cx).to_string(),
|
|
|_, cx| {
|
|
cx.dispatch_action(Box::new(
|
|
zed_actions::DecreaseUiFontSize,
|
|
))
|
|
},
|
|
|_, cx| {
|
|
cx.dispatch_action(Box::new(
|
|
zed_actions::IncreaseUiFontSize,
|
|
))
|
|
},
|
|
)
|
|
.when(
|
|
theme::has_adjusted_ui_font_size(cx),
|
|
|stepper| {
|
|
stepper.on_reset(|_, cx| {
|
|
cx.dispatch_action(Box::new(
|
|
zed_actions::ResetUiFontSize,
|
|
))
|
|
})
|
|
},
|
|
),
|
|
)
|
|
.into_any_element()
|
|
})
|
|
.header("Project")
|
|
.action(
|
|
"Add Folder to Project...",
|
|
Box::new(workspace::AddFolderToProject),
|
|
)
|
|
.action("Open a new Project...", Box::new(workspace::Open))
|
|
.action(
|
|
"Open Recent Projects...",
|
|
Box::new(recent_projects::OpenRecent {
|
|
create_new_window: false,
|
|
}),
|
|
)
|
|
.header("Help")
|
|
.action("About Zed", Box::new(zed_actions::About))
|
|
.action("Welcome", Box::new(workspace::Welcome))
|
|
.link(
|
|
"Documentation",
|
|
Box::new(zed_actions::OpenBrowser {
|
|
url: "https://zed.dev/docs".into(),
|
|
}),
|
|
)
|
|
.action("Give Feedback", Box::new(feedback::GiveFeedback))
|
|
.action("Check for Updates", Box::new(auto_update::Check))
|
|
.action("View Telemetry", Box::new(zed_actions::OpenTelemetryLog))
|
|
.action(
|
|
"View Dependency Licenses",
|
|
Box::new(zed_actions::OpenLicenses),
|
|
)
|
|
.separator()
|
|
.action("Quit", Box::new(zed_actions::Quit))
|
|
})
|
|
.into()
|
|
})
|
|
.trigger(
|
|
IconButton::new("application-menu", ui::IconName::Menu)
|
|
.style(ButtonStyle::Subtle)
|
|
.tooltip(|cx| Tooltip::text("Open Application Menu", cx))
|
|
.icon_size(IconSize::Small),
|
|
)
|
|
.into_any_element()
|
|
}
|
|
}
|