Fix #2
This commit is contained in:
parent
141da7c17c
commit
ba260b02bc
38
src/main.rs
38
src/main.rs
@ -92,7 +92,7 @@ impl Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct ColState {
|
struct ColState {
|
||||||
selected_file: Option<String>,
|
file: Option<String>,
|
||||||
bible_selected: Option<bible::Bible>,
|
bible_selected: Option<bible::Bible>,
|
||||||
|
|
||||||
bible_search: String,
|
bible_search: String,
|
||||||
@ -107,7 +107,7 @@ struct ColState {
|
|||||||
impl Default for ColState {
|
impl Default for ColState {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
selected_file: None,
|
file: None,
|
||||||
bible_selected: None,
|
bible_selected: None,
|
||||||
|
|
||||||
bible_search: String::new(),
|
bible_search: String::new(),
|
||||||
@ -124,7 +124,7 @@ impl Default for ColState {
|
|||||||
struct State {
|
struct State {
|
||||||
files: combo_box::State<String>,
|
files: combo_box::State<String>,
|
||||||
states: Vec<ColState>,
|
states: Vec<ColState>,
|
||||||
cols: usize,
|
// cols: usize,
|
||||||
tab_index: Option<i32>,
|
tab_index: Option<i32>,
|
||||||
|
|
||||||
theme_idx: usize,
|
theme_idx: usize,
|
||||||
@ -159,7 +159,7 @@ impl Default for State {
|
|||||||
Self {
|
Self {
|
||||||
files: combo_box::State::new(files),
|
files: combo_box::State::new(files),
|
||||||
states: vec![ColState::default()],
|
states: vec![ColState::default()],
|
||||||
cols: 1,
|
// cols: 1,
|
||||||
tab_index: None,
|
tab_index: None,
|
||||||
// THEMES
|
// THEMES
|
||||||
// Dark - KanagawaDragon
|
// Dark - KanagawaDragon
|
||||||
@ -209,13 +209,13 @@ impl State {
|
|||||||
let new_idx = if modifiers == Modifiers::SHIFT { idx-1 } else { idx+1 };
|
let new_idx = if modifiers == Modifiers::SHIFT { idx-1 } else { idx+1 };
|
||||||
|
|
||||||
// 2 because two buttons on each col
|
// 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);
|
self.tab_index = Some(new_idx);
|
||||||
|
|
||||||
let id = format!("tabId-{}", new_idx);
|
let id = format!("tabId-{}", new_idx);
|
||||||
return text_input::focus(id);
|
return text_input::focus(id);
|
||||||
} else {
|
} else {
|
||||||
if self.cols > 0 {
|
if self.states.len() > 0 {
|
||||||
self.tab_index = Some(0);
|
self.tab_index = Some(0);
|
||||||
return text_input::focus("tabId-0");
|
return text_input::focus("tabId-0");
|
||||||
}
|
}
|
||||||
@ -229,14 +229,20 @@ impl State {
|
|||||||
self.states[i].error = Some(m);
|
self.states[i].error = Some(m);
|
||||||
}
|
}
|
||||||
Message::DeleteColumn(idx) => {
|
Message::DeleteColumn(idx) => {
|
||||||
self.cols -= 1;
|
// self.cols -= 1;
|
||||||
self.states.remove(idx);
|
self.states.remove(idx);
|
||||||
}
|
}
|
||||||
Message::AddColRight => {
|
Message::AddColRight => {
|
||||||
self.cols += 1;
|
self.states.push(ColState::default());
|
||||||
// clone this state into the new one
|
|
||||||
// self.states.push(self.states.into_iter().last().unwrap().clone())
|
// Add the rightmost opened Bible to the new column
|
||||||
self.states.push(ColState::default())
|
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) => {
|
Message::BibleSelected(i, file) => {
|
||||||
match fs::read_to_string(&file) {
|
match fs::read_to_string(&file) {
|
||||||
@ -245,8 +251,8 @@ impl State {
|
|||||||
Ok(bible) => {
|
Ok(bible) => {
|
||||||
// State is held technically in this variable, although
|
// State is held technically in this variable, although
|
||||||
// the Bible is held in memory in it's own variable.
|
// 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].bible_selected = Some(bible);
|
||||||
|
self.states[i].file = Some(file);
|
||||||
|
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@ -333,13 +339,17 @@ impl State {
|
|||||||
.style(button::secondary),
|
.style(button::secondary),
|
||||||
scrollable(
|
scrollable(
|
||||||
row![
|
row![
|
||||||
row((0..self.cols).map(|col_index| {
|
row((0..self.states.len()).map(|col_index| {
|
||||||
column![
|
column![
|
||||||
// header
|
// header
|
||||||
combo_box(
|
combo_box(
|
||||||
&self.files,
|
&self.files,
|
||||||
"Select Bible",
|
"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)
|
move |s| Message::BibleSelected(col_index, s)
|
||||||
),
|
),
|
||||||
text_input("Search query, ie: Gen 1:1", &self.states[col_index].bible_search)
|
text_input("Search query, ie: Gen 1:1", &self.states[col_index].bible_search)
|
||||||
|
@ -269,15 +269,10 @@ impl Chapter {
|
|||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct Bible {
|
pub struct Bible {
|
||||||
#[serde(rename = "@translation")]
|
#[serde(rename = "@translation")]
|
||||||
translation_name: String,
|
pub translation_name: String,
|
||||||
#[serde(rename = "testament")]
|
#[serde(rename = "testament")]
|
||||||
testaments: Vec<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)]
|
#[derive(Deserialize)]
|
||||||
struct Testament {
|
struct Testament {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user