Commit 019ec897 authored by Jordan Petridis's avatar Jordan Petridis 🌱

InAppNotif: Add a spinner

parent e25e411e
...@@ -53,20 +53,12 @@ Tobias Bernard ...@@ -53,20 +53,12 @@ Tobias Bernard
<property name="margin_end">3</property> <property name="margin_end">3</property>
<property name="spacing">6</property> <property name="spacing">6</property>
<child> <child>
<object class="GtkLabel" id="text"> <object class="GtkSpinner" id="spinner">
<property name="width_request">150</property>
<property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="margin_start">12</property>
<property name="margin_end">12</property>
<property name="label" translatable="yes">An in-app action notification</property>
<property name="ellipsize">start</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">True</property>
<property name="position">0</property> <property name="position">0</property>
</packing> </packing>
</child> </child>
...@@ -97,6 +89,24 @@ Tobias Bernard ...@@ -97,6 +89,24 @@ Tobias Bernard
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkLabel" id="text">
<property name="width_request">150</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="margin_start">12</property>
<property name="margin_end">12</property>
<property name="label" translatable="yes">An in-app action notification</property>
<property name="ellipsize">start</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
<child> <child>
<object class="GtkButton" id="undo"> <object class="GtkButton" id="undo">
<property name="label" translatable="yes">Undo</property> <property name="label" translatable="yes">Undo</property>
...@@ -112,7 +122,7 @@ Tobias Bernard ...@@ -112,7 +122,7 @@ Tobias Bernard
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="pack_type">end</property> <property name="pack_type">end</property>
<property name="position">2</property> <property name="position">3</property>
</packing> </packing>
</child> </child>
</object> </object>
......
...@@ -17,7 +17,7 @@ use settings::{self, WindowGeometry}; ...@@ -17,7 +17,7 @@ use settings::{self, WindowGeometry};
use stacks::{Content, PopulatedState}; use stacks::{Content, PopulatedState};
use utils; use utils;
use widgets::about_dialog; use widgets::about_dialog;
use widgets::appnotif::{InAppNotification, State}; use widgets::appnotif::{InAppNotification, SpinnerState, State};
use widgets::player; use widgets::player;
use widgets::show_menu::{mark_all_notif, remove_show_notif, ShowMenu}; use widgets::show_menu::{mark_all_notif, remove_show_notif, ShowMenu};
...@@ -332,6 +332,7 @@ impl App { ...@@ -332,6 +332,7 @@ impl App {
let undo_cb: Option<fn()> = None; let undo_cb: Option<fn()> = None;
let updater = InAppNotification::new(&txt, 1, callback, undo_cb); let updater = InAppNotification::new(&txt, 1, callback, undo_cb);
updater.set_close_state(State::Hidden); updater.set_close_state(State::Hidden);
updater.set_spinner_state(SpinnerState::Active);
let old = self.updater.replace(Some(updater)); let old = self.updater.replace(Some(updater));
old.map(|i| i.destroy()); old.map(|i| i.destroy());
......
...@@ -12,12 +12,20 @@ pub(crate) enum State { ...@@ -12,12 +12,20 @@ pub(crate) enum State {
Hidden, Hidden,
} }
#[derive(Debug, Clone, Copy)]
#[allow(dead_code)]
pub(crate) enum SpinnerState {
Active,
Stopped,
}
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub(crate) struct InAppNotification { pub(crate) struct InAppNotification {
revealer: gtk::Revealer, revealer: gtk::Revealer,
text: gtk::Label, text: gtk::Label,
undo: gtk::Button, undo: gtk::Button,
close: gtk::Button, close: gtk::Button,
spinner: gtk::Spinner,
} }
impl Default for InAppNotification { impl Default for InAppNotification {
...@@ -28,12 +36,14 @@ impl Default for InAppNotification { ...@@ -28,12 +36,14 @@ impl Default for InAppNotification {
let text: gtk::Label = builder.get_object("text").unwrap(); let text: gtk::Label = builder.get_object("text").unwrap();
let undo: gtk::Button = builder.get_object("undo").unwrap(); let undo: gtk::Button = builder.get_object("undo").unwrap();
let close: gtk::Button = builder.get_object("close").unwrap(); let close: gtk::Button = builder.get_object("close").unwrap();
let spinner = builder.get_object("spinner").unwrap();
InAppNotification { InAppNotification {
revealer, revealer,
text, text,
undo, undo,
close, close,
spinner,
} }
} }
} }
...@@ -121,7 +131,6 @@ impl InAppNotification { ...@@ -121,7 +131,6 @@ impl InAppNotification {
} }
} }
#[allow(dead_code)]
pub(crate) fn set_close_state(&self, state: State) { pub(crate) fn set_close_state(&self, state: State) {
match state { match state {
State::Shown => self.close.show(), State::Shown => self.close.show(),
...@@ -129,6 +138,19 @@ impl InAppNotification { ...@@ -129,6 +138,19 @@ impl InAppNotification {
} }
} }
pub(crate) fn set_spinner_state(&self, state: SpinnerState) {
match state {
SpinnerState::Active => {
self.spinner.start();
self.spinner.show();
}
SpinnerState::Stopped => {
self.spinner.stop();
self.spinner.hide();
}
}
}
pub(crate) fn destroy(self) { pub(crate) fn destroy(self) {
self.revealer.destroy(); self.revealer.destroy();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment