Skip to content

Commit

Permalink
for #410 - getting more of emeus merged into Shoes layout.
Browse files Browse the repository at this point in the history
* It compiles and links and runs but doesn't do much visually.
  • Loading branch information
Cecil committed Nov 7, 2018
1 parent ae75958 commit ff50eeb
Show file tree
Hide file tree
Showing 17 changed files with 809 additions and 72 deletions.
2 changes: 1 addition & 1 deletion Tests/layout/cs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def initialize(identifier)

# Button1's preferred width is 87
solver.add_constraint(b1.width.cn_equal 87, Strength::StrongStrength)
puts "b1: #{b1.inspect}"

# Button2's minimum width is 113
solver.add_constraint(b2.width.cn_geq 113)

Expand Down
8 changes: 5 additions & 3 deletions Tests/layout/vfl3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
"V:|-[but1(but2,but3)]-[but2]-[but3]-|"
]
if @lay.vfl_parse lines: lines, metrics: metrics
constraints = @lay.vfl_constraints
constraints = @lay.vfl_constraints #true # true produces hash
# display purposes only?
constraints.each { |c| $stderr.puts c.inspect }
#constraints.each { |c| $stderr.puts c.inspect }
#@lay.vfl_append constraints[10]
@lay.finish constraints
end
}
end
para "After layout"
#cs = Shoes::Constraint.new 'but1','width', 'eq', 'but3', 'width', 1, 8.0, 1001001000
#para "#{cs.inspect}"
end
1 change: 0 additions & 1 deletion shoes/canvas.c
Original file line number Diff line number Diff line change
Expand Up @@ -1449,4 +1449,3 @@ VALUE shoes_canvas_dialog_plain(VALUE self) {
SETUP_CANVAS();
return shoes_native_dialog_color(canvas->app);
}

1 change: 1 addition & 0 deletions shoes/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ VALUE shoes_canvas_stack(int, VALUE *, VALUE);
VALUE shoes_canvas_mask(int, VALUE *, VALUE);
VALUE shoes_canvas_widget(int, VALUE *, VALUE);
VALUE shoes_canvas_layout(int, VALUE *, VALUE);
VALUE shoes_canvas_cassowary_constraint(int, VALUE *, VALUE);
VALUE shoes_canvas_hide(VALUE);
VALUE shoes_canvas_show(VALUE);
VALUE shoes_canvas_toggle(VALUE);
Expand Down
13 changes: 9 additions & 4 deletions shoes/layout/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@

#define GETTEXT_PACKAGE PACKAGE_NAME

#define HAVE_STDBOOL_H
#ifndef HAVE_STDBOOL_H
//#define HAVE_STDBOOL_H
#endif

#define HAVE_STDINT_H

#define HAVE_STDLIB_H
#ifndef HAVE_STDINT_H
//#define HAVE_STDINT_H
#endif

#ifndef HAVE_STDLIB_H
//#define HAVE_STDLIB_H
#endif
#define LOCALEDIR PACKAGE_LOCALE_DIR

#define PACKAGE_DATADIR "/usr/local/share"
Expand Down
17 changes: 11 additions & 6 deletions shoes/layout/emeus-constraint.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
*/

#include "config.h"
#include "shoes/layout/layouts.h"
#include "shoes/layout/shoes-vfl.h"
#include "emeus-constraint-private.h"

#include "emeus-expression-private.h"
Expand Down Expand Up @@ -218,7 +218,8 @@ emeus_constraint_class_init (EmeusConstraintClass *klass)
*/
emeus_constraint_properties[PROP_TARGET_OBJECT] =
g_param_spec_object ("target-object", "Target Object", NULL,
GTK_TYPE_WIDGET,
GSHOES_TYPE_ELE,
// GTK_TYPE_WIDGET,
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
Expand Down Expand Up @@ -264,7 +265,8 @@ emeus_constraint_class_init (EmeusConstraintClass *klass)
*/
emeus_constraint_properties[PROP_SOURCE_OBJECT] =
g_param_spec_object ("source-object", "Source Object", NULL,
GTK_TYPE_WIDGET,
//GTK_TYPE_WIDGET,
GSHOES_TYPE_ELE,
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
Expand Down Expand Up @@ -396,8 +398,10 @@ emeus_constraint_new (gpointer target_object,
double constant,
int strength)
{
g_return_val_if_fail (target_object == NULL || GTK_IS_WIDGET (target_object), NULL);
g_return_val_if_fail (source_object == NULL || GTK_IS_WIDGET (source_object), NULL);
//g_return_val_if_fail (target_object == NULL || GTK_IS_WIDGET (target_object), NULL);
//g_return_val_if_fail (source_object == NULL || GTK_IS_WIDGET (source_object), NULL);
g_return_val_if_fail (target_object == NULL || GSHOES_IS_ELE (target_object), NULL);
g_return_val_if_fail (source_object == NULL || GSHOES_IS_ELE (source_object), NULL);

return g_object_new (EMEUS_TYPE_CONSTRAINT,
"target-object", target_object,
Expand Down Expand Up @@ -439,7 +443,8 @@ emeus_constraint_new_constant (gpointer target_object,
double constant,
int strength)
{
g_return_val_if_fail (target_object == NULL || GTK_IS_WIDGET (target_object), NULL);
//g_return_val_if_fail (target_object == NULL || GTK_IS_WIDGET (target_object), NULL);
g_return_val_if_fail (target_object == NULL || GSHOES_IS_ELE (target_object), NULL);

return g_object_new (EMEUS_TYPE_CONSTRAINT,
"target-object", target_object,
Expand Down
11 changes: 6 additions & 5 deletions shoes/layout/emeus-constraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ EmeusConstraint *emeus_constraint_new_constant (gpointer target_object,
int strength);

extern
gpointer emeus_constraint_get_target_object(EmeusConstraint *constraint);
gpointer emeus_constraint_get_target_object(EmeusConstraint *constraint);
extern
EmeusConstraintAttribute emeus_constraint_get_target_attribute (EmeusConstraint *constraint);
extern
Expand All @@ -73,12 +73,13 @@ extern
gboolean emeus_constraint_is_required (EmeusConstraint *constraint);

extern
gboolean emeus_constraint_is_attached (EmeusConstraint *constraint);
gboolean emeus_constraint_is_attached (EmeusConstraint *constraint);

extern
void emeus_constraint_set_active (EmeusConstraint *constraint,
void emeus_constraint_set_active (EmeusConstraint *constraint,
gboolean active);
extern
gboolean emeus_constraint_get_active(EmeusConstraint *constraint);

gboolean emeus_constraint_get_active(EmeusConstraint *constraint);
const char *
emeus_constraint_to_string (EmeusConstraint *constraint);
G_END_DECLS
132 changes: 132 additions & 0 deletions shoes/layout/gshoes-ele.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#include "gshoes-ele.h"

/*
* Thin GObject Wrapper for Shoes elements (widgets, textblocks...)
/* Private structure definition. */
typedef struct {
gchar *name; // Private not needed?
/* stuff */
} GshoesElePrivate;

/*
* forward definitions
*/
static void
gshoes_ele_set_property (GObject *gobject,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void
gshoes_ele_get_property (GObject *gobject,
guint prop_id,
GValue *value,
GParamSpec *pspec);

struct _GshoesEle
{
GObject parent_instance;

gpointer element; // It's a Ruby VALUE
const gchar *name; // for debugging help?

};

G_DEFINE_TYPE (GshoesEle, gshoes_ele, G_TYPE_OBJECT)

enum
{
PROP_ELEMENT = 1,
PROP_NAME,
N_PROPERTIES
};

static GParamSpec *gshoes_ele_properties[N_PROPERTIES] = { NULL, };

static void
gshoes_ele_class_init (GshoesEleClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);

object_class->set_property = gshoes_ele_set_property;
object_class->get_property = gshoes_ele_get_property;

gshoes_ele_properties[PROP_ELEMENT] =
g_param_spec_pointer ("element",
"Element",
"Shoes drawable element/widget.",
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
gshoes_ele_properties[PROP_NAME] =
g_param_spec_string ("name",
"Name",
"Layout name of the widget.",
NULL /* default value */,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);

// need to define other properties here - which ones? GtkWidgets?

g_object_class_install_properties (object_class,
N_PROPERTIES,
gshoes_ele_properties);
}

static void
gshoes_ele_init (GshoesEle *self)
{
//GShoesElePrivate *priv = gshoes_ele_get_instance_private (self);

/* initialize all public and private members to reasonable default values.
* They are all automatically initialized to 0 to begin with. */
}

static void
gshoes_ele_set_property (GObject *gobject,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GshoesEle *self = GSHOES_ELE (gobject);
switch (prop_id) {
case PROP_ELEMENT:
self->element = g_value_get_pointer (value);
break;
case PROP_NAME:
self->name = g_value_get_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
}
}

static void
gshoes_ele_get_property (GObject *gobject,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GshoesEle *self = GSHOES_ELE (gobject);
switch (prop_id) {
case PROP_ELEMENT:
g_value_set_pointer (value, self->element);
break;
case PROP_NAME:
g_value_set_string (value, self->name);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
}
}

GshoesEle *gshoes_ele_new(GString *str, gpointer *ele) {
return g_object_new (GSHOES_TYPE_ELE,
"name", str,
"element", ele,
NULL);
}

gpointer gshoes_ele_get_element(GshoesEle *gs) {
g_return_val_if_fail (GSHOES_IS_ELE (gs), NULL);

return gs->element;

}
19 changes: 19 additions & 0 deletions shoes/layout/gshoes-ele.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <glib-object.h>

G_BEGIN_DECLS
/*
* Type declaration.
*/

#define GSHOES_TYPE_ELE (gshoes_ele_get_type())

G_DECLARE_FINAL_TYPE (GshoesEle, gshoes_ele, GSHOES, ELE, GObject)

/*
* Method definitions.
*/
extern GshoesEle *gshoes_ele_new(GString *str, gpointer *ele);
extern gpointer gshoes_ele_get_element(GshoesEle *gs);
G_END_DECLS
6 changes: 3 additions & 3 deletions shoes/layout/shoes-vfl-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "shoes/types/types.h"
#include "shoes/types/settings.h"
#include "shoes/types/layout.h"
#include "shoes/layout/layouts.h"
#include "shoes/layout/shoes-vfl.h"

#include "shoes/layout/emeus-vfl-parser-private.h"
// Test data from emeus/examples/simple-grid.c
Expand Down Expand Up @@ -85,7 +85,7 @@ void print_constraint(VflConstraint *c) {

extern ID s_name;

static VALUE wrap_constraint(VflConstraint *c) {
VALUE shoes_vfl_wrap_constraint(VflConstraint *c) {
VALUE hsh = rb_hash_new();
VALUE val, key;
key = ID2SYM(rb_intern("view1"));
Expand Down Expand Up @@ -234,7 +234,7 @@ VALUE shoes_vfl_rules(shoes_layout *lay, shoes_canvas *canvas, VALUE args) {
//fprintf(stderr, "n_constraints: %d\n", n_constraints);
for (int i = 0; i < n_constraints; i++) {
VflConstraint *c = &constraints[i];
rb_ary_push(lay->rbconstraints, wrap_constraint(c));
rb_ary_push(lay->rbconstraints, shoes_vfl_wrap_constraint(c));
}
}
}
Expand Down
Loading

0 comments on commit ff50eeb

Please sign in to comment.