Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
ximper-welcome
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ximper Linux
ximper-welcome
Commits
1df508a5
Commit
1df508a5
authored
Feb 25, 2023
by
Bilal Elmoussaoui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make use of composite template callbacks
parent
f35f9618
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
31 deletions
+24
-31
paginator.ui
data/resources/ui/paginator.ui
+7
-0
paginator.rs
src/widgets/paginator.rs
+17
-31
No files found.
data/resources/ui/paginator.ui
View file @
1df508a5
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template
class=
"PaginatorWidget"
parent=
"GtkBox"
>
<property
name=
"orientation"
>
vertical
</property>
<child>
<object
class=
"GtkHeaderBar"
>
<property
name=
"show-title-buttons"
>
True
</property>
...
...
@@ -61,9 +62,15 @@
<object
class=
"AdwCarousel"
id=
"carousel"
>
<property
name=
"hexpand"
>
True
</property>
<property
name=
"vexpand"
>
True
</property>
<signal
name=
"notify::position"
handler=
"on_position_notify"
swapped=
"true"
/>
</object>
</child>
</object>
</child>
<child>
<object
class=
"GtkEventControllerKey"
>
<signal
name=
"key-pressed"
handler=
"on_key_pressed"
swapped=
"true"
/>
</object>
</child>
</template>
</interface>
src/widgets/paginator.rs
View file @
1df508a5
use
gtk
::
prelude
::
*
;
use
gtk
::{
gdk
,
glib
::{
self
,
clone
},
subclass
::
prelude
::
*
,
};
use
gtk
::{
gdk
,
glib
,
prelude
::
*
,
subclass
::
prelude
::
*
};
mod
imp
{
use
super
::
*
;
...
...
@@ -33,7 +28,8 @@ mod imp {
type
Interfaces
=
(
gtk
::
Buildable
,);
fn
class_init
(
klass
:
&
mut
Self
::
Class
)
{
Self
::
bind_template
(
klass
);
klass
.bind_template
();
klass
.bind_template_instance_callbacks
();
}
fn
instance_init
(
obj
:
&
glib
::
subclass
::
InitializingObject
<
Self
>
)
{
...
...
@@ -44,30 +40,8 @@ mod imp {
impl
ObjectImpl
for
PaginatorWidget
{
fn
constructed
(
&
self
)
{
self
.parent_constructed
();
let
obj
=
self
.obj
();
let
layout_manager
=
obj
.layout_manager
()
.and_downcast
::
<
gtk
::
BoxLayout
>
()
.unwrap
();
layout_manager
.set_orientation
(
gtk
::
Orientation
::
Vertical
);
self
.carousel
.set_scroll_params
(
&
adw
::
SpringParams
::
new
(
1.0
,
0.5
,
300.0
));
self
.carousel
.connect_position_notify
(
clone!
(
@
weak
obj
=>
move
|
_
|
{
obj
.update_position
();
}));
let
controller
=
gtk
::
EventControllerKey
::
new
();
controller
.connect_key_pressed
(
clone!
(
@
weak
obj
=>
@
default
-
return
gtk
::
Inhibit
(
true
),
move
|
_controller
,
keyval
,
_keycode
,
_state
|
{
if
keyval
==
gdk
::
Key
::
Right
{
obj
.try_next
();
}
else
if
keyval
==
gdk
::
Key
::
Left
{
obj
.try_previous
();
}
gtk
::
Inhibit
(
false
)
}));
obj
.add_controller
(
controller
);
}
}
impl
WidgetImpl
for
PaginatorWidget
{}
...
...
@@ -90,6 +64,7 @@ glib::wrapper! {
@
implements
gtk
::
Buildable
;
}
#[gtk
::
template_callbacks]
impl
PaginatorWidget
{
pub
fn
try_next
(
&
self
)
->
Option
<
()
>
{
let
imp
=
self
.imp
();
...
...
@@ -116,10 +91,21 @@ impl PaginatorWidget {
imp
.carousel
.insert
(
&
page
,
page_nr
as
i32
);
imp
.pages
.borrow_mut
()
.push
(
page
.upcast
());
self
.update_position
();
self
.on_position_notify
();
}
#[template_callback]
fn
on_key_pressed
(
&
self
,
keyval
:
gdk
::
Key
)
->
gtk
::
Inhibit
{
if
keyval
==
gdk
::
Key
::
Right
{
self
.try_next
();
}
else
if
keyval
==
gdk
::
Key
::
Left
{
self
.try_previous
();
}
gtk
::
Inhibit
(
false
)
}
fn
update_position
(
&
self
)
{
#[template_callback]
fn
on_position_notify
(
&
self
)
{
let
imp
=
self
.imp
();
let
position
=
imp
.carousel
.position
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment