platform_linux.rs

 1use gpui::{Action, MouseButton, prelude::*};
 2
 3use ui::prelude::*;
 4
 5use crate::window_controls::{WindowControl, WindowControlType};
 6
 7#[derive(IntoElement)]
 8pub struct LinuxWindowControls {
 9    close_window_action: Box<dyn Action>,
10}
11
12impl LinuxWindowControls {
13    pub fn new(close_window_action: Box<dyn Action>) -> Self {
14        Self {
15            close_window_action,
16        }
17    }
18}
19
20impl RenderOnce for LinuxWindowControls {
21    fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
22        h_flex()
23            .id("generic-window-controls")
24            .px_3()
25            .gap_3()
26            .on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
27            .child(WindowControl::new(
28                "minimize",
29                WindowControlType::Minimize,
30                cx,
31            ))
32            .child(WindowControl::new(
33                "maximize-or-restore",
34                if window.is_maximized() {
35                    WindowControlType::Restore
36                } else {
37                    WindowControlType::Maximize
38                },
39                cx,
40            ))
41            .child(WindowControl::new_close(
42                "close",
43                WindowControlType::Close,
44                self.close_window_action,
45                cx,
46            ))
47    }
48}