Merge branch 'wip_event_redraw' into develop
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use std::time::{SystemTime, Duration};
|
||||
use std::collections::HashMap;
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
use cursive::align::HAlign;
|
||||
use cursive::direction::Direction;
|
||||
@@ -12,6 +12,8 @@ use cursive::views::EditView;
|
||||
use cursive::Printer;
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
||||
use events;
|
||||
|
||||
struct Screen {
|
||||
title: String,
|
||||
view: Box<dyn View>,
|
||||
@@ -26,10 +28,12 @@ pub struct Layout {
|
||||
cmdline_focus: bool,
|
||||
error: Option<String>,
|
||||
error_time: Option<SystemTime>,
|
||||
screenchange: bool,
|
||||
ev: events::EventManager,
|
||||
}
|
||||
|
||||
impl Layout {
|
||||
pub fn new<T: IntoBoxedView>(status: T) -> Layout {
|
||||
pub fn new<T: IntoBoxedView>(status: T, ev: &events::EventManager) -> Layout {
|
||||
Layout {
|
||||
views: HashMap::new(),
|
||||
title: String::new(),
|
||||
@@ -39,6 +43,8 @@ impl Layout {
|
||||
cmdline_focus: false,
|
||||
error: None,
|
||||
error_time: None,
|
||||
ev: ev.clone(),
|
||||
screenchange: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +77,7 @@ impl Layout {
|
||||
self.title = title.clone();
|
||||
self.focus = Some(s);
|
||||
self.cmdline_focus = false;
|
||||
self.screenchange = true;
|
||||
}
|
||||
|
||||
pub fn set_error<S: Into<String>>(&mut self, error: S) {
|
||||
@@ -127,13 +134,15 @@ impl View for Layout {
|
||||
if let Some(e) = error {
|
||||
printer.with_color(ColorStyle::highlight(), |printer| {
|
||||
printer.print_hline((0, printer.size.y - cmdline_height), printer.size.x, " ");
|
||||
printer.print((0, printer.size.y - cmdline_height), &format!("ERROR: {}", e));
|
||||
printer.print(
|
||||
(0, printer.size.y - cmdline_height),
|
||||
&format!("ERROR: {}", e),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
if cmdline_visible {
|
||||
let printer = &printer
|
||||
.offset((0, printer.size.y - 1));
|
||||
let printer = &printer.offset((0, printer.size.y - 1));
|
||||
self.cmdline.draw(&printer);
|
||||
}
|
||||
}
|
||||
@@ -161,6 +170,14 @@ impl View for Layout {
|
||||
if let Some(ref id) = self.focus {
|
||||
let screen = self.views.get_mut(id).unwrap();
|
||||
screen.view.layout(Vec2::new(size.x, size.y - 3));
|
||||
|
||||
// the focus view has changed, let the views know so they can redraw
|
||||
// their items
|
||||
if self.screenchange {
|
||||
debug!("layout: new screen selected: {}", &id);
|
||||
self.ev.send(events::Event::ScreenChange(id.clone()));
|
||||
self.screenchange = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ pub struct Playlist {
|
||||
}
|
||||
|
||||
pub enum PlaylistEvent {
|
||||
Show,
|
||||
NewList(Playlist),
|
||||
}
|
||||
|
||||
@@ -155,15 +154,20 @@ impl PlaylistView {
|
||||
}
|
||||
}
|
||||
|
||||
fn populate(&self, playlists: &mut ViewRef<LinearLayout>) {
|
||||
for list in self
|
||||
.playlists
|
||||
.read()
|
||||
.expect("could not acquire read lock on playlists")
|
||||
.iter()
|
||||
{
|
||||
let button = self.create_button(&list);
|
||||
playlists.add_child(button);
|
||||
pub fn repopulate(&self, cursive: &mut Cursive) {
|
||||
let view_ref: Option<ViewRef<LinearLayout>> = cursive.find_id("playlists");
|
||||
if let Some(mut playlists) = view_ref {
|
||||
self.clear_playlists(&mut playlists);
|
||||
|
||||
for list in self
|
||||
.playlists
|
||||
.read()
|
||||
.expect("could not acquire read lock on playlists")
|
||||
.iter()
|
||||
{
|
||||
let button = self.create_button(&list);
|
||||
playlists.add_child(button);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,10 +176,6 @@ impl PlaylistView {
|
||||
|
||||
if let Some(mut playlists) = view_ref {
|
||||
match event {
|
||||
PlaylistEvent::Show => {
|
||||
self.clear_playlists(&mut playlists);
|
||||
self.populate(&mut playlists);
|
||||
}
|
||||
PlaylistEvent::NewList(list) => {
|
||||
let button = self.create_button(&list);
|
||||
playlists.add_child(button);
|
||||
|
||||
@@ -8,7 +8,7 @@ use cursive::Cursive;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
|
||||
use queue::{Queue, QueueEvent};
|
||||
use queue::Queue;
|
||||
use track::Track;
|
||||
use ui::splitbutton::SplitButton;
|
||||
use ui::trackbutton::TrackButton;
|
||||
@@ -46,16 +46,6 @@ impl QueueView {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_ev(&self, cursive: &mut Cursive, ev: QueueEvent) {
|
||||
let view_ref: Option<ViewRef<LinearLayout>> = cursive.find_id("queue_list");
|
||||
if let Some(mut queuelist) = view_ref {
|
||||
match ev {
|
||||
QueueEvent::Show => self.populate(&mut queuelist),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn create_button(&self, track: &Track) -> SplitButton {
|
||||
let mut button = TrackButton::new(&track);
|
||||
// 'd' deletes the selected track
|
||||
@@ -82,15 +72,18 @@ impl QueueView {
|
||||
button
|
||||
}
|
||||
|
||||
pub fn populate(&self, queuelist: &mut LinearLayout) {
|
||||
while queuelist.len() > 0 {
|
||||
queuelist.remove_child(0);
|
||||
}
|
||||
pub fn repopulate(&self, cursive: &mut Cursive) {
|
||||
let view_ref: Option<ViewRef<LinearLayout>> = cursive.find_id("queue_list");
|
||||
if let Some(mut queuelist) = view_ref {
|
||||
while queuelist.len() > 0 {
|
||||
queuelist.remove_child(0);
|
||||
}
|
||||
|
||||
let queue = self.queue.lock().expect("could not lock queue");
|
||||
for track in queue.iter() {
|
||||
let button = self.create_button(track);
|
||||
queuelist.add_child(button);
|
||||
let queue = self.queue.lock().expect("could not lock queue");
|
||||
for track in queue.iter() {
|
||||
let button = self.create_button(track);
|
||||
queuelist.add_child(button);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user