1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// SPDX-License-Identifier: GPL-3.0-or-later
//! The switches of a classic skin a host keeps in step with the host's settings: the time
//! counting down, the equalizer's auto, the vis mode, the playlist's selection and scroll.
use crate::classic::vis::VisMode;
use crate::runtime::SkinRuntime;
impl SkinRuntime {
/// Whether the time displays count down, as a click on them switches it.
pub fn classic_time_remaining(&self) -> bool {
self.classic_remaining
}
/// Makes the time displays count down, or up.
pub fn set_classic_time_remaining(&mut self, on: bool) {
if self.classic_remaining != on {
self.classic_remaining = on;
self.repaint();
}
}
/// Whether the equalizer's auto button is on.
pub fn classic_eq_auto(&self) -> bool {
self.classic_eq_auto
}
/// Turns the equalizer's auto button on or off.
pub fn set_classic_eq_auto(&mut self, on: bool) {
if self.classic_eq_auto != on {
self.classic_eq_auto = on;
self.repaint();
}
}
/// What the main window's vis shows, as a press on it steps it.
pub fn classic_vis_mode(&self) -> VisMode {
self.classic_vis_mode
}
/// Makes the main window's vis show `mode`.
pub fn set_classic_vis_mode(&mut self, mode: VisMode) {
if self.classic_vis_mode != mode {
self.classic_vis_mode = mode;
self.repaint();
}
}
/// Shows `rows` as the classic playlist's selection, as the host's playlist has it after its
/// select all or invert; rows past the list are left out, and the host is not told back.
pub fn set_classic_playlist_selection(&mut self, rows: &[i32]) {
let len = self.player.tracks().len() as i32;
let mut rows: Vec<i32> = rows
.iter()
.copied()
.filter(|&r| r >= 0 && r < len)
.collect();
rows.sort_unstable();
rows.dedup();
let first = rows.first().copied();
let more = rows.into_iter().skip(1).collect::<Vec<_>>();
if self.classic_selected_row != first || self.classic_selected_more != more {
self.classic_selected_row = first;
self.classic_selected_more = more;
self.repaint();
}
}
/// Whether the classic windows switch to their shade bars, from their shade buttons and a
/// double tap on their title bars.
pub fn classic_shades(&self) -> bool {
self.classic_shades
}
/// Lets the classic windows switch to their shade bars, or not; turning it off puts every
/// shaded one back in its normal layout.
pub fn set_classic_shades(&mut self, on: bool) {
if self.classic_shades == on {
return;
}
self.classic_shades = on;
if on {
return;
}
for id in ["main", "equalizer", "pledit"] {
let Some(c) = self.container(id) else {
continue;
};
let shade = self.container_layout(c, "shade");
if shade.is_none() || self.containers[c].current != shade {
continue;
}
if self.is_open(c) {
self.switch_to(c, "normal");
} else {
// a closed window opens again in its normal layout
self.containers[c].current = self.container_layout(c, "normal");
}
}
self.repaint();
}
/// Puts `marks` on the classic playlist's rows, as the host's playlist marks them; the host
/// sets them again when its playlist changes. Empty marks take them off.
pub fn set_classic_row_marks(&mut self, marks: crate::classic::marks::RowMarks) {
if *self.classic_row_marks != marks {
self.classic_row_marks = std::rc::Rc::new(marks);
self.repaint();
}
}
/// Scrolls the playlist by `rows`, down for more than 0, within its songs.
pub fn scroll_classic_playlist(&mut self, rows: i32) {
let Some(h) = self.object_info("classic.pl").map(|o| o.rect.height) else {
return;
};
let past = self.player.tracks().len() as i32 - self.classic_pl_rows(h);
let to = (self.classic_pl_scroll(h) + rows).clamp(0, past.max(0));
if to != self.classic_pl_scroll {
self.classic_pl_scroll = to;
self.repaint();
}
}
}