2022-01-24 20:20:33 +01:00
|
|
|
// Copyright 2022 System76 <info@system76.com>
|
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
|
|
|
|
|
use ccs::*;
|
|
|
|
|
use gtk::prelude::*;
|
|
|
|
|
|
|
|
|
|
pub enum InfoButtonInput {
|
|
|
|
|
SetDescription(String),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub enum InfoButtonOutput {
|
|
|
|
|
Clicked,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
component! {
|
|
|
|
|
#[derive(Default)]
|
2022-01-26 11:30:58 +01:00
|
|
|
pub struct InfoButton {
|
2022-01-24 20:20:33 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-26 11:30:58 +01:00
|
|
|
pub struct InfoButtonWidgets {
|
2022-01-24 20:20:33 +01:00
|
|
|
description: gtk::Label,
|
|
|
|
|
}
|
2022-01-31 15:55:55 +01:00
|
|
|
|
2022-01-24 20:20:33 +01:00
|
|
|
type Input = InfoButtonInput;
|
|
|
|
|
type Output = InfoButtonOutput;
|
|
|
|
|
|
2022-01-26 11:30:58 +01:00
|
|
|
type Root = gtk::Box {
|
2022-01-24 20:20:33 +01:00
|
|
|
ccs::view! {
|
|
|
|
|
root = gtk::Box {
|
|
|
|
|
set_orientation: gtk::Orientation::Horizontal,
|
|
|
|
|
set_margin_start: 20,
|
|
|
|
|
set_margin_end: 20,
|
|
|
|
|
set_margin_top: 8,
|
|
|
|
|
set_margin_bottom: 8,
|
|
|
|
|
set_spacing: 24,
|
2022-01-26 11:30:58 +01:00
|
|
|
}
|
|
|
|
|
}
|
2022-01-24 20:20:33 +01:00
|
|
|
|
2022-01-26 11:30:58 +01:00
|
|
|
root
|
|
|
|
|
};
|
2022-01-24 20:20:33 +01:00
|
|
|
|
2022-01-31 15:55:55 +01:00
|
|
|
fn init(args: (String, String, gtk::SizeGroup), root, _input, output) {
|
2022-01-26 11:30:58 +01:00
|
|
|
let (desc, button_label, sg) = args;
|
2022-01-24 20:20:33 +01:00
|
|
|
|
2022-01-26 11:30:58 +01:00
|
|
|
ccs::view! {
|
|
|
|
|
description = gtk::Label {
|
|
|
|
|
set_label: &desc,
|
|
|
|
|
set_halign: gtk::Align::Start,
|
|
|
|
|
set_hexpand: true,
|
|
|
|
|
set_valign: gtk::Align::Center,
|
|
|
|
|
set_ellipsize: gtk::pango::EllipsizeMode::End,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ccs::view! {
|
|
|
|
|
button = gtk::Button {
|
|
|
|
|
set_label: &button_label,
|
|
|
|
|
|
|
|
|
|
connect_clicked(output) => move |_| {
|
|
|
|
|
let _ = output.send(InfoButtonOutput::Clicked);
|
2022-01-24 20:20:33 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-26 11:30:58 +01:00
|
|
|
root.append(&description);
|
|
|
|
|
root.append(&button);
|
|
|
|
|
|
2022-01-24 20:20:33 +01:00
|
|
|
sg.add_widget(&button);
|
|
|
|
|
|
2022-01-31 15:55:55 +01:00
|
|
|
Fuselage {
|
2022-01-26 11:30:58 +01:00
|
|
|
model: InfoButton {},
|
|
|
|
|
widgets: InfoButtonWidgets { description },
|
|
|
|
|
}
|
2022-01-24 20:20:33 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-31 15:55:55 +01:00
|
|
|
fn update(&mut self, widgets, message, _input, _output) {
|
2022-01-24 20:20:33 +01:00
|
|
|
match message {
|
|
|
|
|
InfoButtonInput::SetDescription(value) => {
|
2022-01-31 15:55:55 +01:00
|
|
|
widgets.description.set_text(&value);
|
2022-01-24 20:20:33 +01:00
|
|
|
}
|
|
|
|
|
}
|
2022-01-31 15:55:55 +01:00
|
|
|
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn command(_message: (), _input) {
|
|
|
|
|
|
2022-01-24 20:20:33 +01:00
|
|
|
}
|
|
|
|
|
}
|