From dd12f31bf504675abadb0e2c0cdb540597fc9220 Mon Sep 17 00:00:00 2001 From: Vika Date: Sun, 25 Aug 2024 19:26:16 +0300 Subject: Style changes to work better with the default theme Yes, I'm stupid and I'm developing under a custom theme --- src/components/post_editor.rs | 44 +++++++++++++++++++++++++++---------------- src/components/tag_pill.rs | 17 +++++++++++++---- 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/src/components/post_editor.rs b/src/components/post_editor.rs index fe69ac7..86bd91d 100644 --- a/src/components/post_editor.rs +++ b/src/components/post_editor.rs @@ -139,10 +139,9 @@ impl Component for Post #[name = "name_label"] gtk::Label { set_markup: "Name", - set_margin_vertical: 10, set_margin_horizontal: 10, set_halign: gtk::Align::Start, - set_valign: gtk::Align::Start, + set_valign: gtk::Align::Center, }, #[name = "name_field"] gtk::Entry { @@ -155,10 +154,9 @@ impl Component for Post #[name = "summary_label"] gtk::Label { set_markup: "Summary", - set_margin_vertical: 10, set_margin_horizontal: 10, set_halign: gtk::Align::Start, - set_valign: gtk::Align::Start, + set_valign: gtk::Align::Center, }, #[name = "summary_field"] gtk::Box { @@ -178,17 +176,15 @@ impl Component for Post #[name = "tag_label"] gtk::Label { set_markup: "Tags", - set_margin_vertical: 10, set_margin_horizontal: 10, set_halign: gtk::Align::Start, - set_valign: gtk::Align::Start, + set_valign: gtk::Align::Center, }, #[name = "tag_holder"] gtk::Box { set_hexpand: true, set_orientation: gtk::Orientation::Vertical, set_spacing: 5, - set_height_request: 36, gtk::Box { add_css_class: "linked", @@ -199,23 +195,29 @@ impl Component for Post set_hexpand: true, set_width_request: 200, set_buffer: &model.pending_tag_buffer, + connect_activate => Self::Input::AddTagFromBuffer, #[track = "model.changed(Self::sending())"] set_sensitive: !model.sending, }, gtk::Button { - set_icon_name: "plus-symbolic", + set_icon_name: "list-add-symbolic", add_css_class: "suggested-action", connect_clicked => Self::Input::AddTagFromBuffer, } }, + }, - gtk::ScrolledWindow { - gtk::Viewport { - set_scroll_to_focus: true, + #[name = "tag_viewport"] + gtk::ScrolledWindow { + set_height_request: 32, + set_valign: gtk::Align::Center, - #[wrap(Some)] - set_child = model.tags.widget(), - } + gtk::Viewport { + set_scroll_to_focus: true, + set_valign: gtk::Align::Center, + + #[wrap(Some)] + set_child = model.tags.widget(), } }, @@ -395,6 +397,7 @@ impl Component for Post model.visibility = post.visibility; } + let prev_layout = widgets.content.layout_manager().unwrap(); let layout = &model.wide_layout; widgets.content.set_layout_manager(Some(layout.clone())); layout.set_column_homogeneous(false); @@ -402,13 +405,15 @@ impl Component for Post enum Row<'a> { TwoColumn(&'a gtk::Label, &'a gtk::Widget), - Span(&'a gtk::Widget) + Span(&'a gtk::Widget), + SecondColumn(&'a gtk::Widget) } for (row, content) in [ Row::TwoColumn(&widgets.name_label, widgets.name_field.upcast_ref::()), Row::TwoColumn(&widgets.summary_label, widgets.summary_field.upcast_ref::()), Row::TwoColumn(&widgets.tag_label, widgets.tag_holder.upcast_ref::()), + Row::SecondColumn(widgets.tag_viewport.upcast_ref::()), Row::TwoColumn(&widgets.content_label, widgets.content_textarea_wrapper.upcast_ref::()), Row::Span(widgets.misc_prop_wrapper.upcast_ref::()), ].into_iter().enumerate() { @@ -432,11 +437,18 @@ impl Component for Post .unwrap(); widget_layout.set_row(row as i32); widget_layout.set_column_span(2); + }, + Row::SecondColumn(widget) => { + let widget_layout = layout.layout_child(widget) + .downcast::() + .unwrap(); + widget_layout.set_row(row as i32); + widget_layout.set_column(1); } } } - widgets.content.set_layout_manager(Some(model.narrow_layout.clone())); + widgets.content.set_layout_manager(Some(prev_layout)); ComponentParts { model, widgets } } diff --git a/src/components/tag_pill.rs b/src/components/tag_pill.rs index 4947540..7579c0e 100644 --- a/src/components/tag_pill.rs +++ b/src/components/tag_pill.rs @@ -30,13 +30,22 @@ impl FactoryComponent for TagPill { relm4::view! { root = gtk::Box { #[iterate] - add_css_class: &["pill", "frame"], + add_css_class: &["pill", "frame", "tag-pill"], inline_css: "border-radius: 48px", set_spacing: 6, set_height_request: 32, + set_valign: gtk::Align::Center, } } + use gtk::prelude::StyleContextExt; + let css = gtk::CssProvider::new(); + css.load_from_bytes(&glib::Bytes::from_static(b".tag-pill button { + min-height: 30px; + min-width: 30px; +}")); + + root.style_context().add_provider(&css, gtk::STYLE_PROVIDER_PRIORITY_APPLICATION + 2); root } @@ -51,12 +60,12 @@ impl FactoryComponent for TagPill { label = gtk::Label { set_text: &self.0, set_margin_horizontal: 6, - set_margin_start: 12, + set_margin_start: 16, }, button = gtk::Button { #[iterate] - add_css_class: &["destructive-action", "flat", "circular"], - set_icon_name: "close-symbolic", + add_css_class: &["destructive-action", "circular"], + set_icon_name: "window-close-symbolic", connect_clicked[sender, index] => move |_| { let _ = sender.output(TagPillDelete(index.clone())); -- cgit 1.4.1