Add CSS support and tweak styles a bit

This commit is contained in:
Vivianne 2023-06-15 01:04:31 -07:00
parent c656ea5311
commit b09a392351
2 changed files with 14 additions and 2 deletions

4
css/style.css Normal file
View file

@ -0,0 +1,4 @@
.sample-list-view row {
margin: 2px 5px;
border-radius: 7px;
}

View file

@ -1,4 +1,5 @@
use diesel::prelude::*; use diesel::prelude::*;
use gtk::gdk::Display;
use gtk::glib::BoxedAnyObject; use gtk::glib::BoxedAnyObject;
use gtk::prelude::*; use gtk::prelude::*;
use relm4::{factory::FactoryVecDeque, prelude::*}; use relm4::{factory::FactoryVecDeque, prelude::*};
@ -53,12 +54,11 @@ impl SimpleComponent for AppModel {
}, },
gtk::Box { gtk::Box {
set_orientation: gtk::Orientation::Vertical, set_orientation: gtk::Orientation::Vertical,
set_spacing: 5,
set_margin_all: 5,
set_hexpand: true, set_hexpand: true,
gtk::ScrolledWindow { gtk::ScrolledWindow {
set_vexpand: true, set_vexpand: true,
set_css_classes: &["sample-list-view"],
gtk::ColumnView { gtk::ColumnView {
set_model: Some(&model.samples), set_model: Some(&model.samples),
append_column = &gtk::ColumnViewColumn { append_column = &gtk::ColumnViewColumn {
@ -84,6 +84,7 @@ impl SimpleComponent for AppModel {
gtk::Box { gtk::Box {
set_height_request: 100, set_height_request: 100,
set_margin_all: 5,
gtk::Label { gtk::Label {
#[watch] #[watch]
set_label: "Sample playback", set_label: "Sample playback",
@ -178,8 +179,15 @@ impl SimpleComponent for AppModel {
} }
} }
fn load_css() {
let provider = gtk::CssProvider::new();
provider.load_from_data(include_str!("../css/style.css"));
gtk::style_context_add_provider_for_display(&Display::default().expect("Could not connect to a display."), &provider, gtk::STYLE_PROVIDER_PRIORITY_APPLICATION);
}
fn main() { fn main() {
let app = RelmApp::new("relm.test.simple_manual"); let app = RelmApp::new("relm.test.simple_manual");
relm4::main_application().connect_startup(|_| load_css());
relm4_icons::initialize_icons(); relm4_icons::initialize_icons();
app.run::<AppModel>(()); app.run::<AppModel>(());
} }