settings_ui: Add theme settings controls (#15115)

This PR adds settings controls for the theme settings.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-07-24 16:25:52 -04:00 committed by GitHub
parent 325e6b9fef
commit 740c444089
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 392 additions and 156 deletions

View file

@ -42,8 +42,9 @@ impl Disableable for DropdownMenu {
impl RenderOnce for DropdownMenu {
fn render(self, _cx: &mut WindowContext) -> impl IntoElement {
PopoverMenu::new(self.id)
.full_width(self.full_width)
.menu(move |_cx| Some(self.menu.clone()))
.trigger(DropdownMenuTrigger::new(self.label))
.trigger(DropdownMenuTrigger::new(self.label).full_width(self.full_width))
}
}
@ -68,6 +69,11 @@ impl DropdownMenuTrigger {
on_click: None,
}
}
pub fn full_width(mut self, full_width: bool) -> Self {
self.full_width = full_width;
self
}
}
impl Disableable for DropdownMenuTrigger {

View file

@ -7,6 +7,8 @@ pub struct NumericStepper {
value: SharedString,
on_decrement: Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>,
on_increment: Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>,
/// Whether to reserve space for the reset button.
reserve_space_for_reset: bool,
on_reset: Option<Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
}
@ -20,10 +22,16 @@ impl NumericStepper {
value: value.into(),
on_decrement: Box::new(on_decrement),
on_increment: Box::new(on_increment),
reserve_space_for_reset: false,
on_reset: None,
}
}
pub fn reserve_space_for_reset(mut self, reserve_space_for_reset: bool) -> Self {
self.reserve_space_for_reset = reserve_space_for_reset;
self
}
pub fn on_reset(
mut self,
on_reset: impl Fn(&ClickEvent, &mut WindowContext) + 'static,
@ -48,13 +56,15 @@ impl RenderOnce for NumericStepper {
.icon_size(icon_size)
.on_click(on_reset),
)
} else {
} else if self.reserve_space_for_reset {
element.child(
h_flex()
.size(icon_size.square(cx))
.flex_none()
.into_any_element(),
)
} else {
element
}
})
.child(

View file

@ -1,10 +1,10 @@
use std::{cell::RefCell, rc::Rc};
use gpui::{
anchored, deferred, div, point, prelude::FluentBuilder, px, AnchorCorner, AnyElement, Bounds,
DismissEvent, DispatchPhase, Element, ElementId, GlobalElementId, HitboxId, InteractiveElement,
IntoElement, LayoutId, ManagedView, MouseDownEvent, ParentElement, Pixels, Point, View,
VisualContext, WindowContext,
anchored, deferred, div, point, prelude::FluentBuilder, px, size, AnchorCorner, AnyElement,
Bounds, DismissEvent, DispatchPhase, Element, ElementId, GlobalElementId, HitboxId,
InteractiveElement, IntoElement, LayoutId, Length, ManagedView, MouseDownEvent, ParentElement,
Pixels, Point, Style, View, VisualContext, WindowContext,
};
use crate::prelude::*;
@ -74,6 +74,7 @@ pub struct PopoverMenu<M: ManagedView> {
attach: Option<AnchorCorner>,
offset: Option<Point<Pixels>>,
trigger_handle: Option<PopoverMenuHandle<M>>,
full_width: bool,
}
impl<M: ManagedView> PopoverMenu<M> {
@ -87,9 +88,15 @@ impl<M: ManagedView> PopoverMenu<M> {
attach: None,
offset: None,
trigger_handle: None,
full_width: false,
}
}
pub fn full_width(mut self, full_width: bool) -> Self {
self.full_width = full_width;
self
}
pub fn menu(mut self, f: impl Fn(&mut WindowContext) -> Option<View<M>> + 'static) -> Self {
self.menu_builder = Some(Rc::new(f));
self
@ -258,10 +265,13 @@ impl<M: ManagedView> Element for PopoverMenu<M> {
.as_mut()
.map(|child_element| child_element.request_layout(cx));
let layout_id = cx.request_layout(
gpui::Style::default(),
menu_layout_id.into_iter().chain(child_layout_id),
);
let mut style = Style::default();
if self.full_width {
style.size = size(relative(1.).into(), Length::Auto);
}
let layout_id =
cx.request_layout(style, menu_layout_id.into_iter().chain(child_layout_id));
(
(