Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
636 changes: 636 additions & 0 deletions demo/src/window/group/group.blp

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions demo/src/window/group/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use adw::subclass::prelude::*;
use gtk::glib;

mod imp {
use super::*;

#[derive(Debug, Default, gtk::CompositeTemplate)]
#[template(file = "src/window/group/group.blp")]
pub struct GroupPage;

#[glib::object_subclass]
impl ObjectSubclass for GroupPage {
const NAME: &'static str = "OriDemoGroupPage";
type Type = super::GroupPage;
type ParentType = adw::Bin;

fn class_init(klass: &mut Self::Class) {
klass.bind_template();
}

fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
obj.init_template();
}
}

impl ObjectImpl for GroupPage {}
impl WidgetImpl for GroupPage {}
impl BinImpl for GroupPage {}
}

glib::wrapper! {
pub struct GroupPage(ObjectSubclass<imp::GroupPage>)
@extends gtk::Widget;
}
34 changes: 30 additions & 4 deletions demo/src/window/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
mod group;
mod loading_indicator;
mod picture_group;
mod shimmer_effect;
mod spoiler;

Expand All @@ -13,8 +15,14 @@ mod imp {
#[derive(Debug, Default, gtk::CompositeTemplate)]
#[template(file = "src/window/window.blp")]
pub struct SpoilerWindow {
#[template_child]
pub(super) leaflet: TemplateChild<adw::Leaflet>,
#[template_child]
pub(super) sidebar: TemplateChild<gtk::Box>,
#[template_child]
pub(super) stack: TemplateChild<gtk::Stack>,
#[template_child]
pub(super) content: TemplateChild<gtk::Box>,
}

#[glib::object_subclass]
Expand All @@ -27,8 +35,11 @@ mod imp {
loading_indicator::LoadingIndicatorPage::static_type();
shimmer_effect::ShimmerEffectPage::static_type();
spoiler::SpoilerPage::static_type();
group::GroupPage::static_type();
picture_group::PictureGroupPage::static_type();

klass.bind_template();
klass.bind_template_callbacks();
}

fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
Expand All @@ -50,6 +61,19 @@ mod imp {
impl ApplicationWindowImpl for SpoilerWindow {}

impl AdwApplicationWindowImpl for SpoilerWindow {}

#[gtk::template_callbacks]
impl SpoilerWindow {
#[template_callback]
pub(super) fn open_sidebar(&self) {
self.leaflet.set_visible_child(&*self.sidebar);
}

#[template_callback]
pub(super) fn open_content(&self) {
self.leaflet.set_visible_child(&*self.content);
}
}
}

glib::wrapper! {
Expand All @@ -63,17 +87,19 @@ impl SpoilerWindow {
let obj: Self = glib::Object::builder().property("application", app).build();

if let Some(name) = page {
let pages: Vec<_> = obj
.imp()
.stack
let imp = obj.imp();
let stack = &*imp.stack;

let pages: Vec<_> = stack
.pages()
.iter::<gtk::StackPage>()
.filter_map(|res| res.ok())
.filter_map(|page| page.name())
.collect();

if pages.iter().any(|n| n == &name) {
obj.imp().stack.set_visible_child_name(&name);
stack.set_visible_child_name(&name);
imp.open_content();
} else {
eprintln!("Page {name} is not available");
eprintln!("Supported pages: {}", pages.join(", "));
Expand Down
68 changes: 68 additions & 0 deletions demo/src/window/picture_group/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use adw::subclass::prelude::*;
use glib::clone;
use gtk::{gdk, glib};

mod imp {

use super::*;

#[derive(Debug, Default, gtk::CompositeTemplate)]
#[template(file = "src/window/picture_group/picture_group.blp")]
pub struct PictureGroupPage {
#[template_child]
pub(super) group: TemplateChild<ori::Group>,
#[template_child]
pub(super) drop_target: TemplateChild<gtk::DropTarget>,
}

#[glib::object_subclass]
impl ObjectSubclass for PictureGroupPage {
const NAME: &'static str = "OriDemoPictureGroupPage";
type Type = super::PictureGroupPage;
type ParentType = adw::Bin;

fn class_init(klass: &mut Self::Class) {
klass.bind_template();
}

fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
obj.init_template();
}
}

impl ObjectImpl for PictureGroupPage {
fn constructed(&self) {
self.parent_constructed();

self.drop_target.connect_drop(
clone!(@to-owned self as imp => @default-return false, move
|_, value, _, _ | {
let Ok(file_list) = value.get::<gdk::FileList>() else { return false; };

let files = file_list.files();

let pictures = files.iter().map(|file| {
gtk::Picture::builder()
.file(file)
.content_fit(gtk::ContentFit::Cover)
.overflow(gtk::Overflow::Hidden)
.css_classes(["card"])
.build()
});

imp.group.replace_children(pictures);

true
}
),
);
}
}
impl WidgetImpl for PictureGroupPage {}
impl BinImpl for PictureGroupPage {}
}

glib::wrapper! {
pub struct PictureGroupPage(ObjectSubclass<imp::PictureGroupPage>)
@extends gtk::Widget;
}
93 changes: 93 additions & 0 deletions demo/src/window/picture_group/picture_group.blp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using Gtk 4.0;
using Adw 1;

template $OriDemoPictureGroupPage: Adw.Bin {
child: Adw.StatusPage {
DropTarget drop_target {
actions: copy;
formats: "GdkFileList";
}

title: "Picture Group";
description: "Drop pictures here";

Adw.Clamp {
child: Box {
orientation: vertical;
spacing: 16;

Adw.SpinRow {
styles [
"card"
]

title: "Spacing";

adjustment: Adjustment spacing_adjustment {
lower: 0;
upper: 16;
step-increment: 1;
};
}

$OriGroup group {
spacing: bind spacing_adjustment.value;

Adw.Bin {
styles [
"card"
]

width-request: 6;
height-request: 5;
}

Adw.Bin {
styles [
"card"
]

width-request: 6;
height-request: 7;
}

Adw.Bin {
styles [
"card"
]

width-request: 8;
height-request: 10;
}

Adw.Bin {
styles [
"card"
]

width-request: 6;
height-request: 7;
}

Adw.Bin {
styles [
"card"
]

width-request: 8;
height-request: 5;
}

Adw.Bin {
styles [
"card"
]

width-request: 6;
height-request: 8;
}
}
};
}
};
}
33 changes: 31 additions & 2 deletions demo/src/window/window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ template $SpoilerWindow : Adw.ApplicationWindow {
hexpand: true;
vexpand: true;

Box {
visible-child: sidebar;

Box sidebar {
orientation: vertical;
vexpand: true;

Expand All @@ -25,6 +27,12 @@ template $SpoilerWindow : Adw.ApplicationWindow {
}

StackSidebar {
GestureClick {
button: 1;

released => $open_content(template);
}

vexpand: true;
width-request: 270;

Expand All @@ -36,11 +44,18 @@ template $SpoilerWindow : Adw.ApplicationWindow {
orientation: vertical;
}

Box {
Box content {
orientation: vertical;
vexpand: true;

Adw.HeaderBar {
[start]
Button {
icon-name: "go-previous-symbolic";
visible: bind leaflet.folded;
clicked => $open_sidebar(template);
}

[title]
Adw.Bin {}

Expand Down Expand Up @@ -81,6 +96,20 @@ template $SpoilerWindow : Adw.ApplicationWindow {

child: $OriDemoShimmerEffectPage {};
}

StackPage {
name: "group";
title: "Group";

child: $OriDemoGroupPage {};
}

StackPage {
name: "picture_group";
title: "Picture Group";

child: $OriDemoPictureGroupPage {};
}
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions origami/src/group/child_iter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use gtk::prelude::*;

pub struct ChildIter {
current: Option<gtk::Widget>,
}

impl Iterator for ChildIter {
type Item = gtk::Widget;

fn next(&mut self) -> Option<Self::Item> {
self.current.take().map(|w| {
self.current = w.next_sibling();
w
})
}
}

pub trait WidgetIterExt: WidgetExt {
fn iter_children(&self) -> ChildIter {
ChildIter {
current: self.first_child(),
}
}
}

impl<T> WidgetIterExt for T where T: WidgetExt {}
Loading