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

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 {