Split out Interactive<T> into Toggle<T> and Interactive<T>

This commit is contained in:
Piotr Osiewicz
2023-06-20 16:05:20 -07:00
committed by Mikayla Maki
parent 6ed86781b2
commit e92015b12f
35 changed files with 223 additions and 144 deletions
+9 -2
View File
@@ -6,7 +6,7 @@ use gpui::{
};
use serde::Deserialize;
use std::rc::Rc;
use theme::ThemeSettings;
use theme::{ThemeSettings, ToggleState};
pub trait Panel: View {
fn position(&self, cx: &WindowContext) -> DockPosition;
@@ -498,7 +498,14 @@ impl View for PanelButtons {
Stack::new()
.with_child(
MouseEventHandler::<Self, _>::new(panel_ix, cx, |state, cx| {
let style = button_style.style_for(state, is_active);
let toggle_state = if is_active {
ToggleState::On
} else {
ToggleState::Off
};
let style = button_style.in_state(toggle_state);
let style = style.style_for(state);
Flex::row()
.with_child(
Svg::new(view.icon_path(cx))
+2 -2
View File
@@ -291,7 +291,7 @@ pub mod simple_message_notification {
)
.with_child(
MouseEventHandler::<Cancel, _>::new(0, cx, |state, _| {
let style = theme.dismiss_button.style_for(state, false);
let style = theme.dismiss_button.style_for(state);
Svg::new("icons/x_mark_8.svg")
.with_color(style.color)
.constrained()
@@ -323,7 +323,7 @@ pub mod simple_message_notification {
0,
cx,
|state, _| {
let style = theme.action_message.style_for(state, false);
let style = theme.action_message.style_for(state);
Flex::row()
.with_child(
+2 -2
View File
@@ -1410,7 +1410,7 @@ impl Pane {
pub fn render_tab_bar_button<F: 'static + Fn(&mut Pane, &mut EventContext<Pane>)>(
index: usize,
icon: &'static str,
active: bool,
is_active: bool,
tooltip: Option<(String, Option<Box<dyn Action>>)>,
cx: &mut ViewContext<Pane>,
on_click: F,
@@ -1420,7 +1420,7 @@ impl Pane {
let mut button = MouseEventHandler::<TabBarButton, _>::new(index, cx, |mouse_state, cx| {
let theme = &settings::get::<ThemeSettings>(cx).theme.workspace.tab_bar;
let style = theme.pane_button.style_for(mouse_state, active);
let style = theme.pane_button.in_state(is_active).style_for(mouse_state);
Svg::new(icon)
.with_color(style.color)
.constrained()
+3 -3
View File
@@ -219,7 +219,7 @@ impl View for Toolbar {
#[allow(clippy::too_many_arguments)]
fn nav_button<A: Action, F: 'static + Fn(&mut Toolbar, &mut ViewContext<Toolbar>)>(
svg_path: &'static str,
style: theme::Interactive<theme::IconButton>,
style: theme::Toggleable<theme::Interactive<theme::IconButton>>,
nav_button_height: f32,
tooltip_style: TooltipStyle,
enabled: bool,
@@ -231,9 +231,9 @@ fn nav_button<A: Action, F: 'static + Fn(&mut Toolbar, &mut ViewContext<Toolbar>
) -> AnyElement<Toolbar> {
MouseEventHandler::<A, _>::new(0, cx, |state, _| {
let style = if enabled {
style.style_for(state, false)
style.off_state().style_for(state)
} else {
style.disabled_style()
style.off_state().disabled_style()
};
Svg::new(svg_path)
.with_color(style.color)