Skip to content

Commit

Permalink
refactor: Move element bound render toggle to config
Browse files Browse the repository at this point in the history
  • Loading branch information
CosmicHorrorDev committed Apr 13, 2024
1 parent 7793f97 commit 97692a4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ keywords = ["markdown", "viewer", "gpu"]
default = ["wayland", "x11"]
x11 = ["copypasta/x11", "winit/x11"]
wayland = ["copypasta/wayland", "winit/wayland"]
debug = []

[dependencies]
winit = { version = "0.28.7", default-features = false }
Expand Down
3 changes: 2 additions & 1 deletion src/opts/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ pub enum MetricsExporter {
}

#[derive(Deserialize, Clone, Debug, Default, PartialEq)]
#[serde(default)]
#[serde(default, rename_all = "kebab-case")]
pub struct DebugSection {
pub metrics: Option<MetricsExporter>,
pub render_element_bounds: bool,
}

#[derive(Deserialize, Clone, Debug, PartialEq)]
Expand Down
23 changes: 21 additions & 2 deletions src/opts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ mod config;
#[cfg(test)]
mod tests;

use std::path::Path;
use std::{
path::Path,
sync::atomic::{AtomicBool, Ordering},
};

use crate::color;
pub use cli::{Cli, Commands, ConfigCmd, Position, Size, ThemeType, View};
Expand All @@ -15,6 +18,17 @@ use clap::Parser;
use serde::Deserialize;
use smart_debug::SmartDebug;

static RENDER_ELEMENT_BOUNDS: AtomicBool = AtomicBool::new(false);

#[must_use]
pub fn get_render_element_bounds() -> bool {
RENDER_ELEMENT_BOUNDS.load(Ordering::SeqCst)
}

pub fn set_render_element_bounds(b: bool) {
RENDER_ELEMENT_BOUNDS.store(b, Ordering::SeqCst);
}

#[derive(Deserialize, Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum ResolvedTheme {
Dark,
Expand Down Expand Up @@ -108,7 +122,12 @@ impl Opts {
position: v_position,
} = args;

let DebugSection { metrics } = debug;
let DebugSection {
metrics,
render_element_bounds,
} = debug;

set_render_element_bounds(render_element_bounds);

let resolved_theme = args_theme
.or(config_theme)
Expand Down
4 changes: 2 additions & 2 deletions src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,8 @@ impl Renderer {
}
}
}
#[cfg(feature = "debug")]
{

if crate::opts::get_render_element_bounds() {
let mut rect = element
.bounds
.as_ref()
Expand Down

0 comments on commit 97692a4

Please sign in to comment.