integrated-title-bar: Add button style option

This commit is contained in:
YuraIz authored and Wez Furlong committed 2023-03-31 19:45:28 -07:00
1 parent d39bccca10
commit 6c40c2397e
3 files changed
+138 -81

No files matched your search

+1
View File
@@ -245,6 +245,7 @@ impl TabBarState {
is_left,
remove_hide_button,
remove_maximize_button,
..
} = config.fancy_window_decorations;
let button_order = if is_left {
+58 -80
View File
@@ -304,67 +304,59 @@ fn window_button_element(
font: &Rc<LoadedFont>,
metrics: &RenderMetrics,
colors: &TabBarColors,
style: window::FancyWindowDecorationsStyle,
) -> Element {
let poly = if cfg!(windows) {
use window_buttons::windows::{CLOSE, HIDE, MAXIMIZE, RESTORE};
match window_button {
TabBarItem::WindowHideButton => HIDE,
TabBarItem::WindowMaximizeButton => {
if is_maximized {
RESTORE
} else {
MAXIMIZE
use window::FancyWindowDecorationsStyle as Style;
let poly = match style {
Style::Windows => {
use window_buttons::windows::{CLOSE, HIDE, MAXIMIZE, RESTORE};
match window_button {
TabBarItem::WindowHideButton => HIDE,
TabBarItem::WindowMaximizeButton => {
if is_maximized {
RESTORE
} else {
MAXIMIZE
}
}
TabBarItem::WindowCloseButton => CLOSE,
_ => unreachable!(),
}
TabBarItem::WindowCloseButton => CLOSE,
_ => unreachable!(),
}
} else if cfg!(target_os = "linux") {
use window_buttons::gnome::{CLOSE, HIDE, MAXIMIZE, RESTORE};
match window_button {
TabBarItem::WindowHideButton => HIDE,
TabBarItem::WindowMaximizeButton => {
if is_maximized {
RESTORE
} else {
MAXIMIZE
Style::Gnome => {
use window_buttons::gnome::{CLOSE, HIDE, MAXIMIZE, RESTORE};
match window_button {
TabBarItem::WindowHideButton => HIDE,
TabBarItem::WindowMaximizeButton => {
if is_maximized {
RESTORE
} else {
MAXIMIZE
}
}
TabBarItem::WindowCloseButton => CLOSE,
_ => unreachable!(),
}
TabBarItem::WindowCloseButton => CLOSE,
_ => unreachable!(),
}
} else {
match window_button {
Style::MacOs => match window_button {
TabBarItem::WindowHideButton => HIDE_BUTTON,
TabBarItem::WindowMaximizeButton => MAXIMIZE_BUTTON,
TabBarItem::WindowCloseButton => X_BUTTON,
_ => unreachable!(),
}
},
};
let poly = if cfg!(windows) {
window_buttons::windows::sized_poly(poly)
} else if cfg!(target_os = "linux") {
window_buttons::gnome::sized_poly(poly)
} else if cfg!(macos) {
SizedPoly {
let poly = match style {
Style::Windows => window_buttons::windows::sized_poly(poly),
Style::Gnome => window_buttons::gnome::sized_poly(poly),
Style::MacOs => SizedPoly {
poly: &[],
width: Dimension::Pixels(13.),
height: Dimension::Pixels(13.),
}
} else {
SizedPoly {
poly,
width: Dimension::Pixels(metrics.cell_size.height as f32 / 2.),
height: Dimension::Pixels(metrics.cell_size.height as f32 / 2.),
}
},
};
match window_button {
TabBarItem::WindowHideButton => log::debug!("BTN"),
_ => {}
}
let element = Element::new(
&font,
ElementContent::Poly {
@@ -373,24 +365,25 @@ fn window_button_element(
},
);
let element = if cfg!(windows) {
let left_padding = match window_button {
TabBarItem::WindowHideButton => 17.0,
_ => 18.0,
};
let scale = 72.0 / 96.0;
let element = match style {
Style::Windows => {
let left_padding = match window_button {
TabBarItem::WindowHideButton => 17.0,
_ => 18.0,
};
let scale = 72.0 / 96.0;
element
.zindex(1)
.vertical_align(VerticalAlign::Middle)
.padding(BoxDimension {
left: Dimension::Points(left_padding * scale),
right: Dimension::Points(18. * scale),
top: Dimension::Points(10. * scale),
bottom: Dimension::Points(10. * scale),
})
} else if cfg!(target_os = "linux") {
element
element
.zindex(1)
.vertical_align(VerticalAlign::Middle)
.padding(BoxDimension {
left: Dimension::Points(left_padding * scale),
right: Dimension::Points(18. * scale),
top: Dimension::Points(10. * scale),
bottom: Dimension::Points(10. * scale),
})
}
Style::Gnome => element
.zindex(1)
.vertical_align(VerticalAlign::Middle)
.padding(BoxDimension {
@@ -427,9 +420,9 @@ fn window_button_element(
right: Dimension::Pixels(7.),
top: Dimension::Pixels(7.),
bottom: Dimension::Pixels(7.),
})
} else if cfg!(macos) {
element
}),
Style::MacOs => element
.zindex(1)
.vertical_align(VerticalAlign::Middle)
.padding(BoxDimension {
@@ -466,23 +459,7 @@ fn window_button_element(
right: Dimension::Cells(0.5),
top: Dimension::Cells(0.5),
bottom: Dimension::Cells(0.5),
})
} else {
element
.zindex(1)
.vertical_align(VerticalAlign::Middle)
.margin(BoxDimension {
left: Dimension::Cells(0.),
right: Dimension::Cells(0.),
top: Dimension::Cells(0.),
bottom: Dimension::Cells(0.),
})
.padding(BoxDimension {
left: Dimension::Cells(1.0),
right: Dimension::Cells(1.0),
top: Dimension::Cells(0.6),
bottom: Dimension::Cells(0.6),
})
}),
};
let (color, hover_colors) = match window_button {
@@ -1180,6 +1157,7 @@ impl super::TermWindow {
&font,
&metrics,
&colors,
self.config.fancy_window_decorations.style,
),
}
};
+79 -1
View File
@@ -1451,7 +1451,7 @@ impl Default for WindowDecorations {
}
}
#[derive(Debug, Default, FromDynamic, ToDynamic, Clone)]
#[derive(Debug, FromDynamic, ToDynamic, Clone)]
pub struct FancyWindowDecorations {
#[dynamic(default)]
pub is_left: bool,
@@ -1459,6 +1459,84 @@ pub struct FancyWindowDecorations {
pub remove_hide_button: bool,
#[dynamic(default)]
pub remove_maximize_button: bool,
#[dynamic(default)]
pub style: FancyWindowDecorationsStyle,
}
#[cfg(not(target_os = "macos"))]
impl Default for FancyWindowDecorations {
fn default() -> Self {
FancyWindowDecorations {
is_left: false,
remove_hide_button: false,
remove_maximize_button: false,
style: Default::default(),
}
}
}
#[cfg(target_os = "macos")]
impl Default for FancyWindowDecorations {
fn default() -> Self {
FancyWindowDecorations {
is_left: true,
remove_hide_button: false,
remove_maximize_button: false,
style: Default::default(),
}
}
}
#[derive(Debug, Deserialize, Serialize, FromDynamic, ToDynamic, Clone, Copy)]
#[dynamic(try_from = "String")]
pub enum FancyWindowDecorationsStyle {
Windows,
MacOs,
Gnome,
}
#[cfg(any(windows, target_os = "freebsd"))]
impl Default for FancyWindowDecorationsStyle {
fn default() -> Self {
Self::Windows
}
}
#[cfg(target_os = "linux")]
impl Default for FancyWindowDecorationsStyle {
fn default() -> Self {
Self::Gnome
}
}
#[cfg(target_os = "macos")]
impl Default for FancyWindowDecorationsStyle {
fn default() -> Self {
Self::MacOs
}
}
impl Into<String> for FancyWindowDecorationsStyle {
fn into(self) -> String {
match self {
Self::Windows => "windows",
Self::MacOs => "macos",
Self::Gnome => "gnome",
}
.to_string()
}
}
impl TryFrom<String> for FancyWindowDecorationsStyle {
type Error = String;
fn try_from(value: String) -> Result<Self, Self::Error> {
match value.to_lowercase().as_str() {
"windows" => Ok(Self::Windows),
"macos" => Ok(Self::MacOs),
"gnome" => Ok(Self::Gnome),
_ => Err(format!("invalid fancy_window_decoratins.style {}", value)),
}
}
}
/// Map c to its Ctrl equivalent.