Add context to builder

This commit is contained in:
hodasemi 2024-04-07 15:39:32 +02:00
parent 9e28804a38
commit edf81556d9
3 changed files with 92 additions and 30 deletions

View file

@ -1,5 +1,5 @@
use crate::prelude::*;
use anyhow::{bail, Result};
use anyhow::{bail, Context, Result};
use assetpath::AssetPath;
@ -27,9 +27,12 @@ impl GuiBuilder {
#[cfg(feature = "audio")]
gui_handler,
path,
)?;
)
.with_context(|| format!("validator for {}", path.full_path()))?;
Ok(Arc::new(Self::_new(gui_handler, validator)?))
Ok(Arc::new(Self::_new(gui_handler, validator).with_context(
|| format!("for file {}", path.full_path()),
)?))
}
pub fn from_str(gui_handler: &Arc<GuiHandler>, s: &str) -> Result<Arc<Self>> {
@ -62,7 +65,8 @@ impl GuiBuilder {
path,
)?;
let builder = Self::_new(gui_handler, validator)?;
let builder = Self::_new(gui_handler, validator)
.with_context(|| format!("for file {}", path.full_path()))?;
me.grids.extend(builder.grids);
@ -351,12 +355,30 @@ impl GuiBuilder {
}
root_grid.set_frame(
root_grid_info.x_offset.get()?,
root_grid_info.y_offset.get()?,
root_grid_info.width.get()?,
root_grid_info.height.get()?,
root_grid_info.vertical_alignment.get()?,
root_grid_info.horizontal_alignment.get()?,
root_grid_info
.x_offset
.get()
.with_context(|| "x_offset of root grid")?,
root_grid_info
.y_offset
.get()
.with_context(|| "y_offset of root grid")?,
root_grid_info
.width
.get()
.with_context(|| "width of root grid")?,
root_grid_info
.height
.get()
.with_context(|| "height of root grid")?,
root_grid_info
.vertical_alignment
.get()
.with_context(|| "vertical alignment of root grid")?,
root_grid_info
.horizontal_alignment
.get()
.with_context(|| "horizontal alignment of root grid")?,
)?;
Self::insert_id(ids, &root_grid_info.id, &root_grid)?;
@ -391,8 +413,14 @@ impl GuiBuilder {
grid.attach(
button.clone(),
button_info.x_slot.get()?,
button_info.y_slot.get()?,
button_info
.x_slot
.get()
.with_context(|| "x_slot of button")?,
button_info
.y_slot
.get()
.with_context(|| "y_slot of button")?,
button_info.x_dim,
button_info.y_dim,
)?;
@ -417,8 +445,8 @@ impl GuiBuilder {
grid.attach(
label,
label_info.x_slot.get()?,
label_info.y_slot.get()?,
label_info.x_slot.get().with_context(|| "x_slot of label")?,
label_info.y_slot.get().with_context(|| "y_slot of label")?,
label_info.x_dim,
label_info.y_dim,
)?;
@ -431,8 +459,14 @@ impl GuiBuilder {
grid.attach(
multi_line_label,
multi_line_label_info.x_slot.get()?,
multi_line_label_info.y_slot.get()?,
multi_line_label_info
.x_slot
.get()
.with_context(|| "x_slot of label")?,
multi_line_label_info
.y_slot
.get()
.with_context(|| "y_slot of label")?,
multi_line_label_info.x_dim,
multi_line_label_info.y_dim,
)?;
@ -445,8 +479,14 @@ impl GuiBuilder {
grid.attach(
multi_line_text_field,
multi_line_text_field_info.x_slot.get()?,
multi_line_text_field_info.y_slot.get()?,
multi_line_text_field_info
.x_slot
.get()
.with_context(|| "x_slot of text field")?,
multi_line_text_field_info
.y_slot
.get()
.with_context(|| "y_slot of text field")?,
multi_line_text_field_info.x_dim,
multi_line_text_field_info.y_dim,
)?;
@ -458,8 +498,14 @@ impl GuiBuilder {
grid.attach(
text_field,
text_field_info.x_slot.get()?,
text_field_info.y_slot.get()?,
text_field_info
.x_slot
.get()
.with_context(|| "x_slot of text field")?,
text_field_info
.y_slot
.get()
.with_context(|| "y_slot of text field")?,
text_field_info.x_dim,
text_field_info.y_dim,
)?;
@ -471,8 +517,8 @@ impl GuiBuilder {
grid.attach(
icon,
icon_info.x_slot.get()?,
icon_info.y_slot.get()?,
icon_info.x_slot.get().with_context(|| "x_slot of icon")?,
icon_info.y_slot.get().with_context(|| "y_slot of icon")?,
icon_info.x_dim,
icon_info.y_dim,
)?;
@ -484,8 +530,14 @@ impl GuiBuilder {
grid.attach(
progress_bar,
progress_bar_info.x_slot.get()?,
progress_bar_info.y_slot.get()?,
progress_bar_info
.x_slot
.get()
.with_context(|| "x_slot of progress bar")?,
progress_bar_info
.y_slot
.get()
.with_context(|| "y_slot of progress bar")?,
progress_bar_info.x_dim,
progress_bar_info.y_dim,
)?;
@ -497,8 +549,8 @@ impl GuiBuilder {
grid.attach(
sub_grid.clone(),
grid_info.x_slot.get()?,
grid_info.y_slot.get()?,
grid_info.x_slot.get().with_context(|| "x_slot of grid")?,
grid_info.y_slot.get().with_context(|| "y_slot of grid")?,
grid_info.x_dim,
grid_info.y_dim,
)?;

View file

@ -5,7 +5,7 @@ use std::sync::{
Arc, Mutex,
};
use anyhow::Result;
use anyhow::{Context, Result};
use utilities::prelude::*;
pub struct MultiLineLabelBuilder {
@ -184,7 +184,12 @@ impl MultiLineLabel {
let mut multi_line_label_builder = MultiLineLabel::builder()
.set_text_color(color)
.set_text_alignment(multi_line_label_info.text_alignment)
.set_line_count(multi_line_label_info.line_count.get()?);
.set_line_count(
multi_line_label_info
.line_count
.get()
.with_context(|| "line count of label")?,
);
if let Some(background_type) = &multi_line_label_info.background_type {
multi_line_label_builder =

View file

@ -8,7 +8,7 @@ use std::sync::{
Arc, Mutex,
};
use anyhow::Result;
use anyhow::{Context, Result};
use utilities::prelude::*;
use super::fill_type::InnerFillType;
@ -296,7 +296,12 @@ impl MultiLineTextField {
let mut multi_line_text_field_builder = MultiLineTextField::builder()
.set_text_color(color)
.set_text_alignment(multi_line_text_field_info.text_alignment)
.set_line_count(multi_line_text_field_info.line_count.get()?);
.set_line_count(
multi_line_text_field_info
.line_count
.get()
.with_context(|| "line count of text field")?,
);
if let Some(background_type) = &multi_line_text_field_info.background_type {
multi_line_text_field_builder =