1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
mod extended;
mod standard;
mod types;
pub use extended::ExtendedFab;
pub use standard::{Fab, FloatingAction};
pub use types::{FabAlignment, FabColor, FabSize, FabVisibilityAnimation};
macro_rules! fab_builders {
() => {
/// Sets the Expressive FAB size tier. Defaults to [`super::FabSize::Small`].
pub fn size(mut self, size: super::FabSize) -> Self {
self.content.size = size;
self
}
/// Sets the FAB color palette preset. Defaults to [`super::FabColor::Primary`].
pub fn color(mut self, color: super::FabColor) -> Self {
self.content.color = color;
self
}
/// Desktop compatibility extension. Material recommends hiding a FAB
/// when its primary action is unavailable instead of disabling it.
pub fn disabled(mut self, disabled: bool) -> Self {
self.content.disabled = disabled;
self
}
/// Uses a caller-owned focus handle for keyboard traversal and focus state.
pub fn track_focus(mut self, focus: &gpui::FocusHandle) -> Self {
self.content.focus = Some(focus.clone());
self
}
/// Invoked once when the FAB is activated via pointer, keyboard, or assistive technology.
pub fn on_activate(
mut self,
handler: impl Fn(&mut gpui::Window, &mut gpui::App) + 'static,
) -> Self {
self.content.on_activate = Some(std::rc::Rc::new(handler));
self
}
/// Overrides the container shape for all interaction states.
pub fn shape(mut self, shape: gpui_material_theme::CornerShape) -> Self {
self.appearance.style.shapes.resting = Some(shape);
self.appearance.style.shapes.pressed = Some(shape);
self
}
/// Sets the enabled and disabled container and content colors.
pub fn colors(mut self, colors: crate::control_style::ButtonColors) -> Self {
self.appearance.style.colors = colors;
self
}
/// Overrides the elevation for each interaction state.
pub fn elevations(mut self, elevations: crate::control_style::ControlElevations) -> Self {
self.appearance.style.elevations = elevations;
self
}
/// Reports interaction state through a caller-owned source.
pub fn interaction_source(
mut self,
source: &gpui::Entity<gpui_material_foundation::InteractionSource>,
) -> Self {
self.appearance.interaction_source = Some(source.clone());
self
}
/// Applies the caller's visibility state. Use a stable ID across updates.
pub fn visible(mut self, visible: bool) -> Self {
self.appearance.visible = Some(visible);
self
}
/// Sets the pivot, hidden scale, and independent scale and alpha motions.
pub fn visibility_animation(mut self, animation: super::FabVisibilityAnimation) -> Self {
self.appearance.animation = animation;
self
}
};
}
pub(super) use fab_builders;