add a button to the image-page widget

parent f5b429d9
......@@ -19,12 +19,14 @@
<property name="margin-top">12</property>
<property name="margin-start">12</property>
<property name="margin-end">12</property>
<child>
<object class="GtkPicture" id="picture">
<property name="can-shrink">false</property>
<property name="content-fit">contain</property>
</object>
</child>
<child>
<object class="GtkLabel" id="head_label">
<property name="label" bind-source="ImagePageWidget" bind-property="head" />
......@@ -36,6 +38,7 @@
</style>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label" bind-source="ImagePageWidget" bind-property="body" />
......@@ -49,6 +52,34 @@
</style>
</object>
</child>
<child>
<object class="GtkButton" id="action_button">
<property name="visible">false</property>
<property name="halign">center</property>
<style>
<class name="suggested-action, pill" />
</style>
<child>
<object class="GtkBox">
<property name="orientation">horizontal</property>
<property name="spacing">6</property>
<child>
<object class="GtkImage" id="button_icon_widget">
<property name="visible">false</property>
<property name="icon-name" bind-source="ImagePageWidget" bind-property="button-icon" />
<property name="pixel-size">16</property>
</object>
</child>
<child>
<object class="GtkLabel" id="button_label_widget">
<property name="label" bind-source="ImagePageWidget" bind-property="button-label" />
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</template>
......
......@@ -9,6 +9,8 @@
<object class="ImagePageWidget" id="welcome_page">
<property name="resource-uri">/ru/ximperlinux/Welcome/base/welcome.svg</property>
<property name="head" translatable="yes">Welcome to GNOME</property>
<property name="button-label" translatable="yes">Open Wiki</property>
<property name="button-url">https://wiki.ximperlinux.ru</property>
</object>
</child>
<child>
......
......@@ -9,6 +9,8 @@
<object class="ImagePageWidget" id="welcome_page">
<property name="resource-uri">/ru/ximperlinux/Welcome/base/welcome.svg</property>
<property name="head" translatable="yes">Welcome to Hyprland</property>
<property name="button-label" translatable="yes">Open Wiki</property>
<property name="button-url">https://wiki.ximperlinux.ru</property>
</object>
</child>
<child>
......
use gtk::{glib, prelude::*, subclass::prelude::*};
use gtk::{gio, glib, prelude::*, subclass::prelude::*};
mod imp {
use std::cell::{OnceCell, RefCell};
use super::*;
#[derive(Debug, Default, glib::Properties, gtk::CompositeTemplate)]
#[properties(wrapper_type = super::ImagePageWidget)]
#[template(resource = "/ru/ximperlinux/Welcome/ui/image-page.ui")]
pub struct ImagePageWidget {
#[property(get, set= Self::set_resource_uri, construct_only)]
#[property(get, set = Self::set_resource_uri, construct_only)]
pub(super) resource_uri: OnceCell<String>,
#[property(get, set, construct_only)]
pub(super) head: OnceCell<String>,
#[property(get, set, construct)]
pub(super) body: RefCell<Option<String>>,
#[property(get, set, construct)]
pub(super) button_label: RefCell<Option<String>>,
#[property(get, set, construct)]
pub(super) button_icon: RefCell<Option<String>>,
#[property(get, set, construct)]
pub(super) button_url: RefCell<Option<String>>,
#[template_child]
pub(super) picture: TemplateChild<gtk::Picture>,
#[template_child]
pub(super) container: TemplateChild<gtk::Box>,
#[template_child]
pub(super) action_button: TemplateChild<gtk::Button>,
#[template_child]
pub(super) button_label_widget: TemplateChild<gtk::Label>,
#[template_child]
pub(super) button_icon_widget: TemplateChild<gtk::Image>,
}
#[glib::object_subclass]
......@@ -28,9 +40,10 @@ mod imp {
type Type = super::ImagePageWidget;
fn class_init(klass: &mut Self::Class) {
klass.set_layout_manager_type::<adw::ClampLayout>();
klass.bind_template();
klass.set_layout_manager_type::<adw::ClampLayout>();
}
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
obj.init_template();
}
......@@ -38,10 +51,31 @@ mod imp {
#[glib::derived_properties]
impl ObjectImpl for ImagePageWidget {
fn constructed(&self) {
if let Some(label) = self.button_label.borrow().clone() {
self.button_label_widget.set_label(&label);
self.action_button.set_visible(true);
}
if let Some(icon_name) = self.button_icon.borrow().as_ref() {
let button_icon_widget = self.button_icon_widget.get();
button_icon_widget.set_visible(true);
button_icon_widget.set_icon_name(Some(&icon_name));
}
if let Some(url) = self.button_url.borrow().clone() {
let button = self.action_button.get();
button.connect_clicked(move |_| {
let _ = gio::AppInfo::launch_default_for_uri(&url, None::<&gio::AppLaunchContext>);
});
}
}
fn dispose(&self) {
self.container.unparent();
}
}
impl WidgetImpl for ImagePageWidget {}
impl ImagePageWidget {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment