81 lines
2.0 KiB
Rust
81 lines
2.0 KiB
Rust
use std::{cmp::Ordering, sync::Arc};
|
|
|
|
use crate::util::EqData;
|
|
use druid::{
|
|
widget::{Flex, Label, List, Scroll},
|
|
AppLauncher,
|
|
Color,
|
|
Data,
|
|
Lens,
|
|
Widget,
|
|
WidgetExt,
|
|
WindowDesc,
|
|
};
|
|
use libjens::{api::Meme, JMClient};
|
|
|
|
pub(crate) mod util;
|
|
|
|
const LIST_COLS: &[(&str, f64)] = &[("Link", 1000.), ("User", 50.)];
|
|
|
|
#[tokio::main]
|
|
async fn main() -> anyhow::Result<()> {
|
|
let client = JMClient::new();
|
|
let mut memes = client
|
|
.get_memes()
|
|
.await?
|
|
.iter()
|
|
.map(|m| EqData(m.clone()))
|
|
.collect::<Vec<_>>();
|
|
|
|
memes.sort_by(|a, b| {
|
|
if let Ok((a, b)) =
|
|
a.0.file_name()
|
|
.and_then(|a| b.0.file_name().map(|b| (a, b)))
|
|
{
|
|
a.cmp(b)
|
|
} else {
|
|
Ordering::Equal
|
|
}
|
|
});
|
|
|
|
let main_gui = WindowDesc::new(build_root_widget).title("JensMemes GUI");
|
|
|
|
AppLauncher::with_window(main_gui).launch(State {
|
|
memes: Arc::new(memes),
|
|
})?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[derive(Debug, Clone, Data, Lens)]
|
|
pub struct State {
|
|
pub memes: Arc<Vec<EqData<Meme>>>,
|
|
}
|
|
|
|
fn build_root_widget() -> impl Widget<State> {
|
|
Scroll::new(
|
|
Flex::column()
|
|
.with_child(
|
|
Flex::row()
|
|
.with_child(Label::new(LIST_COLS[0].0).fix_width(LIST_COLS[0].1))
|
|
.with_child(Label::new(LIST_COLS[1].0).fix_width(LIST_COLS[1].1))
|
|
.background(Color::grey8(0x33)),
|
|
)
|
|
.with_child(
|
|
List::new(|| {
|
|
Flex::row()
|
|
.with_child(
|
|
Label::dynamic(|d: &EqData<Meme>, _| d.0.link.clone())
|
|
.fix_width(LIST_COLS[0].1),
|
|
)
|
|
.with_child(
|
|
Label::dynamic(|d: &EqData<Meme>, _| d.0.user.clone())
|
|
.fix_width(LIST_COLS[1].1),
|
|
)
|
|
})
|
|
.lens(State::memes),
|
|
),
|
|
)
|
|
.padding(5.)
|
|
}
|