Skip to content

Commit

Permalink
v0.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
ksk001100 committed Mar 29, 2022
1 parent 7d0e7ef commit 235b0a0
Show file tree
Hide file tree
Showing 12 changed files with 254 additions and 199 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "picterm"
version = "0.0.7"
version = "0.0.8"
authors = ["Keisuke Toyota <[email protected]>"]
edition = "2018"
repository = "https://github.com/ksk001100/picterm"
Expand Down
194 changes: 0 additions & 194 deletions src/app/ui.rs

This file was deleted.

32 changes: 32 additions & 0 deletions src/app/ui/help.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use crate::app::Actions;
use tui::{
layout::Constraint,
style::{Color, Style},
text::Span,
widgets::{Block, BorderType, Borders, Cell, Row, Table},
};

pub fn draw(actions: &Actions) -> Table {
let key_style = Style::default().fg(Color::LightCyan);
let help_style = Style::default().fg(Color::Gray);

let mut rows = vec![];
for action in actions.actions().iter() {
let keys: Vec<String> = action.keys().iter().map(|k| k.to_string()).collect();
let key = keys.join(", ");
let row = Row::new(vec![
Cell::from(Span::styled(key, key_style)),
Cell::from(Span::styled(action.to_string(), help_style)),
]);
rows.push(row);
}

Table::new(rows)
.block(
Block::default()
.borders(Borders::ALL)
.border_type(BorderType::Plain),
)
.widths(&[Constraint::Length(30), Constraint::Percentage(70)])
.column_spacing(1)
}
23 changes: 23 additions & 0 deletions src/app/ui/image.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use crate::app::state::AppState;
use tui::{
layout::Alignment,
style::{Color, Style},
widgets::{Block, BorderType, Borders, Paragraph},
};

pub fn draw<'a>(state: &'a AppState) -> Paragraph<'a> {
let result = if let Some(current_image) = state.get_current_image() {
current_image
} else {
vec![]
};

Paragraph::new(result)
.block(
Block::default()
.borders(Borders::ALL)
.style(Style::default().fg(Color::White))
.border_type(BorderType::Plain),
)
.alignment(Alignment::Center)
}
28 changes: 28 additions & 0 deletions src/app/ui/image_list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use crate::app::state::AppState;
use tui::{
style::{Color, Style},
widgets::{Block, BorderType, Borders, List, ListItem},
};

pub fn draw<'a>(state: &AppState) -> List<'a> {
let list_items: Vec<ListItem> = state
.get_paths()
.iter()
.map(|img| {
ListItem::new(
img.file_name()
.unwrap()
.to_os_string()
.into_string()
.unwrap(),
)
})
.collect();

List::new(list_items).highlight_symbol(">>").block(
Block::default()
.borders(Borders::ALL)
.style(Style::default().fg(Color::White))
.border_type(BorderType::Plain),
)
}
48 changes: 48 additions & 0 deletions src/app/ui/info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use crate::app::state::AppState;
use byte_unit::Byte;
use tui::{
layout::Constraint,
style::{Color, Style},
text::Span,
widgets::{Block, BorderType, Borders, Cell, Row, Table},
};

pub fn draw<'a>(state: &AppState) -> Table<'a> {
let key_style = Style::default().fg(Color::LightCyan);
let value_style = Style::default().fg(Color::Gray);

let rows = if let Some(image_info) = state.get_current_image_info() {
let size = Byte::from(image_info.size)
.get_appropriate_unit(false)
.to_string();

vec![
Row::new(vec![
Cell::from(Span::styled("Name", key_style)),
Cell::from(Span::styled(image_info.name, value_style)),
]),
Row::new(vec![
Cell::from(Span::styled("Dimensions", key_style)),
Cell::from(Span::styled(
format!("{}x{}", image_info.dimensions.0, image_info.dimensions.1),
value_style,
)),
]),
Row::new(vec![
Cell::from(Span::styled("Size", key_style)),
Cell::from(Span::styled(size, value_style)),
]),
]
} else {
vec![]
};

Table::new(rows)
.block(
Block::default()
.borders(Borders::ALL)
.border_type(BorderType::Plain),
)
.widths(&[Constraint::Length(15), Constraint::Percentage(85)])
.column_spacing(1)
}
23 changes: 23 additions & 0 deletions src/app/ui/loading.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use tui::{
layout::Alignment,
style::{Color, Modifier, Style},
text::Span,
widgets::{Block, BorderType, Borders, Paragraph, Wrap},
};

pub fn draw<'a>() -> Paragraph<'a> {
Paragraph::new(Span::styled(
"Loading...",
Style::default()
.fg(Color::White)
.add_modifier(Modifier::BOLD),
))
.block(
Block::default()
.borders(Borders::ALL)
.style(Style::default().fg(Color::White))
.border_type(BorderType::Plain),
)
.alignment(Alignment::Center)
.wrap(Wrap { trim: true })
}
Loading

0 comments on commit 235b0a0

Please sign in to comment.