use crate::cmm::cmm_eotf::Eotf;
use crate::control_center::ControlCenterInner;
use crate::control_center::bool;
use crate::control_center::bool_ui;
use crate::control_center::combo_box;
use crate::control_center::drag_value;
use crate::control_center::grid;
use crate::control_center::grid_label_ui;
use crate::control_center::row;
use crate::control_center::text_edit;
use crate::control_center::tip;
use crate::gfx_api::AlphaMode;
use crate::state::State;
use crate::theme::Color;
use crate::theme::ThemeColored;
use crate::theme::ThemeSized;
use crate::utils::static_text::StaticText;
use egui::Ui;
use isnt::std_1::primitive::IsntStrExt;
use linearize::LinearizeExt;
use std::rc::Rc;
pub struct LookAndFeelPane {
state: Rc<State>,
}
impl ControlCenterInner {
pub fn create_look_and_feel_pane(self: &Rc<Self>) -> LookAndFeelPane {
LookAndFeelPane {
state: self.state.clone(),
}
}
}
impl LookAndFeelPane {
pub fn title(&self, res: &mut String) {
res.push_str("Look and Feel");
}
pub fn show(&mut self, ui: &mut Ui) {
let t = &self.state.theme;
grid(ui, "settings", |ui| {
bool(ui, "Show Bar", self.state.show_bar.get(), |v| {
self.state.set_show_bar(v);
});
combo_box(ui, "Bar Position", t.bar_position.get(), |p| {
self.state.set_bar_position(p);
});
bool(ui, "Show Titles", t.show_titles.get(), |v| {
self.state.set_show_titles(v);
});
bool(ui, "Show Window Icons", t.show_window_icons.get(), |v| {
self.state.set_show_window_icons(v);
});
bool_ui(
ui,
"Window Icons Grayscale",
|ui| {
tip(ui, |ui| {
ui.label("Only supported by the Vulkan renderer.");
});
},
t.window_icons_grayscale.get(),
|v| self.state.set_window_icons_grayscale(v),
);
bool_ui(
ui,
"Primary Selection",
|ui| {
tip(ui, |ui| {
ui.label("Requires applications to be restarted.");
});
},
self.state.enable_primary_selection.get(),
|v| self.state.set_primary_selection_enabled(v),
);
bool_ui(
ui,
"UI Drag",
|ui| {
tip(ui, |ui| {
ui.label("Allows dragging workspaces and tiled windows with the mouse.");
});
},
self.state.ui_drag_enabled.get(),
|v| self.state.set_ui_drag_enabled(v),
);
drag_value(
ui,
"UI Drag Threshold (px)",
self.state.ui_drag_threshold_squared.get().isqrt(),
1..=i32::MAX,
1.0,
|v| {
self.state.set_ui_drag_threshold(v);
},
);
bool_ui(
ui,
"Float Pin Icon",
|ui| {
tip(ui, |ui| {
ui.label("Show the pin icon even if the window is not pinned.");
ui.label("Pinned floating windows are shown on all workspaces.");
});
},
self.state.show_pin_icon.get(),
|v| self.state.set_show_pin_icon(v),
);
bool_ui(
ui,
"Float Above Fullscreen",
|ui| {
tip(ui, |ui| {
ui.label("Show floating windows above fullscreen windows.");
});
},
self.state.float_above_fullscreen.get(),
|v| self.state.set_float_above_fullscreen(v),
);
bool_ui(
ui,
"Split Reuses Container",
|ui| {
tip(ui, |ui| {
ui.label(concat!(
"Splitting the only window in a container changes the split ",
"direction of that container.",
));
ui.label("Otherwise the window is wrapped in a new container.");
});
},
self.state.split_reuses_container.get(),
|v| self.state.set_split_reuses_container(v),
);
row(ui, "Font", |ui| {
let mut v = self.state.theme.font.get().to_string();
if text_edit(ui, &mut v).changed() {
self.state.set_font(&v);
}
});
row(ui, "Title Font", |ui| {
let mut v = t
.title_font
.get()
.map(|v| v.to_string())
.unwrap_or_default();
if text_edit(ui, &mut v).changed() {
self.state.set_title_font(v.is_not_empty().then_some(&v));
}
});
row(ui, "Bar Font", |ui| {
let mut v = t.bar_font.get().map(|v| v.to_string()).unwrap_or_default();
if text_edit(ui, &mut v).changed() {
self.state.set_bar_font(v.is_not_empty().then_some(&v));
}
});
combo_box(ui, "Container Borders", t.container_borders.get(), |p| {
self.state.set_container_borders(p);
});
});
if ui.button("Reset Sizes").clicked() {
self.state.reset_sizes();
}
if ui.button("Reset Colors").clicked() {
self.state.reset_colors();
}
if ui.button("Reset Fonts").clicked() {
self.state.reset_fonts();
}
ui.collapsing("Sizes", |ui| {
grid(ui, "Sizes", |ui| {
for v in ThemeSized::variants() {
let f = v.field(&self.state.theme);
drag_value(ui, v.text(), f.get(), v.min()..=v.max(), 1.0, |i| {
self.state.set_size(v, i);
});
}
});
});
ui.collapsing("Colors", |ui| {
grid(ui, "Colors", |ui| {
for tc in ThemeColored::variants() {
let f = tc.field(t);
let mut v = f.get().to_array(Eotf::Linear);
grid_label_ui(ui, |ui| {
ui.label(tc.text());
if tc == ThemeColored::focused_border {
tip(ui, |ui| {
ui.label("Requires `Full` border style for containers.");
});
}
});
let changed = ui.color_edit_button_rgba_premultiplied(&mut v).changed();
ui.end_row();
if changed {
let [r, g, b, a] = v;
let c =
Color::new(Eotf::Linear, AlphaMode::PremultipliedOptical, r, g, b, a);
self.state.set_color(tc, c);
}
}
});
});
}
}