| 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/::ROWS_TO_DISPLAYrust-analyzer cargo gnome-robots 50.0.0 scores/ROWS_TO_DISPLAY.; |
| 21 | 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().; |
| 22 | 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().}; |
| 23 | 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().}; |
| 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#, Scorerust-analyzer cargo gnome-robots 50.0.0 scores/scores/Score#, ScoreListrust-analyzer cargo gnome-robots 50.0.0 scores/scores/ScoreList#}; |
| 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/::{glibrust-analyzer cargo glib 0.22.3 crate/, preluderust-analyzer cargo gtk4 0.11.1 prelude/::*}; |
| 27 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/::RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#; |
| 28 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/::Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#; |
| 29 | |
| 30 | pub async fn new_score_dialogrust-analyzer cargo gnome-robots 50.0.0 scores/new_score_dialog/new_score_dialog().( |
| 31 | new_high_score: &Scorerust-analyzer cargo gnome-robots 50.0.0 scores/scores/Score#, |
| 32 | current_cat: &Categoryrust-analyzer cargo gnome-robots 50.0.0 scores/scores/Category#, |
| 33 | score_list: &ScoreListrust-analyzer cargo gnome-robots 50.0.0 scores/scores/ScoreList#, |
| 34 | window: >krust-analyzer cargo gtk4 0.11.1 crate/::Windowrust-analyzer cargo gtk4 0.11.1 auto/window/Window#, |
| 35 | ) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 36 | let ScoresDialogrust-analyzer cargo gnome-robots 50.0.0 scores/dialog/ScoresDialog# { |
| 37 | dlgrust-analyzer cargo gnome-robots 50.0.0 scores/dialog/ScoresDialog#dlg., |
| 38 | window_titlerust-analyzer cargo gnome-robots 50.0.0 scores/dialog/ScoresDialog#window_title., |
| 39 | headerbarrust-analyzer cargo gnome-robots 50.0.0 scores/dialog/ScoresDialog#headerbar., |
| 40 | vboxrust-analyzer cargo gnome-robots 50.0.0 scores/dialog/ScoresDialog#vbox., |
| 41 | } = new_scores_dialogrust-analyzer cargo gnome-robots 50.0.0 scores/dialog/new_scores_dialog().(window); |
| 42 | |
| 43 | 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().("Congratulations!")); |
| 44 | headerbar.set_show_end_title_buttonsrust-analyzer cargo libadwaita 0.9.1 auto/header_bar/impl#[HeaderBar]set_show_end_title_buttons().(false); |
| 45 | |
| 46 | vbox.set_spacingrust-analyzer cargo gtk4 0.11.1 auto/box_/BoxExt#set_spacing().(20); |
| 47 | |
| 48 | let category_label = 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().() |
| 49 | .labelrust-analyzer cargo gtk4 0.11.1 auto/label/impl#[LabelBuilder]label().(current_cat.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().()) |
| 50 | .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#) |
| 51 | .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#) |
| 52 | .buildrust-analyzer cargo gtk4 0.11.1 auto/label/impl#[LabelBuilder]build().(); |
| 53 | |
| 54 | 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_label)); |
| 55 | vbox.appendrust-analyzer cargo gtk4 0.11.1 auto/box_/BoxExt#append().( |
| 56 | >krust-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().() |
| 57 | .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#) |
| 58 | .buildrust-analyzer cargo gtk4 0.11.1 auto/separator/impl#[SeparatorBuilder]build().(), |
| 59 | ); |
| 60 | |
| 61 | let grid = create_scores_gridrust-analyzer cargo gnome-robots 50.0.0 scores/grid/create_scores_grid().(); |
| 62 | vbox.appendrust-analyzer cargo gtk4 0.11.1 auto/box_/BoxExt#append().(&grid); |
| 63 | |
| 64 | let done = gtkrust-analyzer cargo gtk4 0.11.1 crate/::Buttonrust-analyzer cargo gtk4 0.11.1 auto/button/Button#::builderrust-analyzer cargo gtk4 0.11.1 auto/button/impl#[Button]builder().() |
| 65 | .labelrust-analyzer cargo gtk4 0.11.1 auto/button/impl#[ButtonBuilder]label().(gettextrust-analyzer cargo gettext-rs 0.7.7 gettext().("_Done")) |
| 66 | .use_underlinerust-analyzer cargo gtk4 0.11.1 auto/button/impl#[ButtonBuilder]use_underline().(true) |
| 67 | .buildrust-analyzer cargo gtk4 0.11.1 auto/button/impl#[ButtonBuilder]build().(); |
| 68 | done.add_css_classrust-analyzer cargo gtk4 0.11.1 auto/widget/WidgetExt#add_css_class().("suggested-action"); |
| 69 | done.connect_clickedrust-analyzer cargo gtk4 0.11.1 auto/button/ButtonExt#connect_clicked().(glibrust-analyzer cargo glib 0.22.3 crate/::clonerust-analyzer cargo glib-macros 0.22.2 clone!!( |
| 70 | #[weak] |
| 71 | dlg, |
| 72 | move |_| dlg.closerust-analyzer cargo gtk4 0.11.1 auto/window/GtkWindowExt#close().() |
| 73 | )); |
| 74 | |
| 75 | headerbar.set_show_start_title_buttonsrust-analyzer cargo libadwaita 0.9.1 auto/header_bar/impl#[HeaderBar]set_show_start_title_buttons().(false); |
| 76 | headerbar.set_show_end_title_buttonsrust-analyzer cargo libadwaita 0.9.1 auto/header_bar/impl#[HeaderBar]set_show_end_title_buttons().(false); |
| 77 | headerbar.pack_endrust-analyzer cargo libadwaita 0.9.1 auto/header_bar/impl#[HeaderBar]pack_end().(&done); |
| 78 | |
| 79 | scores_grid_updaterust-analyzer cargo gnome-robots 50.0.0 scores/grid/scores_grid_update().(&grid, score_list); |
| 80 | |
| 81 | let user = Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/impl#[`Rc<T>`]new().(RefCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/RefCell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]new().(new_high_score.userrust-analyzer cargo gnome-robots 50.0.0 scores/scores/Score#user..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().())); |
| 82 | |
| 83 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(position) = score_list |
| 84 | .scoresrust-analyzer cargo gnome-robots 50.0.0 scores/scores/ScoreList#scores. |
| 85 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 86 | .takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(ROWS_TO_DISPLAYrust-analyzer cargo gnome-robots 50.0.0 scores/ROWS_TO_DISPLAY.) |
| 87 | .positionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#position().(|score| score rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().new_high_score) |
| 88 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|p| p as i32) |
| 89 | { |
| 90 | let count = score_list.scoresrust-analyzer cargo gnome-robots 50.0.0 scores/scores/ScoreList#scores..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 91 | if count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().1 && position rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().0 { |
| 92 | window_title.set_subtitlerust-analyzer cargo libadwaita 0.9.1 auto/window_title/impl#[WindowTitle]set_subtitle().(&gettextrust-analyzer cargo gettext-rs 0.7.7 gettext().("Your score is the best!")); |
| 93 | } else { |
| 94 | window_title.set_subtitlerust-analyzer cargo libadwaita 0.9.1 auto/window_title/impl#[WindowTitle]set_subtitle().(&gettextrust-analyzer cargo gettext-rs 0.7.7 gettext().("Your score has made the top ten.")); |
| 95 | } |
| 96 | |
| 97 | let entry = gtkrust-analyzer cargo gtk4 0.11.1 crate/::Entryrust-analyzer cargo gtk4 0.11.1 auto/entry/Entry#::builderrust-analyzer cargo gtk4 0.11.1 auto/entry/impl#[Entry]builder().().textrust-analyzer cargo gtk4 0.11.1 auto/entry/impl#[EntryBuilder]text().(&new_high_score.userrust-analyzer cargo gnome-robots 50.0.0 scores/scores/Score#user.).buildrust-analyzer cargo gtk4 0.11.1 auto/entry/impl#[EntryBuilder]build().(); |
| 98 | entry.connect_text_notifyrust-analyzer cargo gtk4 0.11.1 auto/editable/EditableExt#connect_text_notify().({ |
| 99 | let user = user.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/impl#[`Rc<T, A>`][Clone]clone().(); |
| 100 | move |e| { |
| 101 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefMut<'_, T>`][DerefMut]deref_mut().user.borrow_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]borrow_mut().() = e.textrust-analyzer cargo gtk4 0.11.1 auto/editable/EditableExt#text().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 102 | } |
| 103 | }); |
| 104 | grid_replacerust-analyzer cargo gnome-robots 50.0.0 scores/new_score_dialog/grid_replace().(&grid, entry.upcast_refrust-analyzer cargo glib 0.22.3 object/Cast#upcast_ref().(), 2, position rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add().1); |
| 105 | } |
| 106 | |
| 107 | let (sender, receiver) = async_channelrust-analyzer cargo async-channel 2.5.0 crate/::unboundedrust-analyzer cargo async-channel 2.5.0 unbounded().(); |
| 108 | dlg.connect_close_requestrust-analyzer cargo gtk4 0.11.1 auto/window/GtkWindowExt#connect_close_request().(move |_| { |
| 109 | sender.send_blockingrust-analyzer cargo async-channel 2.5.0 impl#[`Sender<T>`]send_blocking().(()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 110 | glibrust-analyzer cargo glib 0.22.3 crate/::Propagationrust-analyzer cargo glib 0.22.3 signal/Propagation#::Proceedrust-analyzer cargo glib 0.22.3 signal/Propagation#Proceed# |
| 111 | }); |
| 112 | dlg.presentrust-analyzer cargo gtk4 0.11.1 auto/window/GtkWindowExt#present().(); |
| 113 | |
| 114 | receiver.recvrust-analyzer cargo async-channel 2.5.0 impl#[`Receiver<T>`]recv().().rust-analyzer cargo async-channel 2.5.0 impl#[`Recv<'a, T>`][Future]poll().awaitrust-analyzer cargo async-channel 2.5.0 impl#[`Recv<'a, T>`][Future]poll()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 115 | |
| 116 | Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#::unwrap_or_clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/impl#[`Rc<T, A>`]unwrap_or_clone().(user).takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`RefCell<T>`]take().() |
| 117 | } |
| 118 | |
| 119 | fn grid_replacerust-analyzer cargo gnome-robots 50.0.0 scores/new_score_dialog/grid_replace().(grid: >krust-analyzer cargo gtk4 0.11.1 crate/::Gridrust-analyzer cargo gtk4 0.11.1 auto/grid/Grid#, child: >krust-analyzer cargo gtk4 0.11.1 crate/::Widgetrust-analyzer cargo gtk4 0.11.1 auto/widget/Widget#, column: i32, row: i32) { |
| 120 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(prev_child) = grid.child_atrust-analyzer cargo gtk4 0.11.1 auto/grid/GridExt#child_at().(column, row) { |
| 121 | grid.removerust-analyzer cargo gtk4 0.11.1 auto/grid/GridExt#remove().(&prev_child); |
| 122 | } |
| 123 | grid.attachrust-analyzer cargo gtk4 0.11.1 auto/grid/GridExt#attach().(child, column, row, 1, 1); |
| 124 | } |