| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- MODULE test_constraints ;
- (*
- m2-GTK4 test - GtkConstraintLayout, GtkConstraint and
- GtkConstraintGuide. Requires a display.
- *)
- FROM Gio IMPORT g_application_run, g_application_quit;
- FROM GtkApplication IMPORT gtk_application_new;
- FROM GtkWindow IMPORT gtk_application_window_new, gtk_window_set_child,
- gtk_window_present;
- FROM GtkLabel IMPORT gtk_label_new;
- FROM GtkWidget IMPORT gtk_widget_set_parent, gtk_widget_set_layout_manager;
- FROM M2GtkShim IMPORT m2_gtk_widget_new;
- FROM GtkConstraintLayout IMPORT gtk_constraint_layout_new,
- gtk_constraint_layout_add_constraint, gtk_constraint_layout_add_guide,
- gtk_constraint_layout_remove_all_constraints;
- FROM GtkConstraint IMPORT gtk_constraint_new, gtk_constraint_new_constant,
- GtkConstraintAttributeWidth, GtkConstraintAttributeHeight,
- GtkConstraintRelationEq, GtkConstraintStrengthRequired;
- FROM GtkConstraintGuide IMPORT gtk_constraint_guide_new,
- gtk_constraint_guide_set_min_size, gtk_constraint_guide_get_min_size,
- gtk_constraint_guide_set_strength, gtk_constraint_guide_set_name,
- gtk_constraint_guide_get_name;
- FROM GtkUtils IMPORT Connect, CStrToM2;
- FROM SYSTEM IMPORT ADDRESS, ADR;
- FROM libc IMPORT printf;
- CONST
- AppId = "org.example.m2gtk4.TestConstraints";
- VAR
- app: ADDRESS;
- passed: BOOLEAN;
- PROCEDURE OnActivate (application: ADDRESS; data: ADDRESS);
- VAR
- window, parent, layout, label, c1, c2, guide: ADDRESS;
- gw, gh: INTEGER;
- buf: ARRAY [0..31] OF CHAR;
- ok: BOOLEAN;
- BEGIN
- ok := TRUE;
- layout := gtk_constraint_layout_new();
- IF layout = NIL THEN printf("layout NIL\n"); ok := FALSE END;
- parent := m2_gtk_widget_new(NIL, NIL, NIL);
- gtk_widget_set_layout_manager(parent, layout);
- label := gtk_label_new("constrained");
- gtk_widget_set_parent(label, parent);
- c1 := gtk_constraint_new(label, GtkConstraintAttributeWidth,
- GtkConstraintRelationEq, NIL, 0,
- 1.0, 100.0, GtkConstraintStrengthRequired);
- IF c1 = NIL THEN printf("constraint NIL\n"); ok := FALSE END;
- gtk_constraint_layout_add_constraint(layout, c1);
- c2 := gtk_constraint_new_constant(label, GtkConstraintAttributeHeight,
- GtkConstraintRelationEq, 40.0,
- GtkConstraintStrengthRequired);
- gtk_constraint_layout_add_constraint(layout, c2);
- guide := gtk_constraint_guide_new();
- gtk_constraint_guide_set_min_size(guide, 50, 20);
- gtk_constraint_guide_get_min_size(guide, gw, gh);
- IF (gw # 50) OR (gh # 20) THEN
- printf("guide min size wrong: %d x %d\n", gw, gh); ok := FALSE
- END;
- gtk_constraint_guide_set_strength(guide, 1);
- gtk_constraint_guide_set_name(guide, "g1");
- CStrToM2(gtk_constraint_guide_get_name(guide), buf);
- IF (buf[0] # 'g') OR (buf[1] # '1') OR (buf[2] # 0C) THEN
- printf("guide name wrong: [%s]\n", buf); ok := FALSE
- END;
- gtk_constraint_layout_add_guide(layout, guide);
- window := gtk_application_window_new(application);
- gtk_window_set_child(window, parent);
- gtk_window_present(window);
- gtk_constraint_layout_remove_all_constraints(layout);
- passed := ok;
- g_application_quit(application)
- END OnActivate;
- VAR
- rc: INTEGER;
- BEGIN
- passed := FALSE;
- app := gtk_application_new(AppId, 0);
- IF app = NIL THEN
- printf("test_constraints: FAIL (no app)\n");
- HALT(1)
- END;
- Connect(app, "activate", ADR(OnActivate), NIL);
- rc := g_application_run(app, 0, NIL);
- IF passed THEN
- printf("test_constraints: PASS\n");
- HALT(0)
- ELSE
- printf("test_constraints: FAIL\n");
- HALT(1)
- END
- END test_constraints.
|