Debian Codegraph @

src/scores/scores_dialog.rs

raw symbols SCIP
1 /*
2 * Copyright 2024 Andrey Kutejko <[email protected]>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
16 *
17 * For more details see the file COPYING.
18 */
19
20 use superrust-analyzer cargo gnome-robots 50.0.0 scores/::category_barrust-analyzer cargo gnome-robots 50.0.0 scores/category_bar/::category_barrust-analyzer cargo gnome-robots 50.0.0 scores/category_bar/category_bar().;
21 use superrust-analyzer cargo gnome-robots 50.0.0 scores/::dialogrust-analyzer cargo gnome-robots 50.0.0 scores/dialog/::{ScoresDialogrust-analyzer cargo gnome-robots 50.0.0 scores/dialog/ScoresDialog#, new_scores_dialogrust-analyzer cargo gnome-robots 50.0.0 scores/dialog/new_scores_dialog().};
22 use superrust-analyzer cargo gnome-robots 50.0.0 scores/::gridrust-analyzer cargo gnome-robots 50.0.0 scores/grid/::{create_scores_gridrust-analyzer cargo gnome-robots 50.0.0 scores/grid/create_scores_grid()., scores_grid_updaterust-analyzer cargo gnome-robots 50.0.0 scores/grid/scores_grid_update().};
23 use superrust-analyzer cargo gnome-robots 50.0.0 scores/::no_scoresrust-analyzer cargo gnome-robots 50.0.0 scores/no_scores/::no_scoresrust-analyzer cargo gnome-robots 50.0.0 scores/no_scores/no_scores().;
24 use superrust-analyzer cargo gnome-robots 50.0.0 scores/::scoresrust-analyzer cargo gnome-robots 50.0.0 scores/scores/::{Categoryrust-analyzer cargo gnome-robots 50.0.0 scores/scores/Category#, ScoreListrust-analyzer cargo gnome-robots 50.0.0 scores/scores/ScoreList#, Scoresrust-analyzer cargo gnome-robots 50.0.0 scores/scores/Scores#};
25 use gettextrsrust-analyzer cargo gettext-rs 0.7.7 crate/::gettextrust-analyzer cargo gettext-rs 0.7.7 gettext().;
26 use gtkrust-analyzer cargo gtk4 0.11.1 crate/::{giorust-analyzer cargo gio 0.22.2 crate/, glibrust-analyzer cargo glib 0.22.3 crate/, preluderust-analyzer cargo gtk4 0.11.1 prelude/::*};
27
28 struct Pagerust-analyzer cargo gnome-robots 50.0.0 scores/scores_dialog/Page# {
29 categoryrust-analyzer cargo gnome-robots 50.0.0 scores/scores_dialog/Page#category.: Categoryrust-analyzer cargo gnome-robots 50.0.0 scores/scores/Category#,
30 score_listrust-analyzer cargo gnome-robots 50.0.0 scores/scores_dialog/Page#score_list.: ScoreListrust-analyzer cargo gnome-robots 50.0.0 scores/scores/ScoreList#,
31 }
32
33 pub fn scores_dialogrust-analyzer cargo gnome-robots 50.0.0 scores/scores_dialog/scores_dialog().(
34 scores: Scoresrust-analyzer cargo gnome-robots 50.0.0 scores/scores/Scores#,
35 current_cat: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Categoryrust-analyzer cargo gnome-robots 50.0.0 scores/scores/Category#>,
36 window: &gtkrust-analyzer cargo gtk4 0.11.1 crate/::Windowrust-analyzer cargo gtk4 0.11.1 auto/window/Window#,
37 ) -> gtkrust-analyzer cargo gtk4 0.11.1 crate/::Windowrust-analyzer cargo gtk4 0.11.1 auto/window/Window# {
38 let ScoresDialogrust-analyzer cargo gnome-robots 50.0.0 scores/dialog/ScoresDialog# {
39 dlgrust-analyzer cargo gnome-robots 50.0.0 scores/dialog/ScoresDialog#dlg.,
40 window_titlerust-analyzer cargo gnome-robots 50.0.0 scores/dialog/ScoresDialog#window_title.,
41 headerbarrust-analyzer cargo gnome-robots 50.0.0 scores/dialog/ScoresDialog#headerbar.,
42 vboxrust-analyzer cargo gnome-robots 50.0.0 scores/dialog/ScoresDialog#vbox.,
43 } = new_scores_dialogrust-analyzer cargo gnome-robots 50.0.0 scores/dialog/new_scores_dialog().(window);
44
45 window_title.set_titlerust-analyzer cargo libadwaita 0.9.1 auto/window_title/impl#[WindowTitle]set_title().(&gettextrust-analyzer cargo gettext-rs 0.7.7 gettext().("High Scores"));
46 headerbar.set_show_end_title_buttonsrust-analyzer cargo libadwaita 0.9.1 auto/header_bar/impl#[HeaderBar]set_show_end_title_buttons().(true);
47
48 if scores.scoresrust-analyzer cargo gnome-robots 50.0.0 scores/scores/Scores#scores..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]is_empty().() {
49 vbox.appendrust-analyzer cargo gtk4 0.11.1 auto/box_/BoxExt#append().(&no_scoresrust-analyzer cargo gnome-robots 50.0.0 scores/no_scores/no_scores().());
50 return dlg.upcastrust-analyzer cargo glib 0.22.3 object/Cast#upcast().();
51 }
52
53 vbox.set_spacingrust-analyzer cargo gtk4 0.11.1 auto/box_/BoxExt#set_spacing().(20);
54
55 let grid = create_scores_gridrust-analyzer cargo gnome-robots 50.0.0 scores/grid/create_scores_grid().();
56
57 let category_widget: gtkrust-analyzer cargo gtk4 0.11.1 crate/::Widgetrust-analyzer cargo gtk4 0.11.1 auto/widget/Widget# = if scores.scoresrust-analyzer cargo gnome-robots 50.0.0 scores/scores/Scores#scores..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().1 {
58 let (category, score_list) = scores.scoresrust-analyzer cargo gnome-robots 50.0.0 scores/scores/Scores#scores..into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`][IntoIterator]into_iter().().nextrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`IntoIter<K, V, A>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
59
60 scores_grid_updaterust-analyzer cargo gnome-robots 50.0.0 scores/grid/scores_grid_update().(&grid, &score_list);
61
62 gtkrust-analyzer cargo gtk4 0.11.1 crate/::Labelrust-analyzer cargo gtk4 0.11.1 auto/label/Label#::builderrust-analyzer cargo gtk4 0.11.1 auto/label/impl#[Label]builder().()
63 .labelrust-analyzer cargo gtk4 0.11.1 auto/label/impl#[LabelBuilder]label().(category.namerust-analyzer cargo gnome-robots 50.0.0 scores/scores/impl#[Category]name().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().())
64 .halignrust-analyzer cargo gtk4 0.11.1 auto/label/impl#[LabelBuilder]halign().(gtkrust-analyzer cargo gtk4 0.11.1 crate/::Alignrust-analyzer cargo gtk4 0.11.1 enums/Align#::Centerrust-analyzer cargo gtk4 0.11.1 enums/Align#Center#)
65 .valignrust-analyzer cargo gtk4 0.11.1 auto/label/impl#[LabelBuilder]valign().(gtkrust-analyzer cargo gtk4 0.11.1 crate/::Alignrust-analyzer cargo gtk4 0.11.1 enums/Align#::Centerrust-analyzer cargo gtk4 0.11.1 enums/Align#Center#)
66 .buildrust-analyzer cargo gtk4 0.11.1 auto/label/impl#[LabelBuilder]build().()
67 .upcastrust-analyzer cargo glib 0.22.3 object/Cast#upcast().()
68 } else {
69 let model = giorust-analyzer cargo gio 0.22.2 crate/::ListStorerust-analyzer cargo gio 0.22.2 auto/list_store/ListStore#::newrust-analyzer cargo gio 0.22.2 list_store/impl#[ListStore]new().::<glibrust-analyzer cargo glib 0.22.3 crate/::BoxedAnyObjectrust-analyzer cargo glib 0.22.3 boxed_any_object/BoxedAnyObject#>();
70 let mut to_select = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
71 for (index, (category, score_list)) in scores.scoresrust-analyzer cargo gnome-robots 50.0.0 scores/scores/Scores#scores..into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`][IntoIterator]into_iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
72 if current_cat rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&category) {
73 to_select = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(index as u32);
74 }
75 let page = glibrust-analyzer cargo glib 0.22.3 crate/::BoxedAnyObjectrust-analyzer cargo glib 0.22.3 boxed_any_object/BoxedAnyObject#::newrust-analyzer cargo glib 0.22.3 boxed_any_object/impl#[BoxedAnyObject]new().(Pagerust-analyzer cargo gnome-robots 50.0.0 scores/scores_dialog/Page# {
76 categoryrust-analyzer cargo gnome-robots 50.0.0 scores/scores_dialog/Page#category.,
77 score_listrust-analyzer cargo gnome-robots 50.0.0 scores/scores_dialog/Page#score_list.,
78 });
79 model.appendrust-analyzer cargo gio 0.22.2 auto/list_store/impl#[ListStore]append().(&page);
80 }
81
82 let params: &[&gtkrust-analyzer cargo gtk4 0.11.1 crate/::Expressionrust-analyzer cargo gtk4 0.11.1 auto/expression/Expression#] = &[];
83
84 let combo = gtkrust-analyzer cargo gtk4 0.11.1 crate/::DropDownrust-analyzer cargo gtk4 0.11.1 auto/drop_down/DropDown#::builderrust-analyzer cargo gtk4 0.11.1 auto/drop_down/impl#[DropDown]builder().()
85 .focus_on_clickrust-analyzer cargo gtk4 0.11.1 auto/drop_down/impl#[DropDownBuilder]focus_on_click().(false)
86 .modelrust-analyzer cargo gtk4 0.11.1 auto/drop_down/impl#[DropDownBuilder]model().(&model)
87 .expressionrust-analyzer cargo gtk4 0.11.1 auto/drop_down/impl#[DropDownBuilder]expression().(gtkrust-analyzer cargo gtk4 0.11.1 crate/::ClosureExpressionrust-analyzer cargo gtk4 0.11.1 auto/closure_expression/ClosureExpression#::with_callbackrust-analyzer cargo gtk4 0.11.1 closure_expression/impl#[ClosureExpression]with_callback().::<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, _>(
88 params,
89 |values| {
90 values[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().
91 .getrust-analyzer cargo glib 0.22.3 value/impl#[Value]get().::<glibrust-analyzer cargo glib 0.22.3 crate/::BoxedAnyObjectrust-analyzer cargo glib 0.22.3 boxed_any_object/BoxedAnyObject#>()
92 .okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()
93 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|item| {
94 let page = item.borrowrust-analyzer cargo glib 0.22.3 boxed_any_object/impl#[BoxedAnyObject]borrow().::<Pagerust-analyzer cargo gnome-robots 50.0.0 scores/scores_dialog/Page#>();
95 page.categoryrust-analyzer cargo gnome-robots 50.0.0 scores/scores_dialog/Page#category..namerust-analyzer cargo gnome-robots 50.0.0 scores/scores/impl#[Category]name().()
96 })
97 .unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().()
98 },
99 ))
100 .buildrust-analyzer cargo gtk4 0.11.1 auto/drop_down/impl#[DropDownBuilder]build().();
101 combo.connect_selected_item_notifyrust-analyzer cargo gtk4 0.11.1 auto/drop_down/impl#[DropDown]connect_selected_item_notify().(glibrust-analyzer cargo glib 0.22.3 crate/::clonerust-analyzer cargo glib-macros 0.22.2 clone!!(
102 #[weak]
103 grid,
104 move |cb| {
105 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(selected_category) =
106 cb.selected_itemrust-analyzer cargo gtk4 0.11.1 auto/drop_down/impl#[DropDown]selected_item().().and_downcastrust-analyzer cargo glib 0.22.3 object/impl#[`Option<I>`][CastNone]and_downcast().::<glibrust-analyzer cargo glib 0.22.3 crate/::BoxedAnyObjectrust-analyzer cargo glib 0.22.3 boxed_any_object/BoxedAnyObject#>()
107 {
108 scores_grid_updaterust-analyzer cargo gnome-robots 50.0.0 scores/grid/scores_grid_update().(&grid, &selected_category.borrowrust-analyzer cargo glib 0.22.3 boxed_any_object/impl#[BoxedAnyObject]borrow().::<Pagerust-analyzer cargo gnome-robots 50.0.0 scores/scores_dialog/Page#>().score_listrust-analyzer cargo gnome-robots 50.0.0 scores/scores_dialog/Page#score_list.);
109 }
110 }
111 ));
112 combo.set_selectedrust-analyzer cargo gtk4 0.11.1 auto/drop_down/impl#[DropDown]set_selected().(to_select.unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().());
113 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(selected_category) = model
114 .itemrust-analyzer cargo gio 0.22.2 auto/list_model/ListModelExt#item().(to_select.unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().())
115 .and_downcastrust-analyzer cargo glib 0.22.3 object/impl#[`Option<I>`][CastNone]and_downcast().::<glibrust-analyzer cargo glib 0.22.3 crate/::BoxedAnyObjectrust-analyzer cargo glib 0.22.3 boxed_any_object/BoxedAnyObject#>()
116 {
117 scores_grid_updaterust-analyzer cargo gnome-robots 50.0.0 scores/grid/scores_grid_update().(&grid, &selected_category.borrowrust-analyzer cargo glib 0.22.3 boxed_any_object/impl#[BoxedAnyObject]borrow().::<Pagerust-analyzer cargo gnome-robots 50.0.0 scores/scores_dialog/Page#>().score_listrust-analyzer cargo gnome-robots 50.0.0 scores/scores_dialog/Page#score_list.);
118 }
119
120 combo.upcastrust-analyzer cargo glib 0.22.3 object/Cast#upcast().()
121 };
122
123 vbox.appendrust-analyzer cargo gtk4 0.11.1 auto/box_/BoxExt#append().(&category_barrust-analyzer cargo gnome-robots 50.0.0 scores/category_bar/category_bar().(&category_widget));
124
125 vbox.appendrust-analyzer cargo gtk4 0.11.1 auto/box_/BoxExt#append().(
126 &gtkrust-analyzer cargo gtk4 0.11.1 crate/::Separatorrust-analyzer cargo gtk4 0.11.1 auto/separator/Separator#::builderrust-analyzer cargo gtk4 0.11.1 auto/separator/impl#[Separator]builder().()
127 .orientationrust-analyzer cargo gtk4 0.11.1 auto/separator/impl#[SeparatorBuilder]orientation().(gtkrust-analyzer cargo gtk4 0.11.1 crate/::Orientationrust-analyzer cargo gtk4 0.11.1 auto/enums/Orientation#::Horizontalrust-analyzer cargo gtk4 0.11.1 auto/enums/Orientation#Horizontal#)
128 .buildrust-analyzer cargo gtk4 0.11.1 auto/separator/impl#[SeparatorBuilder]build().(),
129 );
130
131 vbox.appendrust-analyzer cargo gtk4 0.11.1 auto/box_/BoxExt#append().(&grid);
132
133 dlg.upcastrust-analyzer cargo glib 0.22.3 object/Cast#upcast().()
134 }