Fix image problems
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Isaac Mills 2024-03-18 19:23:41 -04:00
parent 181741fe68
commit a92c3fdf0c
Signed by: fnmain
GPG key ID: B67D7410F33A0F61
3 changed files with 32 additions and 50 deletions

4
Cargo.lock generated
View file

@ -792,6 +792,7 @@ dependencies = [
[[package]]
name = "cosmic-jotdown"
version = "0.1.0"
source = "git+https://git.nations.lol/fnmain/cosmic-jotdown#1207336fd313c970233ab332cf04683fbd7df693"
dependencies = [
"cosmic-text",
"jotdown",
@ -1031,6 +1032,7 @@ dependencies = [
[[package]]
name = "egui-glyphon"
version = "0.1.0"
source = "git+https://git.nations.lol/fnmain/egui-glyphon#3626c7e55d45734eff9b1b7df04349d97de77667"
dependencies = [
"egui",
"egui-wgpu",
@ -1628,6 +1630,7 @@ dependencies = [
[[package]]
name = "glyphon"
version = "0.5.0"
source = "git+https://git.nations.lol/fnmain/glyphon.git#01ab64704b123d1ae61a5022b2b8ea2a7a4573e8"
dependencies = [
"cosmic-text",
"etagere",
@ -1869,6 +1872,7 @@ dependencies = [
[[package]]
name = "jotdown"
version = "0.3.2"
source = "git+https://git.nations.lol/fnmain/jotdown#8239b2b51d2ad3517bb0e71440e7bcd5114e08d2"
dependencies = [
"databake",
]

View file

@ -12,11 +12,20 @@ fn main() {
let file = std::fs::read_to_string(&path).unwrap();
let name = path.file_name().unwrap();
let jot: Cow<'_, [Event<'_>]> = Cow::Owned(jotdown::Parser::new(&file).collect::<Vec<_>>());
let mut jot = jotdown::Parser::new(&file).collect::<Vec<_>>();
jot.push(Event::Start(
jotdown::Container::Paragraph,
jotdown::Attributes(None),
));
jot.push(Event::Str("Click anywhere to return to home screen".into()));
jot.push(Event::End(jotdown::Container::Paragraph));
std::fs::write(
Path::new(&out).join(name),
jot.bake(&Default::default()).to_string(),
Cow::Owned::<'_, [Event<'_>]>(jot)
.bake(&Default::default())
.to_string(),
)
.unwrap();
}

View file

@ -37,7 +37,6 @@ pub struct Portfolio {
to_beamwidth: f32,
font_system: Arc<Mutex<FontSystem>>,
name_buffers: [(Arc<RwLock<Buffer>>, Vec2); 3],
click_anywhere_buffer: (Vec2, Arc<RwLock<Buffer>>),
window: ContextWindow,
buffer_size: Vec2,
max_size: Rect,
@ -62,7 +61,6 @@ pub enum ContextBlock {
Image {
alt_text: Arc<RwLock<Buffer>>,
image: Image<'static>,
size: Vec2,
},
}
@ -253,7 +251,6 @@ impl ContextWindow {
ContextBlock::Image {
alt_text: Arc::new(RwLock::new(buffer.buffer)),
image,
size,
},
);
const IMAGE_PADDING: f32 = 8.0;
@ -274,7 +271,21 @@ impl ContextWindow {
res.0 = res.0.translate(Vec2::new(ls.x, 0.0));
}
} else {
last_image_size = Some(size + Vec2::new(IMAGE_PADDING, 0.0));
if size.x > max_width {
let max_size = Vec2::new(max_width, size.y);
let new_size = ImageSize {
max_size,
..Default::default()
}
.calc_size(max_size, size);
res.0 = Rect::from_min_size(
Pos2::new(buffer.indent.indent, self.size.y + paragraph_height),
new_size,
);
self.size.y += new_size.y + paragraph_height;
} else {
last_image_size = Some(size);
}
}
res
} else {
@ -301,7 +312,6 @@ impl ContextWindow {
if let Some(size) = last_image_size {
self.size.y += size.y;
}
self.size.y += CONTEXT_METRICS.line_height * 3.0;
}
}
@ -386,18 +396,6 @@ impl Portfolio {
"/usr/share/fonts/TTF/FiraCode-Regular.ttf"
))));
let (buffer_size, name_buffers) = make_buffers(&mut font_system, 1.0);
let mut click_anywhere_buffer =
egui_glyphon::glyphon::Buffer::new(&mut font_system, Metrics::new(16.0, 18.0));
click_anywhere_buffer.set_size(&mut font_system, f32::MAX, f32::MAX);
click_anywhere_buffer.set_text(
&mut font_system,
"Click anywhere to return to home page",
Attrs::new()
.family(glyphon::Family::SansSerif)
.weight(Weight::LIGHT),
glyphon::Shaping::Basic,
);
click_anywhere_buffer.shape_until_scroll(&mut font_system, true);
let font_system = Arc::new(Mutex::new(font_system));
GlyphonRenderer::insert(
cc.wgpu_render_state.as_ref().unwrap(),
@ -418,10 +416,6 @@ impl Portfolio {
to_beamwidth: 2.0,
font_system,
name_buffers,
click_anywhere_buffer: (
measure_buffer(&click_anywhere_buffer, Vec2::INFINITY).size(),
Arc::new(RwLock::new(click_anywhere_buffer)),
),
buffer_size,
window: ContextWindow::default(),
max_size: Rect::ZERO,
@ -689,38 +683,13 @@ impl eframe::App for Portfolio {
_ => {}
}
}
ContextBlock::Image { image, size, .. } => {
ContextBlock::Image { image, .. } => {
image
.clone()
.tint(Color32::WHITE.gamma_multiply(zoom_view_opacity))
.paint_at(
ui,
Rect::from_min_size(
context_block.0.translate(rect.min.to_vec2()).min,
if size.x > rect.width() {
let max_size = Vec2::new(rect.width(), size.y);
ImageSize {
max_size,
..Default::default()
}
.calc_size(max_size, *size)
} else {
*size
},
),
);
.paint_at(ui, context_block.0.translate(rect.min.to_vec2()));
}
});
buffers.push(BufferWithTextArea::new(
self.click_anywhere_buffer.1.clone(),
Rect::from_min_size(
Pos2::new(rect.min.x + 4.0, rect.max.y - 8.0),
self.click_anywhere_buffer.0,
),
zoom_view_opacity,
egui_glyphon::glyphon::Color::rgb(255, 255, 255),
ui.ctx(),
));
}
let mut hovered = false;
if self.zoomed {