-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
216 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<interface> | ||
<template class="EpisodeRow" parent="GtkBox"> | ||
<child> | ||
<object class="GtkPicture" id="image"> | ||
</object> | ||
</child> | ||
<child> | ||
<object class="GtkLabel" id="content_label"> | ||
</object> | ||
</child> | ||
</template> | ||
</interface> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
mod provider; | ||
mod image; | ||
mod network; | ||
mod new_dropsel; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
mod imp { | ||
use std::cell::RefCell; | ||
|
||
use glib::Properties; | ||
use gtk::glib; | ||
use gtk::prelude::*; | ||
use gtk::subclass::prelude::*; | ||
|
||
use super::TaskData; | ||
|
||
// ANCHOR: struct_and_subclass | ||
// Object holding the state | ||
#[derive(Properties, Default)] | ||
#[properties(wrapper_type = super::EpisodeObject)] | ||
pub struct EpisodeObject { | ||
#[property(name = "imageid", get, set, type = String, member = imageid)] | ||
#[property(name = "label", get, set, type = String, member = label)] | ||
pub data: RefCell<TaskData>, | ||
} | ||
|
||
// The central trait for subclassing a GObject | ||
#[glib::object_subclass] | ||
impl ObjectSubclass for EpisodeObject { | ||
const NAME: &'static str = "EpisodeObject"; | ||
type Type = super::EpisodeObject; | ||
} | ||
|
||
// Trait shared by all GObjects | ||
#[glib::derived_properties] | ||
impl ObjectImpl for EpisodeObject {} | ||
// ANCHOR_END: struct_and_subclass | ||
} | ||
|
||
use glib::Object; | ||
use gtk::glib; | ||
|
||
// ANCHOR: glib_wrapper_and_new | ||
glib::wrapper! { | ||
pub struct EpisodeObject(ObjectSubclass<imp::EpisodeObject>); | ||
} | ||
|
||
impl EpisodeObject { | ||
pub fn new(imageid: bool, label: String) -> Self { | ||
Object::builder() | ||
.property("imageid", imageid) | ||
.property("label", label) | ||
.build() | ||
} | ||
} | ||
// ANCHOR_END: glib_wrapper_and_new | ||
|
||
// ANCHOR: task_data | ||
#[derive(Default)] | ||
pub struct TaskData { | ||
pub imageid: String, | ||
pub label: String, | ||
} | ||
// ANCHOR: task_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod episoderowitem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
use glib::Object; | ||
use gtk::prelude::*; | ||
use gtk::subclass::prelude::*; | ||
use gtk::{glib, pango}; | ||
use pango::{AttrInt, AttrList}; | ||
|
||
use crate::ui::provider::episoderowitem::EpisodeObject; | ||
|
||
mod imp { | ||
use std::cell::RefCell; | ||
|
||
use glib::Binding; | ||
use gtk::subclass::prelude::*; | ||
use gtk::{glib, CheckButton, CompositeTemplate, Label, Picture}; | ||
|
||
// Object holding the state | ||
#[derive(Default, CompositeTemplate)] | ||
#[template(resource = "/moe/tsukimi/episoderow.ui")] | ||
pub struct EpisodeRow { | ||
#[template_child] | ||
pub image: TemplateChild<Picture>, | ||
#[template_child] | ||
pub content_label: TemplateChild<Label>, | ||
// Vector holding the bindings to properties of `TaskObject` | ||
pub bindings: RefCell<Vec<Binding>>, | ||
} | ||
|
||
// The central trait for subclassing a GObject | ||
#[glib::object_subclass] | ||
impl ObjectSubclass for EpisodeRow { | ||
// `NAME` needs to match `class` attribute of template | ||
const NAME: &'static str = "EpisodeRow"; | ||
type Type = super::EpisodeRow; | ||
type ParentType = gtk::Box; | ||
|
||
fn class_init(klass: &mut Self::Class) { | ||
klass.bind_template(); | ||
} | ||
|
||
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) { | ||
obj.init_template(); | ||
} | ||
} | ||
|
||
// Trait shared by all GObjects | ||
impl ObjectImpl for EpisodeRow {} | ||
|
||
// Trait shared by all widgets | ||
impl WidgetImpl for EpisodeRow {} | ||
|
||
// Trait shared by all boxes | ||
impl BoxImpl for EpisodeRow {} | ||
} | ||
|
||
glib::wrapper! { | ||
pub struct EpisodeRow(ObjectSubclass<imp::EpisodeRow>) | ||
@extends gtk::Box, gtk::Widget, | ||
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable; | ||
} | ||
|
||
impl Default for EpisodeRow { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl EpisodeRow { | ||
pub fn new() -> Self { | ||
Object::builder().build() | ||
} | ||
|
||
pub fn bind(&self, episode_object: &EpisodeObject) { | ||
// Get state | ||
let image = self.imp().image.get(); | ||
let content_label = self.imp().content_label.get(); | ||
let mut bindings = self.imp().bindings.borrow_mut(); | ||
|
||
// Bind `task_object.completed` to `task_row.completed_button.active` | ||
let image_binding = episode_object | ||
.bind_property("completed", &image, "active") | ||
.bidirectional() | ||
.sync_create() | ||
.build(); | ||
// Save binding | ||
bindings.push(image_binding); | ||
|
||
// Bind `task_object.content` to `task_row.content_label.label` | ||
let content_label_binding = episode_object | ||
.bind_property("content", &content_label, "label") | ||
.sync_create() | ||
.build(); | ||
// Save binding | ||
bindings.push(content_label_binding); | ||
} | ||
|
||
pub fn unbind(&self) { | ||
// Unbind all stored bindings | ||
for binding in self.imp().bindings.borrow_mut().drain(..) { | ||
binding.unbind(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters