merge GUI #1
							
								
								
									
										102
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										102
									
								
								src/main.rs
									
									
									
									
									
								
							@@ -1,9 +1,14 @@
 | 
			
		||||
#![feature(iter_map_windows)]
 | 
			
		||||
use iced::widget::scrollable;
 | 
			
		||||
use iced::{
 | 
			
		||||
    clipboard, color, widget::{
 | 
			
		||||
        self, button, column, combo_box, row, scrollable, scrollable::{Direction, Scrollbar}, text, text_input
 | 
			
		||||
    }, Element, Length, Task, Theme
 | 
			
		||||
    Color, Element, Length, Task, Theme, clipboard, color,
 | 
			
		||||
    widget::{
 | 
			
		||||
        self, button, column, combo_box, row,
 | 
			
		||||
        scrollable::{Direction, Scrollbar},
 | 
			
		||||
        text, text_input,
 | 
			
		||||
    },
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
use std::{env, fs, path::PathBuf};
 | 
			
		||||
use texts::*;
 | 
			
		||||
 | 
			
		||||
@@ -30,6 +35,30 @@ fn main() -> iced::Result {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // ALL BUILTIN THEMES
 | 
			
		||||
    //    Light
 | 
			
		||||
    //    Dark
 | 
			
		||||
    //    Dracula
 | 
			
		||||
    //    Nord
 | 
			
		||||
    //    SolarizedLight
 | 
			
		||||
    //    SolarizedDark
 | 
			
		||||
    //    GruvboxLight
 | 
			
		||||
    //    GruvboxDark
 | 
			
		||||
    //    CatppuccinLatte
 | 
			
		||||
    //    CatppuccinFrappe
 | 
			
		||||
    //    CatppuccinMacchiato
 | 
			
		||||
    //    CatppuccinMocha
 | 
			
		||||
    //    TokyoNight
 | 
			
		||||
    //    TokyoNightStorm
 | 
			
		||||
    //    TokyoNightLight
 | 
			
		||||
    //    KanagawaWave
 | 
			
		||||
    //    KanagawaDragon
 | 
			
		||||
    //    KanagawaLotus
 | 
			
		||||
    //    Moonfly
 | 
			
		||||
    //    Nightfly
 | 
			
		||||
    //    Oxocarbon
 | 
			
		||||
    //    Ferra
 | 
			
		||||
 | 
			
		||||
    // GUI
 | 
			
		||||
    iced::application("Bible Study", State::update, State::view)
 | 
			
		||||
        .theme(|_| Theme::Nord)
 | 
			
		||||
@@ -47,6 +76,7 @@ enum Message {
 | 
			
		||||
    SubmitWordSearch(usize),
 | 
			
		||||
    QuickSearch(usize, String),
 | 
			
		||||
    AddColRight,
 | 
			
		||||
    DeleteColumn(usize),
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct ColState {
 | 
			
		||||
@@ -116,6 +146,10 @@ impl Default for State {
 | 
			
		||||
impl State {
 | 
			
		||||
    fn update(&mut self, msg: Message) -> Task<Message> {
 | 
			
		||||
        match msg {
 | 
			
		||||
            Message::DeleteColumn(idx) => {
 | 
			
		||||
                self.cols -= 1;
 | 
			
		||||
                self.states.remove(idx);
 | 
			
		||||
            }
 | 
			
		||||
            Message::AddColRight => {
 | 
			
		||||
                self.cols += 1;
 | 
			
		||||
                // clone this state into the new one
 | 
			
		||||
@@ -178,6 +212,11 @@ impl State {
 | 
			
		||||
            row((0..self.cols).map(|col_index| {
 | 
			
		||||
                column![
 | 
			
		||||
                    // header
 | 
			
		||||
                    button("Delete Column")
 | 
			
		||||
                        .on_press_with(move || Message::DeleteColumn(col_index))
 | 
			
		||||
                        .width(Length::Fill)
 | 
			
		||||
                        .style(button::danger)
 | 
			
		||||
                        ,
 | 
			
		||||
                    combo_box(
 | 
			
		||||
                        &self.files,
 | 
			
		||||
                        "Select Bible",
 | 
			
		||||
@@ -194,10 +233,16 @@ impl State {
 | 
			
		||||
                        .on_input(move |s| Message::WordSearchInput(col_index, s))
 | 
			
		||||
                        .on_submit(Message::SubmitWordSearch(col_index)),
 | 
			
		||||
                    row![
 | 
			
		||||
                        button("Clear All").on_press_with(move || Message::Clear(col_index)),
 | 
			
		||||
                        button("Clear All")
 | 
			
		||||
                            .on_press_with(move || Message::Clear(col_index))
 | 
			
		||||
                            .style(button::secondary)
 | 
			
		||||
                            ,
 | 
			
		||||
                        button("Copy Scripture")
 | 
			
		||||
                            .on_press_with(move || Message::CopyText(col_index)),
 | 
			
		||||
                    ],
 | 
			
		||||
                            .on_press_with(move || Message::CopyText(col_index))
 | 
			
		||||
                            .style(button::primary)
 | 
			
		||||
                            ,
 | 
			
		||||
                    ]
 | 
			
		||||
                    .spacing(5),
 | 
			
		||||
                    row![
 | 
			
		||||
                        // Word search results
 | 
			
		||||
                        scrollable(
 | 
			
		||||
@@ -218,35 +263,39 @@ impl State {
 | 
			
		||||
                        )
 | 
			
		||||
                        .spacing(5),
 | 
			
		||||
                        // Body
 | 
			
		||||
                        scrollable(
 | 
			
		||||
                            if let Some(body) = &self.states[col_index].scripture_body {
 | 
			
		||||
                                column(body.split("\n").enumerate().map(|(i, msg)| {
 | 
			
		||||
                                    let msg = parse(msg);
 | 
			
		||||
                                    if i & 1 == 0 {
 | 
			
		||||
                                        text(msg.to_owned())
 | 
			
		||||
                                            .color(color![0xFFFFFF])
 | 
			
		||||
                                            .into()
 | 
			
		||||
                                    } else {
 | 
			
		||||
                                        text(msg.to_owned()).color(color![0xAAAAAA]).into()
 | 
			
		||||
                                    }
 | 
			
		||||
                                }))
 | 
			
		||||
                            } else {
 | 
			
		||||
                                column(
 | 
			
		||||
                                    Vec::<String>::new().iter().map(|_| text(String::new()).into())
 | 
			
		||||
                                    )
 | 
			
		||||
                            }
 | 
			
		||||
                        )
 | 
			
		||||
                        scrollable(if let Some(body) = &self.states[col_index].scripture_body {
 | 
			
		||||
                            column(body.split("\n").enumerate().map(|(i, msg)| {
 | 
			
		||||
                                let msg = parse(msg);
 | 
			
		||||
                                if i & 1 == 0 {
 | 
			
		||||
                                    text(msg.to_owned()).color(color![0xFFFFFF]).into()
 | 
			
		||||
                                } else {
 | 
			
		||||
                                    text(msg.to_owned()).color(color![0xAAAAAA]).into()
 | 
			
		||||
                                }
 | 
			
		||||
                            }))
 | 
			
		||||
                        } else {
 | 
			
		||||
                            column(
 | 
			
		||||
                                Vec::<String>::new()
 | 
			
		||||
                                    .iter()
 | 
			
		||||
                                    .map(|_| text(String::new()).into()),
 | 
			
		||||
                            )
 | 
			
		||||
                        })
 | 
			
		||||
                        .spacing(5)
 | 
			
		||||
                    ],
 | 
			
		||||
                ]
 | 
			
		||||
                .padding([10, 5])
 | 
			
		||||
                .spacing(5)
 | 
			
		||||
                .width(800.)
 | 
			
		||||
                .into()
 | 
			
		||||
            })),
 | 
			
		||||
            button(text("+").center())
 | 
			
		||||
                .height(Length::Fixed(200.))
 | 
			
		||||
                .style(button::primary)
 | 
			
		||||
                .on_press(Message::AddColRight)
 | 
			
		||||
        ])
 | 
			
		||||
        ]
 | 
			
		||||
        // 5 pixles css-like padding
 | 
			
		||||
        .padding([5,5])
 | 
			
		||||
        // space elements inside this 5 pixels apart
 | 
			
		||||
        .spacing(5)
 | 
			
		||||
        )
 | 
			
		||||
        .direction(Direction::Horizontal(Scrollbar::new()))
 | 
			
		||||
        .into()
 | 
			
		||||
    }
 | 
			
		||||
@@ -331,4 +380,3 @@ fn parse(input: &str) -> String {
 | 
			
		||||
 | 
			
		||||
    modified
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user