Skip to content

Commit

Permalink
label: add support for pango markup and justification
Browse files Browse the repository at this point in the history
  • Loading branch information
bvr-yr committed Mar 2, 2024
1 parent b20a707 commit b783a39
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ struct WButton {
action: String,
text: String,
keybind: String,
#[serde(default = "default_justify")]
justify: String,
#[serde(default = "default_width")]
width: f32,
#[serde(default = "default_height")]
Expand All @@ -30,6 +32,10 @@ struct WButton {
circular: bool,
}

fn default_justify() -> String {
String::from("center")
}

fn default_width() -> f32 {
0.5
}
Expand Down Expand Up @@ -230,6 +236,14 @@ fn app_main(config: &Arc<AppConfig>, app: &Application) {
bttn.text.to_owned()
};

let justify = match bttn.justify.as_str() {
"center" => gtk::Justification::Center,
"fill" => gtk::Justification::Fill,
"left" => gtk::Justification::Left,
"right" => gtk::Justification::Right,
_ => gtk::Justification::Center
};

let button = gtk::Button::builder()
.label(&label)
.name(&bttn.label)
Expand All @@ -241,6 +255,8 @@ fn app_main(config: &Arc<AppConfig>, app: &Application) {
if let Some(label) = label.downcast_ref::<Label>() {
label.set_xalign(bttn.width);
label.set_yalign(bttn.height);
label.set_use_markup(true);
label.set_justify(justify);
}
}

Expand Down

0 comments on commit b783a39

Please sign in to comment.