diff --git a/Cargo.toml b/Cargo.toml index 42758ff..37fb9cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "speki" -version = "0.4.3" +version = "0.4.4" edition = "2021" authors = ["Tor Berge torberge@outlook.com"] license = "GPL-2.0-only" diff --git a/src/popups/wikiselect.rs b/src/popups/wikiselect.rs index 1446f67..41f5a64 100644 --- a/src/popups/wikiselect.rs +++ b/src/popups/wikiselect.rs @@ -1,31 +1,32 @@ -use tui::layout::Rect; +use tui::layout::{Constraint, Rect}; use tui::Frame; use crate::app::{AppData, PopUpState, Tab, TabData, Widget}; use crate::utils::aliases::*; -use crate::utils::misc::{split_updown_by_percent, View}; +use crate::utils::misc::split_updown; use crate::utils::sql::insert::new_incread; +use crate::widgets::infobox::InfoBox; use crate::widgets::textinput::Field; use crate::{MyKey, MyType}; -pub struct WikiSelect { +pub struct WikiSelect<'a> { pub searchbar: Field, - prompt: String, + prompt: InfoBox<'a>, topic: TopicID, tabdata: TabData, } -impl WikiSelect { +impl<'a> WikiSelect<'a> { pub fn new(id: TopicID) -> Self { WikiSelect { searchbar: Field::default(), - prompt: "Search for a wikipedia page".to_string(), + prompt: InfoBox::new("Search for a wikipedia page".to_string()), topic: id, tabdata: TabData::default(), } } } -impl Tab for WikiSelect { +impl<'a> Tab for WikiSelect<'a> { fn get_tabdata(&mut self) -> &mut TabData { &mut self.tabdata } @@ -34,10 +35,6 @@ impl Tab for WikiSelect { "Wikipedia selection".to_string() } - fn get_view(&mut self) -> &mut View { - todo!() - } - fn navigate(&mut self, _dir: crate::NavDir) {} fn keyhandler(&mut self, appdata: &AppData, key: MyKey, _cursor: &(u16, u16)) { @@ -50,24 +47,29 @@ impl Tab for WikiSelect { new_incread(&appdata.conn, 0, self.topic, content, true).unwrap(); self.tabdata.state = PopUpState::Exit; } else { - self.prompt = "Invalid search result".to_string(); + self.prompt = InfoBox::new("Invalid search result".to_string()); } } key => self.searchbar.keyhandler(appdata, key), } } + fn set_selection(&mut self, area: Rect) { + let chunks = split_updown( + [ + Constraint::Percentage(20), + Constraint::Percentage(20), + Constraint::Length(3), + Constraint::Percentage(20), + ], + area, + ); + self.prompt.set_area(chunks[1]); + self.searchbar.set_area(chunks[2]); + self.tabdata.view.areas.push(chunks[2]); + } - fn set_selection(&mut self, _area: Rect) {} - - fn render(&mut self, f: &mut Frame, appdata: &AppData, _cursor: &(u16, u16)) { - let cursor = &(0, 0); - let chunks = split_updown_by_percent([50, 50], f.size()); - let (mut msg, mut search) = (chunks[0], chunks[1]); - msg.y = search.y - 5; - msg.height = 5; - search.height = 3; - self.searchbar.set_area(chunks[1]); - //draw_message(f, msg, &self.prompt); + fn render(&mut self, f: &mut Frame, appdata: &AppData, cursor: &(u16, u16)) { + self.prompt.render(f, appdata, cursor); self.searchbar.render(f, appdata, cursor); } } diff --git a/src/utils/incread.rs b/src/utils/incread.rs index 63ba0e0..b88cbce 100644 --- a/src/utils/incread.rs +++ b/src/utils/incread.rs @@ -37,10 +37,10 @@ pub struct IncRead { pub id: IncID, pub parent: IncID, pub topic: TopicID, + pub isactive: bool, pub source: Field, pub extracts: StatefulList, pub clozes: StatefulList, - pub isactive: bool, } impl IncRead {