bar dropdown backend logic

This commit is contained in:
galister
2026-01-05 20:36:44 +09:00
parent b56aa1a8de
commit ac9bfc9fc4
18 changed files with 476 additions and 185 deletions

View File

@@ -3,7 +3,7 @@ use std::ffi::OsStr;
use std::io::Read;
use std::path::{Component, Path, PathBuf};
#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy)]
pub enum AssetPath<'a> {
WguiInternal(&'a str), // tied to internal wgui AssetProvider. Used internally
BuiltIn(&'a str), // tied to user AssetProvider
@@ -12,7 +12,7 @@ pub enum AssetPath<'a> {
}
// see AssetPath above for documentation
#[derive(Clone)]
#[derive(Debug, Clone)]
pub enum AssetPathOwned {
WguiInternal(PathBuf),
BuiltIn(PathBuf),

View File

@@ -1,27 +1,17 @@
use std::fmt::Debug;
pub trait LogErr {
fn log_err(self) -> Self;
fn log_err_with(self, additional: &str) -> Self;
fn log_warn(self) -> Self;
fn log_warn_with(self, additional: &str) -> Self;
fn log_err(self, additional: &str) -> Self;
fn log_err_with<D: Debug>(self, additional: &D) -> Self;
fn log_warn(self, additional: &str) -> Self;
fn log_warn_with<D: Debug>(self, additional: &D) -> Self;
}
impl<T, E> LogErr for Result<T, E>
where
E: Debug + Send + Sync + 'static,
{
fn log_warn(self) -> Result<T, E> {
match self {
Ok(ok) => Ok(ok),
Err(error) => {
log::warn!("{error:?}");
Err(error)
}
}
}
fn log_warn_with(self, additional: &str) -> Result<T, E> {
fn log_warn(self, additional: &str) -> Result<T, E> {
match self {
Ok(ok) => Ok(ok),
Err(error) => {
@@ -31,17 +21,17 @@ where
}
}
fn log_err(self) -> Result<T, E> {
fn log_warn_with<D: Debug>(self, additional: &D) -> Result<T, E> {
match self {
Ok(ok) => Ok(ok),
Err(error) => {
log::error!("{error:?}");
log::warn!("{additional:?}: {error:?}");
Err(error)
}
}
}
fn log_err_with(self, additional: &str) -> Result<T, E> {
fn log_err(self, additional: &str) -> Result<T, E> {
match self {
Ok(ok) => Ok(ok),
Err(error) => {
@@ -50,4 +40,14 @@ where
}
}
}
fn log_err_with<D: Debug>(self, additional: &D) -> Self {
match self {
Ok(ok) => Ok(ok),
Err(error) => {
log::error!("{additional:?}: {error:?}");
Err(error)
}
}
}
}

View File

@@ -10,16 +10,11 @@ mod widget_rectangle;
mod widget_sprite;
use crate::{
assets::{normalize_path, AssetPath, AssetPathOwned},
components::{Component, ComponentWeak},
drawing::{self},
globals::WguiGlobals,
layout::{Layout, LayoutParams, LayoutState, Widget, WidgetID, WidgetMap, WidgetPair},
parser::{
assets::{normalize_path, AssetPath, AssetPathOwned}, components::{Component, ComponentWeak}, drawing::{self}, globals::WguiGlobals, layout::{Layout, LayoutParams, LayoutState, Widget, WidgetID, WidgetMap, WidgetPair}, log::LogErr, parser::{
component_button::parse_component_button, component_checkbox::{parse_component_checkbox, CheckboxKind}, component_radio_group::parse_component_radio_group, component_slider::parse_component_slider, widget_div::parse_widget_div, widget_image::parse_widget_image, widget_label::parse_widget_label, widget_rectangle::parse_widget_rectangle, widget_sprite::parse_widget_sprite
},
widget::ConstructEssentials,
}, widget::ConstructEssentials
};
use anyhow::Context;
use ouroboros::self_referencing;
use smallvec::SmallVec;
use std::{cell::RefMut, collections::HashMap, path::Path, rc::Rc};
@@ -1109,7 +1104,7 @@ fn get_doc_from_asset_path(
allow_dtd: true,
..Default::default()
};
roxmltree::Document::parse_with_options(xml, opt).unwrap()
roxmltree::Document::parse_with_options(xml, opt).context("Unable to parse XML").log_err_with(&asset_path).unwrap()
}));
let root = document.borrow_doc().root();