74 lines
2.3 KiB
Vala
74 lines
2.3 KiB
Vala
|
|
using Adw;
|
||
|
|
using Gtk;
|
||
|
|
|
||
|
|
public class MessageListView : Adw.Bin
|
||
|
|
{
|
||
|
|
private Adw.ToolbarView container;
|
||
|
|
|
||
|
|
private MessageDrawingArea message_drawing_area = new MessageDrawingArea();
|
||
|
|
private ScrolledWindow scrolled_window = new ScrolledWindow();
|
||
|
|
|
||
|
|
public MessageListView(MessageListModel model) {
|
||
|
|
container = new Adw.ToolbarView();
|
||
|
|
set_child(container);
|
||
|
|
|
||
|
|
scrolled_window.set_child(message_drawing_area);
|
||
|
|
scrolled_window.add_css_class("message-list-scroller");
|
||
|
|
container.set_content(scrolled_window);
|
||
|
|
|
||
|
|
var header_bar = new Adw.HeaderBar();
|
||
|
|
header_bar.set_title_widget(new Label("Messages"));
|
||
|
|
container.add_top_bar(header_bar);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
private class MessageDrawingArea : Widget {
|
||
|
|
public MessageDrawingArea() {
|
||
|
|
}
|
||
|
|
|
||
|
|
public override SizeRequestMode get_request_mode() {
|
||
|
|
return SizeRequestMode.HEIGHT_FOR_WIDTH;
|
||
|
|
}
|
||
|
|
|
||
|
|
public override void measure(Orientation orientation, int for_size, out int minimum, out int natural, out int minimum_baseline, out int natural_baseline) {
|
||
|
|
GLib.message("Measure orientation: %s, for_size: %d", orientation.to_string(), for_size);
|
||
|
|
|
||
|
|
if (orientation == Orientation.HORIZONTAL) {
|
||
|
|
// Horizontal, so we take up the full width provided
|
||
|
|
minimum = 0;
|
||
|
|
natural = for_size;
|
||
|
|
} else {
|
||
|
|
GLib.message("Vertical measure for width: %d", for_size);
|
||
|
|
minimum = 1500;
|
||
|
|
natural = 1500;
|
||
|
|
}
|
||
|
|
|
||
|
|
minimum_baseline = -1;
|
||
|
|
natural_baseline = -1;
|
||
|
|
}
|
||
|
|
|
||
|
|
public override void snapshot(Snapshot snapshot) {
|
||
|
|
var width = get_width();
|
||
|
|
var height = get_height();
|
||
|
|
|
||
|
|
GLib.message("Snapshot width: %d, height: %d", width, height);
|
||
|
|
|
||
|
|
var rect = Graphene.Rect().init(0, 0, width, height);
|
||
|
|
snapshot.append_color({1.0f, 0.0f, 0.0f, 1.0f}, rect);
|
||
|
|
|
||
|
|
// Create a text layout
|
||
|
|
var layout = create_pango_layout("Hello World!");
|
||
|
|
layout.set_width(width * Pango.SCALE);
|
||
|
|
|
||
|
|
// Set text attributes
|
||
|
|
var font_desc = Pango.FontDescription.from_string("Sans 14");
|
||
|
|
layout.set_font_description(font_desc);
|
||
|
|
|
||
|
|
// Draw the text in white
|
||
|
|
snapshot.append_layout(layout, Gdk.RGBA() { red = 1.0f, green = 1.0f, blue = 1.0f, alpha = 1.0f });
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|