Compare commits

...

5 Commits

Author SHA1 Message Date
Oliver Atkinson
035bd21466 closes #7 2025-05-16 09:43:49 -06:00
Oliver Atkinson
ba260b02bc Fix #2 2025-05-16 09:22:39 -06:00
Oliver Atkinson
141da7c17c moved todos into issues 2025-05-16 09:22:30 -06:00
Oliver Atkinson
e487bb9a69 Merge branch 'master' of https://git.oliveratkinson.net/Oliver/bible 2025-05-16 07:47:29 -06:00
Oliver Atkinson
8a7804e780 formatting 2025-04-08 13:04:34 -06:00
3 changed files with 59 additions and 45 deletions

View File

@ -11,14 +11,3 @@
[Tanach.us](https://tanach.us) [Tanach.us](https://tanach.us)
[AndBible's formats](https://github.com/AndBible/and-bible/wiki/Supported-3rd-party-module-formats) [AndBible's formats](https://github.com/AndBible/and-bible/wiki/Supported-3rd-party-module-formats)
## TODOs
- [ ]: When 1 scripture is open; put a button to view full chapter in new col
- [ ]: Button to add new col, same translation
- [ ]: Save all cols to file button
- [ ]: Only have 1 chapter/translation header for verse range copy
- [ ]: Pane widget could work for cols
- [ ]: Notes block at bottom of each col
- [ ]: Program doesn't wake back up from sleep very well

View File

@ -2,11 +2,11 @@
use iced::keyboard::key::Named; use iced::keyboard::key::Named;
use iced::keyboard::{Key, Modifiers}; use iced::keyboard::{Key, Modifiers};
use iced::{event, Event, Subscription}; use iced::{event, Event, Subscription};
use iced::widget::scrollable; use iced::widget::{scrollable, text_editor};
use iced::{ use iced::{
Element, Length, Task, Theme, clipboard, color, Element, Length, Task, Theme, clipboard, color,
widget::{ widget::{
self, button, column, combo_box, row, button, column, combo_box, row,
scrollable::{Direction, Scrollbar}, scrollable::{Direction, Scrollbar},
text, text_input, text, text_input,
}, },
@ -68,6 +68,7 @@ enum Message {
DeleteColumn(usize), DeleteColumn(usize),
SetErrorMessage(usize, String), SetErrorMessage(usize, String),
RecievedEvent(Event), RecievedEvent(Event),
NoteInput(usize, text_editor::Action),
} }
impl Message { impl Message {
@ -82,7 +83,8 @@ impl Message {
Message::WordSearchInput(i, _) | Message::WordSearchInput(i, _) |
Message::SubmitWordSearch(i) | Message::SubmitWordSearch(i) |
Message::QuickSearch(i, _, _) | Message::QuickSearch(i, _, _) |
Message::DeleteColumn(i) Message::DeleteColumn(i) |
Message::NoteInput(i, _)
=> { => {
Some(*i) Some(*i)
}, },
@ -92,7 +94,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,
@ -101,13 +103,15 @@ struct ColState {
word_search: String, word_search: String,
word_search_results: Option<Vec<(String, bool)>>, word_search_results: Option<Vec<(String, bool)>>,
notes: text_editor::Content,
error: Option<String>, error: Option<String>,
} }
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(),
@ -116,6 +120,8 @@ impl Default for ColState {
word_search: String::new(), word_search: String::new(),
word_search_results: None, word_search_results: None,
notes: text_editor::Content::new(),
error: None, error: None,
} }
} }
@ -124,7 +130,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 +165,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
@ -191,6 +197,10 @@ impl State {
} }
// match normal messages // match normal messages
match msg { match msg {
Message::NoteInput(i, action) => {
let notes = &mut self.states[i].notes;
notes.perform(action);
}
Message::CycleTheme => { Message::CycleTheme => {
let len = self.themes.len(); let len = self.themes.len();
let i = &mut self.theme_idx; let i = &mut self.theme_idx;
@ -209,13 +219,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 +239,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 +261,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) => {
@ -326,33 +342,36 @@ impl State {
} }
fn view(&self) -> Element<Message> { fn view(&self) -> Element<Message> {
//TODO error message // Header bar, static, doesn't scroll
column![ column![
button("Cycle Themes") button("Cycle Themes")
.on_press(Message::CycleTheme) .on_press(Message::CycleTheme)
.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 // Top of Column, text entry boxes
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( text_input("Search query, ie: Gen 1:1", &self.states[col_index].bible_search)
"Search query, ie: Gen 1:1",
&self.states[col_index].bible_search
)
.id(format!("tabId-{}", (col_index*2)+0)) .id(format!("tabId-{}", (col_index*2)+0))
.on_input(move |s| Message::BibleSearchInput(col_index, s)) .on_input(move |s| Message::BibleSearchInput(col_index, s))
.on_submit(Message::BibleSearchSubmit(col_index)), .on_submit(Message::BibleSearchSubmit(col_index)),
widget::text_input("Word Search", &self.states[col_index].word_search) text_input("Word Search", &self.states[col_index].word_search)
.id(format!("tabId-{}", (col_index*2)+1)) .id(format!("tabId-{}", (col_index*2)+1))
.on_input(move |s| Message::WordSearchInput(col_index, s)) .on_input(move |s| Message::WordSearchInput(col_index, s))
.on_submit(Message::SubmitWordSearch(col_index)), .on_submit(Message::SubmitWordSearch(col_index)),
// Horizontal Row just above scripture
row![ row![
button("Clear All") button("Clear All")
.on_press_with(move || Message::Clear(col_index)) .on_press_with(move || Message::Clear(col_index))
@ -367,6 +386,7 @@ impl State {
.style(text::danger), .style(text::danger),
] ]
.spacing(5), .spacing(5),
// Body
row![ row![
// Word search results // Word search results
scrollable( scrollable(
@ -396,10 +416,11 @@ impl State {
.padding([5, 5]) .padding([5, 5])
) )
.spacing(5), .spacing(5),
// Body // Scripture
scrollable( scrollable(
if let Some(body) = &self.states[col_index].scripture_body { if let Some(body) = &self.states[col_index].scripture_body {
column(body.split("\n").enumerate().map(|(i, msg)| { column(body.split("\n").enumerate().map(|(i, msg)| {
// Color every other verse slightly differently
let msg = parse(msg); let msg = parse(msg);
if i & 1 == 0 { if i & 1 == 0 {
text(msg.to_owned()).color(color![0xFFFFFF]).into() text(msg.to_owned()).color(color![0xFFFFFF]).into()
@ -415,13 +436,22 @@ impl State {
) )
} }
) )
// TODO make this dynamic
.height(600)
.spacing(5) .spacing(5)
], ],
// Notes
text_editor(&self.states[col_index].notes)
.placeholder("Notes...")
.on_action(move |a| Message::NoteInput(col_index, a))
.height(100)
// .id(format!("tabId-{}", (col_index*2)+2))
] ]
.spacing(5) .spacing(5)
.width(800.) .width(800.)
.into() .into()
})), })),
// Right most vertical buttons
button(text("+").center()) button(text("+").center())
.height(Length::Fixed(200.)) .height(Length::Fixed(200.))
.style(button::primary) .style(button::primary)

View File

@ -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 {