|
Packit |
1470ea |
#!/usr/bin/gjs
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
imports.gi.versions.Gtk = '3.0';
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
const GObject = imports.gi.GObject;
|
|
Packit |
1470ea |
const Gtk = imports.gi.Gtk;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class ScrolledWindowExample {
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Create the application itself
|
|
Packit |
1470ea |
constructor() {
|
|
Packit |
1470ea |
this.application = new Gtk.Application({
|
|
Packit |
1470ea |
application_id: 'org.example.jscrolledwindow'
|
|
Packit |
1470ea |
});
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Connect 'activate' and 'startup' signals to the callback functions
|
|
Packit |
1470ea |
this.application.connect('activate', this._onActivate.bind(this));
|
|
Packit |
1470ea |
this.application.connect('startup', this._onStartup.bind(this));
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Callback function for 'activate' signal presents windows when active
|
|
Packit |
1470ea |
_onActivate() {
|
|
Packit |
1470ea |
this.window.present();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Callback function for 'startup' signal builds the UI
|
|
Packit |
1470ea |
_onStartup() {
|
|
Packit |
1470ea |
this._buildUI();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Build the application's UI
|
|
Packit |
1470ea |
_buildUI() {
|
|
Packit |
1470ea |
// Create the application window
|
|
Packit |
1470ea |
this.window = new Gtk.ApplicationWindow({
|
|
Packit |
1470ea |
application: this.application,
|
|
Packit |
1470ea |
window_position: Gtk.WindowPosition.CENTER,
|
|
Packit |
1470ea |
title: "ScrolledWindow Example",
|
|
Packit |
1470ea |
default_width: 200,
|
|
Packit |
1470ea |
default_height: 200,
|
|
Packit |
1470ea |
border_width: 10
|
|
Packit |
1470ea |
});
|
|
Packit |
1470ea |
// the scrolledwindow
|
|
Packit |
1470ea |
this.scrolledWindow = new Gtk.ScrolledWindow();
|
|
Packit |
1470ea |
this.scrolledWindow.set_border_width(10);
|
|
Packit |
1470ea |
// there is always the scrollbar (otherwise: AUTOMATIC - only if needed - or NEVER)
|
|
Packit |
1470ea |
this.scrolledWindow.set_policy(Gtk.PolicyType.ALWAYS, Gtk.PolicyType.ALWAYS);
|
|
Packit |
1470ea |
// an image - slightly larger than the window
|
|
Packit |
1470ea |
this.image = new Gtk.Image();
|
|
Packit |
1470ea |
this.image.set_from_file("gnome-image.png");
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// add the image to the scrolledwindow
|
|
Packit |
1470ea |
this.scrolledWindow.add_with_viewport(this.image);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// add the scrolledwindow to the window
|
|
Packit |
1470ea |
this.window.add(this.scrolledWindow);
|
|
Packit |
1470ea |
this.window.show_all();
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
};
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
// Run the application
|
|
Packit |
1470ea |
let app = new ScrolledWindowExample();
|
|
Packit |
1470ea |
app.application.run (ARGV);
|