This commit is contained in:
Oliver Atkinson 2025-05-16 09:22:39 -06:00
parent 141da7c17c
commit ba260b02bc
2 changed files with 25 additions and 20 deletions

View File

@ -92,7 +92,7 @@ impl Message {
}
struct ColState {
selected_file: Option<String>,
file: Option<String>,
bible_selected: Option<bible::Bible>,
bible_search: String,
@ -107,7 +107,7 @@ struct ColState {
impl Default for ColState {
fn default() -> Self {
Self {
selected_file: None,
file: None,
bible_selected: None,
bible_search: String::new(),
@ -124,7 +124,7 @@ impl Default for ColState {
struct State {
files: combo_box::State<String>,
states: Vec<ColState>,
cols: usize,
// cols: usize,
tab_index: Option<i32>,
theme_idx: usize,
@ -159,7 +159,7 @@ impl Default for State {
Self {
files: combo_box::State::new(files),
states: vec![ColState::default()],
cols: 1,
// cols: 1,
tab_index: None,
// THEMES
// Dark - KanagawaDragon
@ -209,13 +209,13 @@ impl State {
let new_idx = if modifiers == Modifiers::SHIFT { idx-1 } else { idx+1 };
// 2 because two buttons on each col
let new_idx = new_idx.clamp(0, (self.cols*2) as i32 -1);
let new_idx = new_idx.clamp(0, (self.states.len()*2) as i32 -1);
self.tab_index = Some(new_idx);
let id = format!("tabId-{}", new_idx);
return text_input::focus(id);
} else {
if self.cols > 0 {
if self.states.len() > 0 {
self.tab_index = Some(0);
return text_input::focus("tabId-0");
}
@ -229,14 +229,20 @@ impl State {
self.states[i].error = Some(m);
}
Message::DeleteColumn(idx) => {
self.cols -= 1;
// self.cols -= 1;
self.states.remove(idx);
}
Message::AddColRight => {
self.cols += 1;
// clone this state into the new one
// self.states.push(self.states.into_iter().last().unwrap().clone())
self.states.push(ColState::default())
self.states.push(ColState::default());
// Add the rightmost opened Bible to the new column
if let Some(last) = self.states.get(self.states.len()-2) {
let file = &last.file;
if let Some(file) = file {
return self.update(Message::BibleSelected(self.states.len()-1, file.to_string()));
}
};
}
Message::BibleSelected(i, file) => {
match fs::read_to_string(&file) {
@ -245,8 +251,8 @@ impl State {
Ok(bible) => {
// State is held technically in this variable, although
// the Bible is held in memory in it's own variable.
self.states[i].selected_file = Some(format!("{bible}"));
self.states[i].bible_selected = Some(bible);
self.states[i].file = Some(file);
}
Err(err) => {
@ -333,13 +339,17 @@ impl State {
.style(button::secondary),
scrollable(
row![
row((0..self.cols).map(|col_index| {
row((0..self.states.len()).map(|col_index| {
column![
// header
combo_box(
&self.files,
"Select Bible",
self.states[col_index].selected_file.as_ref(),
// Some(&"IDK where this text is".to_string()),
match &self.states[col_index].bible_selected {
Some(b) => Some(&b.translation_name),
None => None,
},
move |s| Message::BibleSelected(col_index, s)
),
text_input("Search query, ie: Gen 1:1", &self.states[col_index].bible_search)

View File

@ -269,15 +269,10 @@ impl Chapter {
#[derive(Deserialize)]
pub struct Bible {
#[serde(rename = "@translation")]
translation_name: String,
pub translation_name: String,
#[serde(rename = "testament")]
testaments: Vec<Testament>,
}
impl Display for Bible {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}",self.translation_name)
}
}
#[derive(Deserialize)]
struct Testament {