Push language selector handler down into StatusBar

This commit is contained in:
Marshall Bowers
2023-10-11 12:11:22 -04:00
parent 382693a199
commit b6a9c58994
2 changed files with 21 additions and 22 deletions
+20 -5
View File
@@ -1,8 +1,9 @@
use std::marker::PhantomData; use std::marker::PhantomData;
use std::sync::atomic::Ordering; use std::sync::atomic::Ordering;
use std::sync::Arc;
use crate::prelude::*; use crate::prelude::*;
use crate::{get_workspace_state, Button, ClickHandler, Icon, IconButton, IconColor, ToolDivider}; use crate::{get_workspace_state, Button, Icon, IconButton, IconColor, ToolDivider};
#[derive(Default, PartialEq)] #[derive(Default, PartialEq)]
pub enum Tool { pub enum Tool {
@@ -35,17 +36,15 @@ pub struct StatusBar<S: 'static + Send + Sync + Clone> {
left_tools: Option<ToolGroup>, left_tools: Option<ToolGroup>,
right_tools: Option<ToolGroup>, right_tools: Option<ToolGroup>,
bottom_tools: Option<ToolGroup>, bottom_tools: Option<ToolGroup>,
on_select_language: ClickHandler<S>,
} }
impl<S: 'static + Send + Sync + Clone> StatusBar<S> { impl<S: 'static + Send + Sync + Clone> StatusBar<S> {
pub fn new(on_select_language: ClickHandler<S>) -> Self { pub fn new() -> Self {
Self { Self {
state_type: PhantomData, state_type: PhantomData,
left_tools: None, left_tools: None,
right_tools: None, right_tools: None,
bottom_tools: None, bottom_tools: None,
on_select_language,
} }
} }
@@ -148,7 +147,23 @@ impl<S: 'static + Send + Sync + Clone> StatusBar<S> {
.items_center() .items_center()
.gap_1() .gap_1()
.child(Button::new("116:25")) .child(Button::new("116:25"))
.child(Button::new("Rust").on_click(self.on_select_language.clone())), .child(Button::new("Rust").on_click(Arc::new(|_, cx| {
let is_showing_language_selector = workspace_state
.show_language_selector
.load(Ordering::SeqCst);
workspace_state
.show_language_selector
.compare_exchange(
is_showing_language_selector,
!is_showing_language_selector,
Ordering::SeqCst,
Ordering::SeqCst,
)
.unwrap();
cx.notify();
}))),
) )
.child(ToolDivider::new()) .child(ToolDivider::new())
.child( .child(
+1 -17
View File
@@ -218,23 +218,7 @@ impl<S: 'static + Send + Sync + Clone> WorkspaceElement<S> {
.filter(|_| workspace_state.show_chat_panel.load(Ordering::SeqCst)), .filter(|_| workspace_state.show_chat_panel.load(Ordering::SeqCst)),
), ),
) )
.child(StatusBar::new(Arc::new(move |_, cx| { .child(StatusBar::new())
let is_showing_language_selector = workspace_state
.show_language_selector
.load(Ordering::SeqCst);
workspace_state
.show_language_selector
.compare_exchange(
is_showing_language_selector,
!is_showing_language_selector,
Ordering::SeqCst,
Ordering::SeqCst,
)
.unwrap();
cx.notify();
})))
.children( .children(
Some( Some(
div() div()