Skip to content

Commit

Permalink
fix(gtk): Set margins for changelogs in dropdown
Browse files Browse the repository at this point in the history
Closes #18
  • Loading branch information
mmstick committed Aug 13, 2019
1 parent 08fc93c commit 2f400dd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 7 additions & 1 deletion gtk/src/changelog.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use gtk::prelude::*;
use std::borrow::Cow;

pub fn generate_widget<I, S>(changelog: I) -> gtk::Box
pub fn generate_widget<I, S>(changelog: I, pad: bool) -> gtk::Box
where
S: AsRef<str>,
I: Iterator<Item = (S, S)>,
Expand All @@ -22,18 +22,24 @@ where
// Even though we set a max width of chars, this will be ignored by GTK as the
// parent is resized.

let margin = if pad { 48 } else { 0 };

let version = gtk::LabelBuilder::new()
.label(&*format!("<b>{}</b>", version.as_ref()))
.use_markup(true)
.xalign(0.0)
.max_width_chars(40)
.margin_start(margin)
.margin_end(margin)
.build();

let changelog = gtk::LabelBuilder::new()
.label(&*markdown)
.wrap(true)
.xalign(0.0)
.max_width_chars(40)
.margin_start(margin)
.margin_end(margin)
.build();

changelog_entries.add(&cascade! {
Expand Down
2 changes: 1 addition & 1 deletion gtk/src/dialogs/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ impl FirmwareUpdateDialog {
upgradeable: bool,
needs_reboot: bool,
) -> Self {
let changelog_entries = crate::changelog::generate_widget(changelog);
let changelog_entries = crate::changelog::generate_widget(changelog, false);

let header_text =
["Firmware version ", version.trim(), " is available. Fixes and features include:"]
Expand Down
6 changes: 3 additions & 3 deletions gtk/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl State {
.rev()
.map(|release| (release.version.as_ref(), release.description.as_ref()));

crate::changelog::generate_widget(log_entries).upcast::<gtk::Container>()
crate::changelog::generate_widget(log_entries, true).upcast::<gtk::Container>()
});
});

Expand Down Expand Up @@ -223,7 +223,7 @@ impl State {
)
});

crate::changelog::generate_widget(log_entries).upcast::<gtk::Container>()
crate::changelog::generate_widget(log_entries, true).upcast::<gtk::Container>()
})
});

Expand Down Expand Up @@ -273,7 +273,7 @@ impl State {
let sender = self.ui_sender.clone();
widget.connect_clicked(move |revealer| {
reveal(&revealer, &sender, entity, || {
crate::changelog::generate_widget(iter::once((info.latest.as_ref(), "")))
crate::changelog::generate_widget(iter::once((info.latest.as_ref(), "")), true)
.upcast::<gtk::Container>()
});
});
Expand Down

0 comments on commit 2f400dd

Please sign in to comment.