Skip to content

Commit

Permalink
feature: add first,previous,next,last selections in item page
Browse files Browse the repository at this point in the history
  • Loading branch information
tsukinaha committed Mar 27, 2024
1 parent 4052f85 commit 346fbe3
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 12 deletions.
55 changes: 43 additions & 12 deletions resources/ui/item.ui
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,64 @@
</child>
<child type="overlay">
<object class="GtkBox" id="logobox">
<property name="margin-start">30</property>
<property name="margin-top">15</property>
<property name="height-request">150</property>
<property name="valign">start</property>
<property name="halign">start</property>
<property name="margin-start">30</property>
<property name="margin-top">15</property>
<property name="height-request">150</property>
<property name="valign">start</property>
<property name="halign">start</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkBox">
<property name="orientation">horizontal</property>
<property name="spacing">6</property>
<property name="hexpand">true</property>
<child>
<object class="GtkDropDown" id="seasonlist">
</object>
</child>
<child>
<object class="GtkToggleButton" id="go-first">
<property name="halign">end</property>
<property name="icon-name">go-first-symbolic</property>
<property name="action-name">item.first</property>
<property name="hexpand">true</property>
</object>
</child>
<child>
<object class="GtkToggleButton" id="go-previous-symbolic">
<property name="halign">end</property>
<property name="icon-name">go-previous-symbolic</property>
<property name="action-name">item.previous</property>
</object>
</child>
<child>
<object class="GtkToggleButton" id="go-next-symbolic">
<property name="halign">end</property>
<property name="icon-name">go-next-symbolic</property>
<property name="action-name">item.next</property>
</object>
</child>
<child>
<object class="GtkToggleButton" id="go-last-symbolic">
<property name="halign">end</property>
<property name="icon-name">go-last-symbolic</property>
<property name="action-name">item.last</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="vscrollbar-policy">never</property>
<property name="valign">fill</property>
<property name="margin-bottom">3</property>
<object class="GtkRevealer" id="itemrevealer">
<property name="transition-duration">700</property>
<property name="reveal-child">False</property>
<child>
<object class="GtkRevealer" id="itemrevealer">
<property name="transition-duration">700</property>
<property name="reveal-child">False</property>
<object class="GtkScrolledWindow">
<property name="vscrollbar-policy">never</property>
<property name="valign">fill</property>
<property name="margin-bottom">3</property>
<child>
<object class="GtkListView" id="itemlist">
<property name="orientation">horizontal</property>
Expand Down
42 changes: 42 additions & 0 deletions src/ui/widgets/item.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use glib::Object;
use gtk::prelude::*;
use gtk::{gio, glib};
use adw::subclass::prelude::*;

mod imp {
use crate::ui::network::{self, runtime};
use adw::subclass::prelude::*;
Expand Down Expand Up @@ -45,6 +47,18 @@ mod imp {

fn class_init(klass: &mut Self::Class) {
klass.bind_template();
klass.install_action("item.first", None, move |window, _action, _parameter| {
window.itemfirst();
});
klass.install_action("item.previous", None, move |window, _action, _parameter| {
window.itemprevious();
});
klass.install_action("item.next", None, move |window, _action, _parameter| {
window.itemnext();
});
klass.install_action("item.last", None, move |window, _action, _parameter| {
window.itemlast();
});
}

fn instance_init(obj: &InitializingObject<Self>) {
Expand Down Expand Up @@ -267,4 +281,32 @@ impl ItemPage {
osd.append(&logo);
osd.add_css_class("logo");
}

pub fn itemfirst(&self) {
let imp = self.imp();
imp.itemlist.scroll_to(0, gtk::ListScrollFlags::SELECT, None);
}

pub fn itemprevious(&self) {
let imp = self.imp();
let selection = &imp.selection;
let position = selection.selected();
if position > 0 {
imp.itemlist.scroll_to(position - 1, gtk::ListScrollFlags::SELECT, None);
}
}

pub fn itemnext(&self) {
let imp = self.imp();
let selection = &imp.selection;
let position = selection.selected();
if position < imp.itemlist.model().unwrap().n_items() {
imp.itemlist.scroll_to(position + 1, gtk::ListScrollFlags::SELECT, None);
}
}

pub fn itemlast(&self) {
let imp = self.imp();
imp.itemlist.scroll_to(imp.itemlist.model().unwrap().n_items() - 1, gtk::ListScrollFlags::SELECT, None);
}
}

0 comments on commit 346fbe3

Please sign in to comment.