Extract Card and CardArea classes

This commit is contained in:
Camden Dixie O'Brien 2025-03-02 14:32:08 +00:00
parent 94df48db7b
commit c2d81778a8
4 changed files with 48 additions and 28 deletions

View File

@ -1,37 +1,16 @@
namespace StudySystemClient {
public class ActivitiesView : Gtk.Box {
private Client client;
private Gtk.FlowBox card_container;
private RefreshingIndicator refreshing_indicator;
private CardArea card_area;
public ActivitiesView(Client client) {
Object(orientation: Gtk.Orientation.VERTICAL,
hexpand: true,
vexpand: true,
margin_top: 0,
margin_bottom: 0,
margin_start: 0,
margin_end: 0);
this.client = client;
card_container = new Gtk.FlowBox();
card_container.homogeneous = true;
card_container.min_children_per_line = 1;
card_container.max_children_per_line = 1;
card_container.selection_mode = Gtk.SelectionMode.NONE;
card_container.valign = Gtk.Align.START;
var scrolled_window = new Gtk.ScrolledWindow();
scrolled_window.hscrollbar_policy = Gtk.PolicyType.NEVER;
scrolled_window.hexpand = true;
scrolled_window.vexpand = true;
scrolled_window.add_css_class("card-container");
scrolled_window.set_child(card_container);
card_area = new CardArea();
var overlay = new Gtk.Overlay();
overlay.hexpand = overlay.vexpand = true;
overlay.set_child(scrolled_window);
overlay.set_child(card_area);
this.append(overlay);
refreshing_indicator = new RefreshingIndicator(overlay);
@ -43,11 +22,11 @@ namespace StudySystemClient {
refreshing_indicator.show();
try {
var activities = yield client.list_activities();
card_container.remove_all();
card_area.clear();
foreach (var activity in activities) {
var card = new ActivityCard(activity);
card.session_logged.connect(log_session);
card_container.append(card);
card_area.add(card);
}
} catch (ClientError e) {
stderr.printf("Error refreshing activities: %s\n",

View File

@ -1,10 +1,10 @@
namespace StudySystemClient {
public class ActivityCard : Gtk.Frame {
public class ActivityCard : Card {
public signal void session_logged(string subject, ActivityType type,
int minutes);
public ActivityCard(Activity activity) {
add_css_class("card");
base();
var subject = new Gtk.Label(activity.subject);
subject.halign = Gtk.Align.START;

40
client/src/card.vala Normal file
View File

@ -0,0 +1,40 @@
namespace StudySystemClient {
public class Card : Gtk.Frame {
public Card() {
hexpand = true;
add_css_class("card");
}
}
public class CardArea : Gtk.Box {
private Gtk.FlowBox flow_box;
public CardArea() {
hexpand = vexpand = true;
margin_top = margin_bottom = margin_start = margin_end = 0;
flow_box = new Gtk.FlowBox();
flow_box.homogeneous = true;
flow_box.min_children_per_line = 1;
flow_box.max_children_per_line = 1;
flow_box.selection_mode = Gtk.SelectionMode.NONE;
flow_box.valign = Gtk.Align.START;
var scrolled_window = new Gtk.ScrolledWindow();
scrolled_window.hscrollbar_policy = Gtk.PolicyType.NEVER;
scrolled_window.hexpand = scrolled_window.vexpand = true;
scrolled_window.add_css_class("card-container");
scrolled_window.set_child(flow_box);
append(scrolled_window);
}
public void clear() {
flow_box.remove_all();
}
public void add(Card card) {
flow_box.append(card);
}
}
}

View File

@ -13,6 +13,7 @@ lib = library(
'activities_view.vala',
'activity.vala',
'activity_card.vala',
'card.vala',
'client.vala',
'connection.vala',
'der.vala',