Skip to content

Commit

Permalink
faet: изменить внешний вид интерактивной карусели и изменить внешний …
Browse files Browse the repository at this point in the history
…вид `Cassette.TrackInfoPanel` при `track-info` равным `null`, сделав его пустым
  • Loading branch information
Rirusha committed May 16, 2024
1 parent 614ae38 commit 173123d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 47 deletions.
5 changes: 0 additions & 5 deletions data/ui/cover-image.blp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@ using Gtk 4.0;
using Adw 1;

template $CassetteCoverImage: Frame {
styles [
"card"
]

halign: center;
valign: center;

Image real_image {
icon-name: "audio-x-generic-symbolic";
icon-size: large;
}
}
4 changes: 2 additions & 2 deletions data/ui/devel-view.blp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ template $CassetteDevelView: $CassetteBaseView {

$CassetteTrackCarousel {
interactive: true;
spacing: 4;
panels-width: 240;
spacing: 24;
panels-width: 270;
vexpand: true;
hexpand: true;
orientation: vertical;
Expand Down
12 changes: 9 additions & 3 deletions src/widgets/cover-image.vala
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ public sealed class Cassette.CoverImage : Gtk.Frame {
* Easy way to set both width and height of the image.
*/
public int size {
get {
return real_image.width_request == real_image.height_request ? real_image.height_request : -1;
}
set {
width_request = value;
height_request = value;
real_image.width_request = value;
real_image.height_request = value;
}
}

Expand All @@ -59,12 +62,15 @@ public sealed class Cassette.CoverImage : Gtk.Frame {
}

public void init_content (HasCover yam_object) {
real_image.icon_name = "audio-x-generic-symbolic";
this.yam_object = yam_object;
add_css_class ("card");
}

public void clear () {
real_image.icon_name = "audio-x-generic-symbolic";
real_image.icon_name = null;
yam_object = null;
remove_css_class ("card");
}

public async void load_image () {
Expand Down
63 changes: 29 additions & 34 deletions src/widgets/track-carousel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,7 @@ public class Cassette.TrackCarousel : Adw.Bin, Gtk.Orientable {
[GtkChild]
unowned Adw.Carousel carousel;

bool interactive_connected = false;
bool _interactive = false;
public bool interactive {
get {
return _interactive;
}
set {
_interactive = value;

if (_interactive && !interactive_connected) {
var gs = new Gtk.GestureClick ();
gs.pressed.connect (() => {
is_scrolling_now = true;
});
carousel.add_controller (gs);

player.bind_property (
"current-track-loading",
this,
"interactive",
BindingFlags.DEFAULT | BindingFlags.INVERT_BOOLEAN
);

interactive_connected = true;
}
}
}
public bool interactive { get; construct set; }

public uint spacing {
get {
Expand Down Expand Up @@ -118,15 +92,36 @@ public class Cassette.TrackCarousel : Adw.Bin, Gtk.Orientable {

construct {
carousel.append (new TrackInfoPanel (orientation) {
width_request = panels_width
width_request = panels_width,
image_size = panels_width
});
carousel.append (new TrackInfoPanel (orientation) {
width_request = panels_width
width_request = panels_width,
image_size = panels_width
});
carousel.append (new TrackInfoPanel (orientation) {
width_request = panels_width
width_request = panels_width,
image_size = panels_width
});

if (interactive) {
var gs = new Gtk.GestureClick ();
gs.pressed.connect (() => {
is_scrolling_now = true;
});
carousel.add_controller (gs);

player.bind_property (
"current-track-loading",
this,
"interactive",
BindingFlags.DEFAULT | BindingFlags.INVERT_BOOLEAN
);

} else {
player.current_track_finish_loading.connect_after (check_situation);
}

bind_property (
"interactive",
carousel,
Expand All @@ -138,8 +133,6 @@ public class Cassette.TrackCarousel : Adw.Bin, Gtk.Orientable {

player.next_track_loaded.connect (check_situation);

player.current_track_finish_loading.connect (check_situation);

player.notify["shuffle-mode"].connect (check_situation);
player.notify["repeat-mode"].connect (check_situation);

Expand Down Expand Up @@ -200,13 +193,15 @@ public class Cassette.TrackCarousel : Adw.Bin, Gtk.Orientable {
if (carousel.position == 0.0) {
carousel.remove (track_info_panel_right);
carousel.insert (new TrackInfoPanel (orientation) {
width_request = panels_width
width_request = panels_width,
image_size = panels_width
}, 0);

} else if (carousel.position == 2.0) {
carousel.remove (track_info_panel_left);
carousel.insert (new TrackInfoPanel (orientation) {
width_request = panels_width
width_request = panels_width,
image_size = panels_width
}, -1);
carousel.scroll_to (track_info_panel_center, false);
}
Expand Down
25 changes: 22 additions & 3 deletions src/widgets/track-info-panel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,32 @@ public class Cassette.TrackInfoPanel : Adw.Bin, Gtk.Orientable {

cover_image.init_content (track_info);
cover_image.load_image.begin ();
cover_image.visible = true;

play_mark_track.init_content (_track_info.id);
}
}
}


public int image_size {
get {
return cover_image.size;
}
set {
if (value == -1) {
if (orientation == Gtk.Orientation.HORIZONTAL) {
cover_image.size = 60;

} else {
cover_image.size = 200;
}

} else {
cover_image.size = value;
}
}
}

public int position { get; set; }

Gtk.Orientation _orientation = Gtk.Orientation.HORIZONTAL;
Expand Down Expand Up @@ -124,7 +143,7 @@ public class Cassette.TrackInfoPanel : Adw.Bin, Gtk.Orientable {
title_and_marks_box.center_widget = info_marks;

cover_image.cover_size = CoverSize.SMALL;
cover_image.size = 60;
cover_image.size = image_size == -1 ? 60 : image_size;
break;

case Gtk.Orientation.VERTICAL:
Expand Down Expand Up @@ -153,7 +172,7 @@ public class Cassette.TrackInfoPanel : Adw.Bin, Gtk.Orientable {
title_and_marks_box.end_widget = info_marks;

cover_image.cover_size = CoverSize.BIG;
cover_image.size = 200;
cover_image.size = image_size == -1 ? 200 : image_size;
break;
}
}
Expand Down

0 comments on commit 173123d

Please sign in to comment.