summaryrefslogtreecommitdiff
path: root/src/config/theme/view
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2024-08-02 21:34:41 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2024-08-02 21:34:41 +0200
commitbb9944d086332ed0b8d6064316225e901c456bd7 (patch)
treed8e42f8cee5db6236b775f10346ac5cd24c888a4 /src/config/theme/view
parent665eecff57a0a5f9ccb225d3781f6ecdc7637920 (diff)
change 'viewsheet' bindings to 'view'
Diffstat (limited to 'src/config/theme/view')
-rw-r--r--src/config/theme/view/bar.rs9
-rw-r--r--src/config/theme/view/mod.rs74
2 files changed, 83 insertions, 0 deletions
diff --git a/src/config/theme/view/bar.rs b/src/config/theme/view/bar.rs
new file mode 100644
index 0000000..7fab31a
--- /dev/null
+++ b/src/config/theme/view/bar.rs
@@ -0,0 +1,9 @@
+use super::super::bar::BarTheme;
+use crate::{config::GlobalConfig, state::view::mode::Mode};
+
+BarTheme!(
+ SheetViewBarTheme,
+ Mode,
+ GlobalConfig::instance().theme.view.bar,
+ GlobalConfig::instance_mut().theme.view.bar
+);
diff --git a/src/config/theme/view/mod.rs b/src/config/theme/view/mod.rs
new file mode 100644
index 0000000..e88e9ad
--- /dev/null
+++ b/src/config/theme/view/mod.rs
@@ -0,0 +1,74 @@
+use mlua::UserData;
+use ratatui::style::Color;
+
+use crate::{config::{GlobalConfig, DUMMY_CONFIG}, lua::evalsto::EvalTo, sheet::cell::CellRef};
+
+use self::bar::SheetViewBarTheme;
+
+use super::style::Style;
+
+pub mod bar;
+
+#[derive(Debug, Clone, Default)]
+pub struct SheetViewTheme {
+ pub cursor: EvalTo<Style, CellRef>,
+ pub selection: EvalTo<Style, CellRef>,
+ pub cell: EvalTo<Style, CellRef>,
+ pub background: EvalTo<Style, ()>,
+ pub bar: SheetViewBarTheme,
+}
+
+impl SheetViewTheme {
+ pub const fn new() -> Self {
+ Self {
+ cursor: EvalTo::Value(Style::new().fg(Color::Black).bg(Color::White)),
+ selection: EvalTo::Value(Style::new().fg(Color::White).bg(Color::DarkGray)),
+ cell: EvalTo::Value(Style::new().fg(Color::White).bg(Color::Black)),
+ background: EvalTo::Value(Style::new().bg(Color::Black)),
+ bar: SheetViewBarTheme::new(),
+ }
+ }
+}
+
+macro_rules! cfg {
+ () => {
+ GlobalConfig::instance().theme.view
+ };
+}
+
+macro_rules! cfg_mut {
+ () => {
+ GlobalConfig::instance_mut().theme.view
+ };
+}
+
+impl UserData for SheetViewTheme {
+ fn add_fields<'lua, F: mlua::prelude::LuaUserDataFields<'lua, Self>>(fields: &mut F) {
+ fields.add_field_function_get("cursor", |_, _| Ok(cfg!().cursor.clone()));
+
+ fields.add_field_function_set("cursor", |_, _, pair: EvalTo<Style, CellRef>| {
+ cfg_mut!().cursor = pair;
+ Ok(())
+ });
+
+ fields.add_field_function_get("selection", |_, _| Ok(cfg!().selection.clone()));
+ fields.add_field_function_set("selection", |_, _, pair: EvalTo<Style, CellRef>| {
+ cfg_mut!().selection = pair;
+ Ok(())
+ });
+
+ fields.add_field_function_get("cell", |_, _| Ok(cfg!().cell.clone()));
+ fields.add_field_function_set("cell", |_, _, cell: EvalTo<Style, CellRef>| {
+ cfg_mut!().cell = cell;
+ Ok(())
+ });
+
+ fields.add_field_function_get("background", |_, _| Ok(cfg!().background.clone()));
+ fields.add_field_function_set("background", |_, _, background: EvalTo<Style, ()>| {
+ cfg_mut!().background = background;
+ Ok(())
+ });
+
+ fields.add_field_function_get("bar", |_, _| Ok(DUMMY_CONFIG.theme.view.bar))
+ }
+}