Extract Card and CardArea classes
This commit is contained in:
parent
94df48db7b
commit
c2d81778a8
@ -1,37 +1,16 @@
|
|||||||
namespace StudySystemClient {
|
namespace StudySystemClient {
|
||||||
public class ActivitiesView : Gtk.Box {
|
public class ActivitiesView : Gtk.Box {
|
||||||
private Client client;
|
private Client client;
|
||||||
private Gtk.FlowBox card_container;
|
|
||||||
private RefreshingIndicator refreshing_indicator;
|
private RefreshingIndicator refreshing_indicator;
|
||||||
|
private CardArea card_area;
|
||||||
|
|
||||||
public ActivitiesView(Client client) {
|
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;
|
this.client = client;
|
||||||
|
card_area = new CardArea();
|
||||||
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);
|
|
||||||
|
|
||||||
var overlay = new Gtk.Overlay();
|
var overlay = new Gtk.Overlay();
|
||||||
overlay.hexpand = overlay.vexpand = true;
|
overlay.hexpand = overlay.vexpand = true;
|
||||||
overlay.set_child(scrolled_window);
|
overlay.set_child(card_area);
|
||||||
this.append(overlay);
|
this.append(overlay);
|
||||||
|
|
||||||
refreshing_indicator = new RefreshingIndicator(overlay);
|
refreshing_indicator = new RefreshingIndicator(overlay);
|
||||||
@ -43,11 +22,11 @@ namespace StudySystemClient {
|
|||||||
refreshing_indicator.show();
|
refreshing_indicator.show();
|
||||||
try {
|
try {
|
||||||
var activities = yield client.list_activities();
|
var activities = yield client.list_activities();
|
||||||
card_container.remove_all();
|
card_area.clear();
|
||||||
foreach (var activity in activities) {
|
foreach (var activity in activities) {
|
||||||
var card = new ActivityCard(activity);
|
var card = new ActivityCard(activity);
|
||||||
card.session_logged.connect(log_session);
|
card.session_logged.connect(log_session);
|
||||||
card_container.append(card);
|
card_area.add(card);
|
||||||
}
|
}
|
||||||
} catch (ClientError e) {
|
} catch (ClientError e) {
|
||||||
stderr.printf("Error refreshing activities: %s\n",
|
stderr.printf("Error refreshing activities: %s\n",
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
namespace StudySystemClient {
|
namespace StudySystemClient {
|
||||||
public class ActivityCard : Gtk.Frame {
|
public class ActivityCard : Card {
|
||||||
public signal void session_logged(string subject, ActivityType type,
|
public signal void session_logged(string subject, ActivityType type,
|
||||||
int minutes);
|
int minutes);
|
||||||
|
|
||||||
public ActivityCard(Activity activity) {
|
public ActivityCard(Activity activity) {
|
||||||
add_css_class("card");
|
base();
|
||||||
|
|
||||||
var subject = new Gtk.Label(activity.subject);
|
var subject = new Gtk.Label(activity.subject);
|
||||||
subject.halign = Gtk.Align.START;
|
subject.halign = Gtk.Align.START;
|
||||||
|
40
client/src/card.vala
Normal file
40
client/src/card.vala
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -13,6 +13,7 @@ lib = library(
|
|||||||
'activities_view.vala',
|
'activities_view.vala',
|
||||||
'activity.vala',
|
'activity.vala',
|
||||||
'activity_card.vala',
|
'activity_card.vala',
|
||||||
|
'card.vala',
|
||||||
'client.vala',
|
'client.vala',
|
||||||
'connection.vala',
|
'connection.vala',
|
||||||
'der.vala',
|
'der.vala',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user