feat: dynamic image measures based on screen size (see #27)

This commit is contained in:
Bnyro 2023-09-14 19:16:33 +02:00
parent 8e9cde2f97
commit 5d47f33661
2 changed files with 22 additions and 2 deletions

View File

@ -27,6 +27,7 @@ pub struct PostPage {
#[allow(dead_code)]
create_comment_dialog: Controller<EditorDialog>,
voting_row: Controller<VotingRowModel>,
thumbnail_height: i32,
}
#[derive(Debug)]
@ -65,7 +66,8 @@ impl SimpleComponent for PostPage {
#[local_ref]
image -> gtk::Box {
set_height_request: 400,
#[watch]
set_height_request: model.thumbnail_height,
set_margin_bottom: 20,
set_margin_top: 20,
#[watch]
@ -218,6 +220,7 @@ impl SimpleComponent for PostPage {
let voting_row = VotingRowModel::builder()
.launch(VotingStats::default())
.detach();
let model = PostPage {
info: init,
image,
@ -226,6 +229,7 @@ impl SimpleComponent for PostPage {
community_avatar,
create_comment_dialog: dialog,
voting_row,
thumbnail_height: 400,
};
let image = model.image.widget();
@ -241,6 +245,13 @@ impl SimpleComponent for PostPage {
fn update(&mut self, message: Self::Input, sender: ComponentSender<Self>) {
match message {
PostPageInput::UpdatePost(post) => {
match relm4::main_application().active_window() {
Some(window) => {
self.thumbnail_height = window.allocated_width() / 2;
}
None => unreachable!(),
}
self.info = post.clone();
self.image

View File

@ -15,6 +15,7 @@ pub struct PostRow {
community_image: Controller<WebImage>,
thumbnail: Controller<WebImage>,
voting_row: Controller<VotingRowModel>,
image_size: i32,
}
#[derive(Debug)]
@ -49,7 +50,7 @@ impl FactoryComponent for PostRow {
#[local_ref]
thumbnail -> gtk::Box {
set_visible: self.post.post.thumbnail_url.is_some(),
set_size_request: (180, 180),
set_size_request: (self.image_size, self.image_size),
set_margin_start: 10,
set_margin_end: 10,
set_hexpand: false,
@ -168,6 +169,7 @@ impl FactoryComponent for PostRow {
community_image,
voting_row,
thumbnail,
image_size: 1500,
}
}
@ -178,6 +180,13 @@ impl FactoryComponent for PostRow {
_returned_widget: &<Self::ParentWidget as relm4::factory::FactoryView>::ReturnedWidget,
sender: FactorySender<Self>,
) -> Self::Widgets {
match root.widget_ref().toplevel_window() {
Some(window) => {
self.image_size = window.allocated_width() / 8;
}
None => unreachable!(),
}
println!("size {}", self.image_size);
let thumbnail = self.thumbnail.widget();
let author_image = self.author_image.widget();
let community_image = self.community_image.widget();