Actually render images
Some checks failed
CI / lint (push) Failing after 34s
CI / Build and test (, nightly) (push) Failing after 10m58s
CI / Build and test (, 1.76.0) (push) Failing after 11m33s
CI / Build and test (, beta) (push) Failing after 11m31s

This commit is contained in:
2024-02-11 11:40:58 +01:00
parent 719f87afaa
commit 85a07dbe98
3 changed files with 16 additions and 10 deletions

View File

@ -87,7 +87,7 @@ tui-textarea = "0.3.0"
unicode-width = "0.1"
# UI (images)
ratatui-image = { version = "0.8.0", optional = true }
ratatui-image = { version = "0.8.0", optional = true, features = ["crossterm"] }
image = { version = "0.24.8", optional = true }
[patch.crates-io]

View File

@ -53,6 +53,10 @@ pub struct App {
impl App {
pub async fn new(frame_rate: f64, log_receiver: mpsc::UnboundedReceiver<String>) -> Result<Self> {
// Forces PROTOCOL_PICKER to be initialized early, as it may get stuck if called
// after we started rendering.
#[cfg(feature = "images")]
log::info!("Using image protocol: {:?}", crate::widgets::PROTOCOL_PICKER.protocol_type);
let config = Config::new()?;
let datadir = config.config._data_dir.join("default");
let future_clients = config.accounts.clone().map(|conf| {

View File

@ -78,7 +78,7 @@ mod images {
lazy_static::lazy_static! {
static ref PROTOCOL_PICKER_LOCK: Mutex<()> = Mutex::new(());
static ref PROTOCOL_PICKER: Picker = make_protocol_picker();
pub static ref PROTOCOL_PICKER: Picker = make_protocol_picker();
}
fn make_protocol_picker() -> Picker {
@ -99,15 +99,17 @@ mod images {
}
impl<'a> OverlappableWidget for BottomAlignedImage<'a> {
fn height(&self, _width: u16) -> u64 {
20 // TODO
}
fn render_overlap(self, area: Rect, buf: &mut Buffer) -> (u16, u16) {
/*
let width = u16::min(100, area.width);
fn height(&self, width: u16) -> u64 {
let width_px: u32 = (width as u32) * (PROTOCOL_PICKER.font_size.0 as u32);
let height_px = width_px * self.0.height() / self.0.width();
let height = u32::min(u16::MAX.into(), height_px / (PROTOCOL_PICKER.font_size.1 as u32)) as u16;
u32::min(u16::MAX.into(), height_px / (PROTOCOL_PICKER.font_size.1 as u32)).into()
}
fn render_overlap(self, mut area: Rect, buf: &mut Buffer) -> (u16, u16) {
let width = u16::min(100, area.width);
let height = u64::min(self.height(width), u16::MAX.into()) as u16;
area.y = u16::max(area.y, area.y.saturating_add(area.height).saturating_sub(height));
let protocol = PROTOCOL_PICKER
.clone()
@ -124,12 +126,12 @@ mod images {
.expect("picker.new_protocol failed");
let widget= ratatui_image::Image::new(protocol.as_ref());
widget.render(area, buf); // TODO: scroll
*/
(area.width, 20)
}
}
}
#[cfg(feature = "images")]
pub use images::*;
/*