mod progress;
pub(in crate::gui::editor) use indicatrix_editor::guide::NEW_DESIGN_CREATED;
pub(in crate::gui::editor) use progress::{check_design_progress, check_progress, notify};
use super::state::EditorState;
use crate::{GuideAllow, GuideModel, GuideStepData, MainWindow};
use indicatrix_editor::guide::{Group, STEPS, Step};
use slint::{ComponentHandle, ModelRc, SharedString, VecModel};
use std::{cell::RefCell, rc::Rc};
fn guide_allow(allow: &[Group]) -> GuideAllow {
GuideAllow {
new_design: allow.contains(&Group::NewDesign),
tier_form: allow.contains(&Group::TierForm),
tier_table: allow.contains(&Group::TierTable),
design_settings: allow.contains(&Group::DesignSettings),
solve: allow.contains(&Group::Solve),
preform_tab: allow.contains(&Group::PreformTab),
advanced: allow.contains(&Group::Advanced),
view_tabs: allow.contains(&Group::ViewTabs),
file_ops: allow.contains(&Group::FileOps),
history: allow.contains(&Group::History),
}
}
fn step_data(step: &Step) -> GuideStepData {
let actions: Vec<SharedString> = step
.actions
.iter()
.map(|a| SharedString::from(*a))
.collect();
GuideStepData {
title: step.title.into(),
intro: step.intro.into(),
actions: ModelRc::new(VecModel::from(actions)),
check: step.check.into(),
why: step.why.into(),
waiting: step.waiting.into(),
highlight_target: step.highlight_target.into(),
completion: step.completion.into(),
allow: guide_allow(step.allow),
}
}
pub(in crate::gui::editor) fn setup_guide(ui: &MainWindow, state: &Rc<RefCell<EditorState>>) {
let steps: Vec<GuideStepData> = STEPS.iter().map(step_data).collect();
ui.global::<GuideModel>()
.set_steps(ModelRc::new(VecModel::from(steps)));
let state = Rc::clone(state);
let ui_weak = ui.as_weak();
ui.global::<GuideModel>().on_step_entered(move || {
let Some(ui) = ui_weak.upgrade() else {
return;
};
let Ok(st) = state.try_borrow() else {
return;
};
check_progress(&ui, &st);
});
}