egui: add integration
This commit is contained in:
parent
85b9b7222d
commit
008e8a671a
49 changed files with 4110 additions and 149 deletions
|
|
@ -19,6 +19,7 @@ mod connector_match;
|
|||
mod content_type;
|
||||
mod drm_device;
|
||||
mod drm_device_match;
|
||||
mod egui;
|
||||
mod env;
|
||||
pub mod exec;
|
||||
mod fallback_output_mode;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use {
|
||||
crate::{
|
||||
config::{
|
||||
Action, Config, Libei, Theme, UiDrag,
|
||||
Action, Config, Egui, Libei, Theme, UiDrag,
|
||||
context::Context,
|
||||
extractor::{Extractor, ExtractorError, arr, bol, int, opt, recover, str, val},
|
||||
parser::{DataType, ParseResult, Parser, UnexpectedDataType},
|
||||
|
|
@ -13,6 +13,7 @@ use {
|
|||
connector::ConnectorsParser,
|
||||
drm_device::DrmDevicesParser,
|
||||
drm_device_match::DrmDeviceMatchParser,
|
||||
egui::EguiParser,
|
||||
env::EnvParser,
|
||||
fallback_output_mode::FallbackOutputModeParser,
|
||||
float::FloatParser,
|
||||
|
|
@ -150,6 +151,7 @@ impl Parser for ConfigParser<'_> {
|
|||
simple_im_val,
|
||||
show_titles,
|
||||
fallback_output_mode_val,
|
||||
egui_val,
|
||||
),
|
||||
) = ext.extract((
|
||||
(
|
||||
|
|
@ -208,6 +210,7 @@ impl Parser for ConfigParser<'_> {
|
|||
opt(val("simple-im")),
|
||||
recover(opt(bol("show-titles"))),
|
||||
opt(val("fallback-output-mode")),
|
||||
opt(val("egui")),
|
||||
),
|
||||
))?;
|
||||
let mut keymap = None;
|
||||
|
|
@ -313,6 +316,15 @@ impl Parser for ConfigParser<'_> {
|
|||
}
|
||||
}
|
||||
}
|
||||
let mut egui = Egui::default();
|
||||
if let Some(value) = egui_val {
|
||||
match value.parse(&mut EguiParser(self.0)) {
|
||||
Ok(v) => egui = v,
|
||||
Err(e) => {
|
||||
log::warn!("Could not parse the egui settings: {}", self.0.error(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut gfx_api = None;
|
||||
if let Some(value) = gfx_api_val {
|
||||
match value.parse(&mut GfxApiParser) {
|
||||
|
|
@ -556,6 +568,7 @@ impl Parser for ConfigParser<'_> {
|
|||
auto_reload: auto_reload.despan(),
|
||||
log_level,
|
||||
theme,
|
||||
egui,
|
||||
gfx_api,
|
||||
drm_devices,
|
||||
direct_scanout_enabled: direct_scanout.despan(),
|
||||
|
|
|
|||
63
toml-config/src/config/parsers/egui.rs
Normal file
63
toml-config/src/config/parsers/egui.rs
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
use {
|
||||
crate::{
|
||||
config::{
|
||||
Egui,
|
||||
context::Context,
|
||||
extractor::{Extractor, ExtractorError, arr, opt},
|
||||
parser::{DataType, ParseResult, Parser, UnexpectedDataType},
|
||||
},
|
||||
toml::{
|
||||
toml_span::{Span, Spanned},
|
||||
toml_value::Value,
|
||||
},
|
||||
},
|
||||
indexmap::IndexMap,
|
||||
thiserror::Error,
|
||||
};
|
||||
|
||||
pub struct EguiParser<'a>(pub &'a Context<'a>);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum EguiParserError {
|
||||
#[error(transparent)]
|
||||
Expected(#[from] UnexpectedDataType),
|
||||
#[error(transparent)]
|
||||
Extractor(#[from] ExtractorError),
|
||||
}
|
||||
|
||||
impl Parser for EguiParser<'_> {
|
||||
type Value = Egui;
|
||||
type Error = EguiParserError;
|
||||
const EXPECTED: &'static [DataType] = &[DataType::Table];
|
||||
|
||||
fn parse_table(
|
||||
&mut self,
|
||||
span: Span,
|
||||
table: &IndexMap<Spanned<String>, Spanned<Value>>,
|
||||
) -> ParseResult<Self> {
|
||||
let mut ext = Extractor::new(self.0, span, table);
|
||||
let (proportional_fonts_arr, monospace_fonts_arr) =
|
||||
ext.extract((opt(arr("proportional-fonts")), opt(arr("monospace-fonts"))))?;
|
||||
let mut proportional_fonts = None;
|
||||
let mut monospace_fonts = None;
|
||||
for (out, f) in [
|
||||
(&mut proportional_fonts, proportional_fonts_arr),
|
||||
(&mut monospace_fonts, monospace_fonts_arr),
|
||||
] {
|
||||
if let Some(f) = f {
|
||||
let fonts = out.insert(vec![]);
|
||||
for f in f.value {
|
||||
let Value::String(s) = &f.value else {
|
||||
log::error!("Expected a string: {}", self.0.error3(f.span));
|
||||
continue;
|
||||
};
|
||||
fonts.push(s.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(Egui {
|
||||
proportional_fonts,
|
||||
monospace_fonts,
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue