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
aa06f0f6
Commit
aa06f0f6
authored
Dec 31, 2021
by
Bilal Elmoussaoui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
subclass PaginatorWidget
parent
8f181ddc
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
148 additions
and
115 deletions
+148
-115
application.rs
src/application.rs
+2
-2
paginator.rs
src/widgets/paginator.rs
+136
-98
window.rs
src/widgets/window.rs
+10
-15
No files found.
src/application.rs
View file @
aa06f0f6
...
@@ -68,7 +68,7 @@ mod imp {
...
@@ -68,7 +68,7 @@ mod imp {
"next-page"
,
"next-page"
,
clone!
(
@
weak
application
=>
move
|
_
,
_
|
{
clone!
(
@
weak
application
=>
move
|
_
,
_
|
{
let
window
=
application
.window
();
let
window
=
application
.window
();
if
window
.paginator
.
borrow_mut
()
.
try_next
()
.is_none
()
{
if
window
.paginator
.try_next
()
.is_none
()
{
window
.widget
.close
();
window
.widget
.close
();
}
}
}),
}),
...
@@ -79,7 +79,7 @@ mod imp {
...
@@ -79,7 +79,7 @@ mod imp {
"previous-page"
,
"previous-page"
,
clone!
(
@
weak
application
=>
move
|
_
,
_
|
{
clone!
(
@
weak
application
=>
move
|
_
,
_
|
{
let
window
=
application
.window
();
let
window
=
application
.window
();
if
window
.paginator
.
borrow_mut
()
.
try_previous
()
.is_none
()
{
if
window
.paginator
.try_previous
()
.is_none
()
{
window
.reset_tour
();
window
.reset_tour
();
}
}
}),
}),
...
...
src/widgets/paginator.rs
View file @
aa06f0f6
use
gettextrs
::
gettext
;
use
gettextrs
::
gettext
;
use
gtk
::
glib
::{
self
,
clone
};
use
gtk
::
prelude
::
*
;
use
gtk
::
prelude
::
*
;
use
gtk
::{
glib
::{
self
,
clone
},
subclass
::
prelude
::
*
,
};
use
std
::
cell
::
RefCell
;
use
std
::
cell
::
RefCell
;
use
std
::
rc
::
Rc
;
#[derive(Debug)]
pub
struct
PaginatorWidget
{
pub
widget
:
gtk
::
Box
,
carousel
:
adw
::
Carousel
,
carousel_dots
:
adw
::
CarouselIndicatorDots
,
headerbar
:
gtk
::
HeaderBar
,
pages
:
RefCell
<
Vec
<
gtk
::
Widget
>>
,
current_page
:
RefCell
<
u32
>
,
next_overlay
:
gtk
::
Overlay
,
next_btn
:
gtk
::
Button
,
start_btn
:
gtk
::
Button
,
finish_btn
:
gtk
::
Button
,
close_btn
:
gtk
::
Button
,
previous_btn
:
gtk
::
Button
,
}
impl
PaginatorWidget
{
mod
imp
{
pub
fn
new
()
->
Rc
<
Self
>
{
use
std
::
cell
::
Cell
;
let
widget
=
gtk
::
Box
::
new
(
gtk
::
Orientation
::
Vertical
,
0
);
use
super
::
*
;
#[derive(Debug)]
pub
struct
PaginatorWidget
{
pub
(
super
)
carousel
:
adw
::
Carousel
,
pub
(
super
)
carousel_dots
:
adw
::
CarouselIndicatorDots
,
pub
(
super
)
headerbar
:
gtk
::
HeaderBar
,
pub
(
super
)
pages
:
RefCell
<
Vec
<
gtk
::
Widget
>>
,
pub
(
super
)
current_page
:
Cell
<
u32
>
,
pub
(
super
)
next_overlay
:
gtk
::
Overlay
,
pub
(
super
)
next_btn
:
gtk
::
Button
,
pub
(
super
)
start_btn
:
gtk
::
Button
,
pub
(
super
)
finish_btn
:
gtk
::
Button
,
pub
(
super
)
close_btn
:
gtk
::
Button
,
pub
(
super
)
previous_btn
:
gtk
::
Button
,
}
let
paginator
=
Rc
::
new
(
Self
{
impl
Default
for
PaginatorWidget
{
widget
,
fn
default
()
->
Self
{
Self
{
carousel
:
adw
::
Carousel
::
new
(),
carousel
:
adw
::
Carousel
::
new
(),
carousel_dots
:
adw
::
CarouselIndicatorDots
::
new
(),
carousel_dots
:
adw
::
CarouselIndicatorDots
::
new
(),
headerbar
:
gtk
::
HeaderBar
::
builder
()
.show_title_buttons
(
false
)
.build
(),
headerbar
:
gtk
::
HeaderBar
::
builder
()
.show_title_buttons
(
false
)
.build
(),
...
@@ -36,81 +39,26 @@ impl PaginatorWidget {
...
@@ -36,81 +39,26 @@ impl PaginatorWidget {
close_btn
:
gtk
::
Button
::
with_label
(
&
gettext
(
"_Close"
)),
close_btn
:
gtk
::
Button
::
with_label
(
&
gettext
(
"_Close"
)),
previous_btn
:
gtk
::
Button
::
with_label
(
&
gettext
(
"_Previous"
)),
previous_btn
:
gtk
::
Button
::
with_label
(
&
gettext
(
"_Previous"
)),
pages
:
RefCell
::
new
(
Vec
::
new
()),
pages
:
RefCell
::
new
(
Vec
::
new
()),
current_page
:
RefCell
::
new
(
0
),
current_page
:
Cell
::
new
(
0
),
});
paginator
.init
(
paginator
.clone
());
paginator
}
pub
fn
try_next
(
&
self
)
->
Option
<
()
>
{
let
p
=
*
self
.current_page
.borrow
()
+
1
;
if
p
==
self
.carousel
.n_pages
()
{
return
None
;
}
self
.set_page
(
p
);
Some
(())
}
pub
fn
try_previous
(
&
self
)
->
Option
<
()
>
{
let
p
=
*
self
.current_page
.borrow
();
if
p
==
0
{
return
None
;
}
}
self
.set_page
(
p
-
1
);
Some
(())
}
}
pub
fn
add_page
(
&
self
,
page
:
gtk
::
Widget
)
{
let
page_nr
=
self
.pages
.borrow
()
.len
();
self
.carousel
.insert
(
&
page
,
page_nr
as
i32
);
self
.pages
.borrow_mut
()
.push
(
page
);
self
.update_position
();
}
}
fn
update_position
(
&
self
)
{
#[glib
::
object_subclass]
let
position
=
self
.carousel
.position
();
impl
ObjectSubclass
for
PaginatorWidget
{
let
page_nr
=
position
.round
()
as
u32
;
const
NAME
:
&
'static
str
=
"PaginatorWidget"
;
type
ParentType
=
gtk
::
Box
;
let
n_pages
=
self
.carousel
.n_pages
()
as
f64
;
type
Type
=
super
::
PaginatorWidget
;
let
forelast_page
=
n_pages
-
2.0
;
let
last_page
=
n_pages
-
1.0
;
let
(
opacity_finish
,
opacity_previous
,
opacity_start
,
opacity_next
,
opacity_close
)
=
if
(
0.0
..
1.0
)
.contains
(
&
position
)
{
if
position
==
0.0
{
(
0.0
,
position
,
1.0
,
position
,
1.0
)
}
else
{
(
0.0
,
position
,
1.0
,
position
,
1f64
-
position
)
}
}
}
else
if
(
0.0
<=
position
)
&&
(
position
<=
forelast_page
)
{
(
0.0
,
1.0
,
1f64
-
position
,
1.0
,
0.0
)
}
else
if
(
forelast_page
<
position
)
&&
(
position
<=
last_page
)
{
(
position
-
forelast_page
,
1.0
,
0.0
,
1.0
,
0.0
)
}
else
{
panic!
(
"Position of the carousel is outside the allowed range"
);
};
self
.start_btn
.set_opacity
(
opacity_start
);
self
.start_btn
.set_visible
(
opacity_start
>
0
_f64
);
self
.next_btn
.set_opacity
(
opacity_next
);
self
.next_btn
.set_visible
(
opacity_next
>
0
_f64
);
self
.next_overlay
.set_can_target
(
opacity_next
>
0
_f64
);
self
.finish_btn
.set_opacity
(
opacity_finish
);
self
.finish_btn
.set_visible
(
opacity_finish
>
0
_f64
);
self
.previous_btn
.set_opacity
(
opacity_previous
);
impl
ObjectImpl
for
PaginatorWidget
{
self
.previous_btn
.set_visible
(
opacity_previous
>
0
_f64
);
fn
constructed
(
&
self
,
obj
:
&
Self
::
Type
)
{
let
layout_manager
=
obj
self
.close_btn
.set_opacity
(
opacity_close
);
.layout_manager
()
self
.start_btn
.set_visible
(
opacity_close
>
0
_f64
);
.map
(|
l
|
l
.downcast
::
<
gtk
::
BoxLayout
>
()
.unwrap
())
.unwrap
();
self
.current_page
.replace
(
page_nr
);
layout_manager
.set_orientation
(
gtk
::
Orientation
::
Vertical
);
}
fn
init
(
&
self
,
p
:
Rc
<
Self
>
)
{
self
.carousel_dots
.set_carousel
(
Some
(
&
self
.carousel
));
self
.carousel_dots
.set_carousel
(
Some
(
&
self
.carousel
));
self
.carousel
.set_hexpand
(
true
);
self
.carousel
.set_hexpand
(
true
);
self
.carousel
.set_vexpand
(
true
);
self
.carousel
.set_vexpand
(
true
);
...
@@ -118,8 +66,8 @@ impl PaginatorWidget {
...
@@ -118,8 +66,8 @@ impl PaginatorWidget {
.set_scroll_params
(
&
adw
::
SpringParams
::
new
(
1.0
,
0.5
,
300.0
));
.set_scroll_params
(
&
adw
::
SpringParams
::
new
(
1.0
,
0.5
,
300.0
));
self
.carousel
self
.carousel
.connect_position_notify
(
clone!
(
@
weak
p
=>
move
|
_
|
{
.connect_position_notify
(
clone!
(
@
weak
obj
=>
move
|
_
|
{
p
.update_position
();
obj
.update_position
();
}));
}));
self
.start_btn
.add_css_class
(
"suggested-action"
);
self
.start_btn
.add_css_class
(
"suggested-action"
);
self
.start_btn
.set_use_underline
(
true
);
self
.start_btn
.set_use_underline
(
true
);
...
@@ -162,15 +110,105 @@ impl PaginatorWidget {
...
@@ -162,15 +110,105 @@ impl PaginatorWidget {
self
.headerbar
.pack_start
(
&
previous_overlay
);
self
.headerbar
.pack_start
(
&
previous_overlay
);
self
.headerbar
.pack_end
(
&
start_overlay
);
self
.headerbar
.pack_end
(
&
start_overlay
);
self
.widget
.append
(
&
self
.headerbar
);
obj
.append
(
&
self
.headerbar
);
self
.widget
.append
(
&
self
.carousel
);
obj
.append
(
&
self
.carousel
);
self
.parent_constructed
(
obj
);
}
}
impl
WidgetImpl
for
PaginatorWidget
{}
impl
BoxImpl
for
PaginatorWidget
{}
}
glib
::
wrapper!
{
pub
struct
PaginatorWidget
(
ObjectSubclass
<
imp
::
PaginatorWidget
>
)
@
extends
gtk
::
Widget
,
gtk
::
Box
;
}
impl
PaginatorWidget
{
pub
fn
new
()
->
Self
{
glib
::
Object
::
new
(
&
[])
.unwrap
()
}
pub
fn
try_next
(
&
self
)
->
Option
<
()
>
{
let
imp
=
self
.imp
();
let
p
=
imp
.current_page
.get
()
+
1
;
if
p
==
imp
.carousel
.n_pages
()
{
return
None
;
}
self
.set_page
(
p
);
Some
(())
}
pub
fn
try_previous
(
&
self
)
->
Option
<
()
>
{
let
p
=
self
.imp
()
.current_page
.get
();
if
p
==
0
{
return
None
;
}
self
.set_page
(
p
-
1
);
Some
(())
}
pub
fn
add_page
(
&
self
,
page
:
gtk
::
Widget
)
{
let
imp
=
self
.imp
();
let
page_nr
=
imp
.pages
.borrow
()
.len
();
imp
.carousel
.insert
(
&
page
,
page_nr
as
i32
);
imp
.pages
.borrow_mut
()
.push
(
page
);
self
.update_position
();
}
fn
update_position
(
&
self
)
{
let
imp
=
self
.imp
();
let
position
=
imp
.carousel
.position
();
let
page_nr
=
position
.round
()
as
u32
;
let
n_pages
=
imp
.carousel
.n_pages
()
as
f64
;
let
forelast_page
=
n_pages
-
2.0
;
let
last_page
=
n_pages
-
1.0
;
let
(
opacity_finish
,
opacity_previous
,
opacity_start
,
opacity_next
,
opacity_close
)
=
if
(
0.0
..
1.0
)
.contains
(
&
position
)
{
if
position
==
0.0
{
(
0.0
,
position
,
1.0
,
position
,
1.0
)
}
else
{
(
0.0
,
position
,
1.0
,
position
,
1f64
-
position
)
}
}
else
if
(
0.0
<=
position
)
&&
(
position
<=
forelast_page
)
{
(
0.0
,
1.0
,
1f64
-
position
,
1.0
,
0.0
)
}
else
if
(
forelast_page
<
position
)
&&
(
position
<=
last_page
)
{
(
position
-
forelast_page
,
1.0
,
0.0
,
1.0
,
0.0
)
}
else
{
panic!
(
"Position of the carousel is outside the allowed range"
);
};
imp
.start_btn
.set_opacity
(
opacity_start
);
imp
.start_btn
.set_visible
(
opacity_start
>
0
_f64
);
imp
.next_btn
.set_opacity
(
opacity_next
);
imp
.next_btn
.set_visible
(
opacity_next
>
0
_f64
);
imp
.next_overlay
.set_can_target
(
opacity_next
>
0
_f64
);
imp
.finish_btn
.set_opacity
(
opacity_finish
);
imp
.finish_btn
.set_visible
(
opacity_finish
>
0
_f64
);
imp
.previous_btn
.set_opacity
(
opacity_previous
);
imp
.previous_btn
.set_visible
(
opacity_previous
>
0
_f64
);
imp
.close_btn
.set_opacity
(
opacity_close
);
imp
.start_btn
.set_visible
(
opacity_close
>
0
_f64
);
imp
.current_page
.set
(
page_nr
);
}
}
pub
fn
set_page
(
&
self
,
page_nr
:
u32
)
{
pub
fn
set_page
(
&
self
,
page_nr
:
u32
)
{
if
page_nr
<
self
.carousel
.n_pages
()
{
let
imp
=
self
.imp
();
let
pages
=
&
self
.pages
.borrow
();
if
page_nr
<
imp
.carousel
.n_pages
()
{
let
pages
=
&
imp
.pages
.borrow
();
let
page
=
pages
.get
(
page_nr
as
usize
)
.unwrap
();
let
page
=
pages
.get
(
page_nr
as
usize
)
.unwrap
();
self
.carousel
.scroll_to
(
page
,
true
);
imp
.carousel
.scroll_to
(
page
,
true
);
}
}
}
}
}
}
src/widgets/window.rs
View file @
aa06f0f6
use
adw
::
prelude
::
*
;
use
adw
::
prelude
::
*
;
use
gettextrs
::
gettext
;
use
gettextrs
::
gettext
;
use
std
::
cell
::
RefCell
;
use
std
::
rc
::
Rc
;
use
super
::
pages
::{
ImagePageWidget
,
WelcomePageWidget
};
use
super
::
pages
::{
ImagePageWidget
,
WelcomePageWidget
};
use
super
::
paginator
::
PaginatorWidget
;
use
super
::
paginator
::
PaginatorWidget
;
...
@@ -11,14 +9,14 @@ use crate::Application;
...
@@ -11,14 +9,14 @@ use crate::Application;
#[derive(Debug)]
#[derive(Debug)]
pub
struct
Window
{
pub
struct
Window
{
pub
widget
:
adw
::
ApplicationWindow
,
pub
widget
:
adw
::
ApplicationWindow
,
pub
paginator
:
RefCell
<
Rc
<
PaginatorWidget
>>
,
pub
paginator
:
PaginatorWidget
,
}
}
impl
Window
{
impl
Window
{
pub
fn
new
(
app
:
&
Application
)
->
Self
{
pub
fn
new
(
app
:
&
Application
)
->
Self
{
let
widget
=
adw
::
ApplicationWindow
::
new
(
app
);
let
widget
=
adw
::
ApplicationWindow
::
new
(
app
);
let
paginator
=
RefCell
::
new
(
PaginatorWidget
::
new
()
);
let
paginator
=
PaginatorWidget
::
new
(
);
let
mut
window_widget
=
Window
{
widget
,
paginator
};
let
mut
window_widget
=
Window
{
widget
,
paginator
};
...
@@ -27,11 +25,11 @@ impl Window {
...
@@ -27,11 +25,11 @@ impl Window {
}
}
pub
fn
start_tour
(
&
self
)
{
pub
fn
start_tour
(
&
self
)
{
self
.paginator
.
borrow_mut
()
.
set_page
(
1
);
self
.paginator
.set_page
(
1
);
}
}
pub
fn
reset_tour
(
&
self
)
{
pub
fn
reset_tour
(
&
self
)
{
self
.paginator
.
borrow_mut
()
.
set_page
(
0
);
self
.paginator
.set_page
(
0
);
}
}
fn
init
(
&
mut
self
)
{
fn
init
(
&
mut
self
)
{
...
@@ -43,9 +41,8 @@ impl Window {
...
@@ -43,9 +41,8 @@ impl Window {
self
.widget
.add_css_class
(
"devel"
);
self
.widget
.add_css_class
(
"devel"
);
}
}
self
.paginator
self
.paginator
.borrow_mut
()
.add_page
(
WelcomePageWidget
::
new
()
.widget.upcast
::
<
gtk
::
Widget
>
());
.add_page
(
WelcomePageWidget
::
new
()
.widget.upcast
::
<
gtk
::
Widget
>
());
self
.paginator
.
borrow_mut
()
.
add_page
(
self
.paginator
.add_page
(
ImagePageWidget
::
new
(
ImagePageWidget
::
new
(
"/org/gnome/Tour/overview.svg"
,
"/org/gnome/Tour/overview.svg"
,
gettext
(
"Get an Overview"
),
gettext
(
"Get an Overview"
),
...
@@ -55,7 +52,7 @@ impl Window {
...
@@ -55,7 +52,7 @@ impl Window {
.upcast
::
<
gtk
::
Widget
>
(),
.upcast
::
<
gtk
::
Widget
>
(),
);
);
self
.paginator
.
borrow_mut
()
.
add_page
(
self
.paginator
.add_page
(
ImagePageWidget
::
new
(
ImagePageWidget
::
new
(
"/org/gnome/Tour/search.svg"
,
"/org/gnome/Tour/search.svg"
,
gettext
(
"Just Type to Search"
),
gettext
(
"Just Type to Search"
),
...
@@ -65,7 +62,7 @@ impl Window {
...
@@ -65,7 +62,7 @@ impl Window {
.upcast
::
<
gtk
::
Widget
>
(),
.upcast
::
<
gtk
::
Widget
>
(),
);
);
self
.paginator
.
borrow_mut
()
.
add_page
(
self
.paginator
.add_page
(
ImagePageWidget
::
new
(
ImagePageWidget
::
new
(
"/org/gnome/Tour/workspaces.svg"
,
"/org/gnome/Tour/workspaces.svg"
,
gettext
(
"Keep on Top with Workspaces"
),
gettext
(
"Keep on Top with Workspaces"
),
...
@@ -75,7 +72,7 @@ impl Window {
...
@@ -75,7 +72,7 @@ impl Window {
.upcast
::
<
gtk
::
Widget
>
(),
.upcast
::
<
gtk
::
Widget
>
(),
);
);
self
.paginator
.
borrow_mut
()
.
add_page
(
self
.paginator
.add_page
(
ImagePageWidget
::
new
(
ImagePageWidget
::
new
(
"/org/gnome/Tour/blank.svg"
,
"/org/gnome/Tour/blank.svg"
,
gettext
(
"Up/Down for the Overview"
),
gettext
(
"Up/Down for the Overview"
),
...
@@ -85,7 +82,7 @@ impl Window {
...
@@ -85,7 +82,7 @@ impl Window {
.upcast
::
<
gtk
::
Widget
>
(),
.upcast
::
<
gtk
::
Widget
>
(),
);
);
self
.paginator
.
borrow_mut
()
.
add_page
(
self
.paginator
.add_page
(
ImagePageWidget
::
new
(
ImagePageWidget
::
new
(
"/org/gnome/Tour/blank.svg"
,
"/org/gnome/Tour/blank.svg"
,
gettext
(
"Left/Right for Workspaces"
),
gettext
(
"Left/Right for Workspaces"
),
...
@@ -102,10 +99,8 @@ impl Window {
...
@@ -102,10 +99,8 @@ impl Window {
);
);
last_page
.widget
.add_css_class
(
"last-page"
);
last_page
.widget
.add_css_class
(
"last-page"
);
self
.paginator
self
.paginator
.borrow_mut
()
.add_page
(
last_page
.widget.upcast
::
<
gtk
::
Widget
>
());
.add_page
(
last_page
.widget.upcast
::
<
gtk
::
Widget
>
());
self
.widget
self
.widget
.set_content
(
Some
(
&
self
.paginator
));
.set_content
(
Some
(
&
self
.paginator
.borrow
()
.widget
));
}
}
}
}
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