Skip to content

Commit 4580c46

Browse files
committed
demo: Init small demo of Tenfoot
1 parent 59385c9 commit 4580c46

8 files changed

+442
-0
lines changed

Diff for: demo/meson.build

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
project(
2+
'fabric-tenfoot-demo',
3+
'vala', 'c',
4+
version: '0.1'
5+
)
6+
7+
vapi_dir = meson.current_source_dir() / 'vapi'
8+
add_project_arguments(['--vapidir', vapi_dir], language: 'vala')
9+
10+
dependencies = [
11+
meson.get_compiler('vala').find_library('linux'),
12+
dependency('gtk4'),
13+
dependency('fabric-ui', fallback:['fabric-ui', 'fabric_ui_dep']),
14+
dependency('fabric-tenfoot', fallback:['fabric-tenfoot', 'fabric_tenfoot_dep']),
15+
]
16+
17+
sources = []
18+
19+
# Add data for use at runtime
20+
conf = configuration_data()
21+
conf.set_quoted('VERSION', meson.project_version())
22+
conf.set('bindir', join_paths(get_option('prefix'), 'bin'))
23+
24+
configure_file(output: 'config.h', configuration: conf)
25+
config_h_dir = include_directories('.')
26+
27+
# Call subdirs
28+
subdir('src')

Diff for: demo/src/main.vala

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Fabric.Tenfoot;
2+
3+
// Make it so we're not a sub-namespace, and thus more privileged in scope.
4+
namespace FabricDemo.Tenfoot {
5+
class Application : Fabric.Tenfoot.Application {
6+
construct {
7+
application_id = "demo.fabric.tenfoot";
8+
}
9+
10+
protected override void activate() {
11+
base.activate();
12+
13+
var container = Fabric.UI.PagesContainer.instance;
14+
container.push(Pages.Welcome.instance);
15+
16+
GlobalMenu.instance.add_item("open-test-page", "Open test page").activate.connect(() => {
17+
GlobalMenu.instance.hide();
18+
container.push(Pages.Test.instance);
19+
});
20+
GlobalMenu.instance.add_item("quit", "Quit").activate.connect(() => {
21+
Process.exit(0);
22+
});
23+
24+
window = new Fabric.UI.PagedWindow() {
25+
title = "Fabric Tenfoot — Demo",
26+
application = this,
27+
};
28+
window.present();
29+
}
30+
}
31+
32+
public static int main(string[] args) {
33+
return (new Application()).run(args);
34+
}
35+
}

Diff for: demo/src/meson.build

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
sources += files(
2+
'main.vala',
3+
)
4+
5+
subdir('pages')
6+
7+
executable(
8+
meson.project_name(),
9+
[sources],
10+
dependencies: dependencies,
11+
c_args: [
12+
'-include', 'config.h'
13+
],
14+
vala_args: [
15+
'--vapidir', join_paths(meson.current_source_dir(), 'vapi'),
16+
],
17+
install: true,
18+
)

Diff for: demo/src/pages/base_page.vala

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Fabric.Tenfoot;
2+
3+
namespace FabricDemo.Tenfoot.Pages {
4+
// Move to Fabric.Tenfoot.BasePage
5+
class Base : Fabric.UI.ScrollingPage, ContextualWidget {
6+
construct {
7+
// Hook the back action to the intrinsic `go_back` action.
8+
contextual_action_add("gamepad.back", "Back")
9+
.activate.connect(this.go_back)
10+
;
11+
}
12+
13+
public override bool grab_focus() {
14+
scroll_to_top();
15+
16+
return true;
17+
}
18+
}
19+
}

Diff for: demo/src/pages/meson.build

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
sources += files(
2+
'base_page.vala',
3+
'test_page.vala',
4+
'welcome_page.vala',
5+
'widgets_playground_page.vala',
6+
)

Diff for: demo/src/pages/test_page.vala

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Fabric.UI.Helpers;
2+
3+
namespace FabricDemo.Tenfoot.Pages {
4+
class Test : Base {
5+
public static Test instance {
6+
owned get { return new Test(); }
7+
}
8+
private Test() {}
9+
10+
construct {
11+
add_css_class("page-test");
12+
append(make_subheading("Test page"));
13+
append(make_text(""));
14+
append(make_text("Hello!"));
15+
}
16+
}
17+
}

Diff for: demo/src/pages/welcome_page.vala

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Fabric.Tenfoot;
2+
using Fabric.UI.Helpers;
3+
4+
namespace FabricDemo.Tenfoot.Pages {
5+
class Welcome : Base {
6+
private static GLib.Once<Welcome> _instance;
7+
public static unowned Welcome instance {
8+
get { return _instance.once(() => { return new Welcome(); }); }
9+
}
10+
private Welcome() {}
11+
12+
construct {
13+
add_css_class("page-welcome");
14+
15+
append(make_subheading("Welcome to the Fabric Tenfoot Demo!"));
16+
append(make_text(""));
17+
append(make_text("Don't be alarmed, this application is barely useful."));
18+
append(make_text(""));
19+
append(make_text("You'll likely want to use the global menu, or one of the following actions next."));
20+
append(make_text(""));
21+
22+
23+
// By virtue of being the first and only button, it cheaply makes
24+
// it the default action for the global actions.
25+
// It's better than overriding actions, as the focus on the button
26+
// shows what is going to happen.
27+
var button = new Button() {
28+
halign = Gtk.Align.START,
29+
};
30+
button.label = "Continue to the widgets playground";
31+
button.clicked.connect(() => {
32+
var container = Fabric.UI.PagesContainer.instance;
33+
container.push(new Pages.WidgetsPlayground());
34+
});
35+
append(button);
36+
37+
38+
// We're making this the "root" first of the app, and instead of disabling
39+
// the back action, which would be the default, we'll instead show the menu.
40+
var back = contextual_action_for("gamepad.back");
41+
back.activate.disconnect(this.go_back);
42+
back.activate.connect(() => {
43+
GlobalMenu.activate_menu_action("_show");
44+
});
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)