示例#1
0
文件: webkit.go 项目: lamproae/hgui
func startGui(width, height int, title string, port int) {
	C.gtk_init(nil, nil) //gtk.Init(nil)

	window := C.window
	window = C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL)
	C.gtk_window_set_title(C.to_GtkWindow(window), C.to_gcharptr(C.CString(title)))
	C.connect_destroy(window)

	vbox := C.gtk_hbox_new(0, 1)

	C.webview = C._new_webkit()

	C.gtk_container_add(C.to_GtkContainer(vbox), C.webview)

	C.loadUri(C.webview, C.to_gcharptr(C.CString(fmt.Sprintf("http://127.0.0.1:%d", port))))

	C.gtk_container_add(C.to_GtkContainer(window), vbox)
	C.gtk_widget_set_size_request(window, C.gint(width), C.gint(height))

	C.gtk_widget_show(vbox)
	C.gtk_widget_show(window) //Window.ShowAll()
	C.gtk_widget_show(C.webview)

	/*
		This only matters if proxy is stupid!
		proxy := os.Getenv("HTTP_PROXY")
		if len(proxy) > 0 {
			ptr := C.CString(uri)
			C.proxyshit(ptr)
			C.free(ptr)
		}
	*/

	C.gtk_main() //gtk.GtkMain()
}
示例#2
0
func newScroller(widget *C.GtkWidget, native bool, bordered bool, overlay bool) *scroller {
	var o *C.GtkWidget

	scrollwidget := C.gtk_scrolled_window_new(nil, nil)
	if overlay {
		o = C.gtk_overlay_new()
	}
	s := &scroller{
		scrollwidget:     scrollwidget,
		scrollcontainer:  (*C.GtkContainer)(unsafe.Pointer(scrollwidget)),
		scrollwindow:     (*C.GtkScrolledWindow)(unsafe.Pointer(scrollwidget)),
		overlaywidget:    o,
		overlaycontainer: (*C.GtkContainer)(unsafe.Pointer(o)),
		overlay:          (*C.GtkOverlay)(unsafe.Pointer(o)),
	}
	// give the scrolled window a border (thanks to jlindgren in irc.gimp.net/#gtk+)
	if bordered {
		C.gtk_scrolled_window_set_shadow_type(s.scrollwindow, C.GTK_SHADOW_IN)
	}
	if native {
		C.gtk_container_add(s.scrollcontainer, widget)
	} else {
		C.gtk_scrolled_window_add_with_viewport(s.scrollwindow, widget)
	}
	s.addShowWhich = s.scrollwidget
	if overlay {
		C.gtk_container_add(s.overlaycontainer, s.scrollwidget)
		s.addShowWhich = s.overlaywidget
	}
	return s
}
示例#3
0
文件: gtk.go 项目: kayon/cef2go
func CreateWindow(title string, width int, height int) unsafe.Pointer {
	Logger.Println("CreateWindow")

	// Create window.
	window := C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL)

	// Default size.
	C.gtk_window_set_default_size(C.ToGtkWindow(window),
		C.gint(width), C.gint(height))

	// Center.
	C.gtk_window_set_position(C.ToGtkWindow(window), C.GTK_WIN_POS_CENTER)

	// Title.
	csTitle := C.CString(title)
	defer C.free(unsafe.Pointer(csTitle))
	C.gtk_window_set_title(C.ToGtkWindow(window), (*C.gchar)(csTitle))

	// TODO: focus
	// g_signal_connect(window, "focus", G_CALLBACK(&HandleFocus), NULL);

	// CEF requires a container. Embedding browser in a top
	// level window fails.
	vbox := C.gtk_vbox_new(0, 0)
	C.gtk_container_add(C.ToGtkContainer(window), vbox)

	// Show.
	C.gtk_widget_show_all(window)

	return unsafe.Pointer(vbox)
}
示例#4
0
文件: group_unix.go 项目: sjn1978/ui
func newGroup(text string, control Control) Group {
	ctext := togstr(text)
	defer freegstr(ctext)
	widget := C.gtk_frame_new(ctext)
	g := &group{
		controlSingleWidget: newControlSingleWidget(widget),
		gcontainer:          (*C.GtkContainer)(unsafe.Pointer(widget)),
		frame:               (*C.GtkFrame)(unsafe.Pointer(widget)),
		child:               control,
	}

	// with GTK+, groupboxes by default have frames and slightly x-offset regular text
	// they should have no frame and fully left-justified, bold text
	var yalign C.gfloat

	// preserve default y-alignment
	C.gtk_frame_get_label_align(g.frame, nil, &yalign)
	C.gtk_frame_set_label_align(g.frame, 0, yalign)
	C.gtk_frame_set_shadow_type(g.frame, C.GTK_SHADOW_NONE)
	label := (*C.GtkLabel)(unsafe.Pointer(C.gtk_frame_get_label_widget(g.frame)))
	// this is the boldness level used by GtkPrintUnixDialog
	// (it technically uses "bold" but see pango's pango-enum-types.c for the name conversion; GType is weird)
	bold := C.pango_attr_weight_new(C.PANGO_WEIGHT_BOLD)
	boldlist := C.pango_attr_list_new()
	C.pango_attr_list_insert(boldlist, bold)
	C.gtk_label_set_attributes(label, boldlist)
	C.pango_attr_list_unref(boldlist) // thanks baedert in irc.gimp.net/#gtk+

	g.container = newContainer()
	g.child.setParent(g.container.parent())
	g.container.resize = g.child.resize
	C.gtk_container_add(g.gcontainer, g.container.widget)

	return g
}
示例#5
0
文件: window_unix.go 项目: sjn1978/ui
func newWindow(title string, width int, height int, control Control) *window {
	widget := C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL)
	ctitle := togstr(title)
	defer freegstr(ctitle)
	w := &window{
		widget:  widget,
		wc:      (*C.GtkContainer)(unsafe.Pointer(widget)),
		bin:     (*C.GtkBin)(unsafe.Pointer(widget)),
		window:  (*C.GtkWindow)(unsafe.Pointer(widget)),
		closing: newEvent(),
		child:   control,
	}
	C.gtk_window_set_title(w.window, ctitle)
	g_signal_connect(
		C.gpointer(unsafe.Pointer(w.window)),
		"delete-event",
		C.GCallback(C.windowClosing),
		C.gpointer(unsafe.Pointer(w)))
	C.gtk_window_resize(w.window, C.gint(width), C.gint(height))
	w.container = newContainer()
	w.child.setParent(w.container.parent())
	w.container.resize = w.child.resize
	C.gtk_container_add(w.wc, w.container.widget)
	// for dialogs; otherwise, they will be modal to all windows, not just this one
	w.group = C.gtk_window_group_new()
	C.gtk_window_group_add_window(w.group, w.window)
	return w
}
示例#6
0
// this should allow us to resize the window arbitrarily
// thanks to Company in irc.gimp.net/#gtk+
func gtkNewWindowLayout() *C.GtkWidget {
	layout := C.gtk_layout_new(nil, nil)
	scrollarea := C.gtk_scrolled_window_new((*C.GtkAdjustment)(nil), (*C.GtkAdjustment)(nil))
	C.gtk_container_add((*C.GtkContainer)(unsafe.Pointer(scrollarea)), layout)
	// never show scrollbars; we're just doing this to allow arbitrary resizes
	C.gtk_scrolled_window_set_policy((*C.GtkScrolledWindow)(unsafe.Pointer(scrollarea)),
		C.GTK_POLICY_NEVER, C.GTK_POLICY_NEVER)
	return scrollarea
}
示例#7
0
func newScroller(widget *C.GtkWidget, native bool, bordered bool, overlay bool) *scroller {
	s := new(scroller)
	s.controlSingleWidget = newControlSingleWidget(widget)
	s.scrollwidget = C.gtk_scrolled_window_new(nil, nil)
	s.scrollcontainer = (*C.GtkContainer)(unsafe.Pointer(s.scrollwidget))
	s.scrollwindow = (*C.GtkScrolledWindow)(unsafe.Pointer(s.scrollwidget))

	// any actual changing operations need to be done to the GtkScrolledWindow
	// that is, everything /except/ preferredSize() are done to the GtkScrolledWindow
	s.scroller = newControlSingleWidget(s.scrollwidget)
	s.fsetParent = s.scroller.fsetParent
	s.fresize = s.scroller.fresize

	// in GTK+ 3.4 we still technically need to use the separate gtk_scrolled_window_add_with_viewpoint()/gtk_container_add() spiel for adding the widget to the scrolled window
	if native {
		C.gtk_container_add(s.scrollcontainer, s.widget)
	} else {
		C.gtk_scrolled_window_add_with_viewport(s.scrollwindow, s.widget)
	}

	// give the scrolled window a border (thanks to jlindgren in irc.gimp.net/#gtk+)
	if bordered {
		C.gtk_scrolled_window_set_shadow_type(s.scrollwindow, C.GTK_SHADOW_IN)
	}

	if overlay {
		// ok things get REALLY fun now
		// we now have to do all of the above again
		s.overlaywidget = C.gtk_overlay_new()
		s.overlaycontainer = (*C.GtkContainer)(unsafe.Pointer(s.overlaywidget))
		s.overlayoverlay = (*C.GtkOverlay)(unsafe.Pointer(s.overlaywidget))
		s.overlay = newControlSingleWidget(s.overlaywidget)
		s.fsetParent = s.overlay.fsetParent
		s.fresize = s.overlay.fresize
		C.gtk_container_add(s.overlaycontainer, s.scrollwidget)
	}

	return s
}
示例#8
0
文件: tab_unix.go 项目: sjn1978/ui
func (t *tab) Append(name string, control Control) {
	c := newContainer()
	t.tabs = append(t.tabs, c)
	// this calls gtk_container_add(), which, according to gregier in irc.gimp.net/#gtk+, acts just like gtk_notebook_append_page()
	C.gtk_container_add(t.container, c.widget)
	control.setParent(c.parent())
	c.resize = control.resize
	t.children = append(t.children, control)
	cname := togstr(name)
	defer freegstr(cname)
	C.gtk_notebook_set_tab_label_text(t.notebook,
		// unfortunately there does not seem to be a gtk_notebook_set_nth_tab_label_text()
		C.gtk_notebook_get_nth_page(t.notebook, C.gint(len(t.tabs)-1)),
		cname)
}
示例#9
0
文件: listbox_unix.go 项目: UIKit0/ui
func gListboxNew(multisel bool) *C.GtkWidget {
	store := C.gtkListStoreNew()
	widget := C.gtk_tree_view_new_with_model((*C.GtkTreeModel)(unsafe.Pointer(store)))
	tv := (*C.GtkTreeView)(unsafe.Pointer(widget))
	column := C.gtkTreeViewColumnNewWithAttributes(C.gtk_cell_renderer_text_new())
	C.gtk_tree_view_column_set_sizing(column, C.GTK_TREE_VIEW_COLUMN_AUTOSIZE)
	C.gtk_tree_view_column_set_resizable(column, C.FALSE) // not resizeable by the user; just autoresize
	C.gtk_tree_view_append_column(tv, column)
	C.gtk_tree_view_set_headers_visible(tv, C.FALSE)
	sel := C.GTK_SELECTION_SINGLE
	if multisel {
		sel = C.GTK_SELECTION_MULTIPLE
	}
	C.gtk_tree_selection_set_mode(C.gtk_tree_view_get_selection(tv), C.GtkSelectionMode(sel))
	scrollarea := C.gtk_scrolled_window_new((*C.GtkAdjustment)(nil), (*C.GtkAdjustment)(nil))
	// thanks to jlindgren in irc.gimp.net/#gtk+
	C.gtk_scrolled_window_set_shadow_type((*C.GtkScrolledWindow)(unsafe.Pointer(scrollarea)), C.GTK_SHADOW_IN)
	C.gtk_container_add((*C.GtkContainer)(unsafe.Pointer(scrollarea)), widget)
	return scrollarea
}
示例#10
0
// interfaces
func (self Container) Add(w WidgetLike) {
	C.gtk_container_add(self.object, w.W().object)
}
示例#11
0
func FromLua(code string) map[string]unsafe.Pointer {
	lua := lgo.NewLua()
	bindings := make(map[string]unsafe.Pointer)

	processActorArgs := func(actor *C.ClutterActor, args map[interface{}]interface{}) unsafe.Pointer {
		pointer := unsafe.Pointer(actor)
		var minFilter, magFilter *C.ClutterScalingFilter
		var scaleX C.gdouble = 1.0
		var scaleY C.gdouble = 1.0
		var translationX, translationY, translationZ C.gfloat
		for k, v := range args {
			switch key := k.(type) {
			case string:
				switch key {
				case "id":
					bindings[v.(string)] = pointer
				case "bgcolor", "background_color":
					C.clutter_actor_set_background_color(actor, NewColorFromString(v.(string)))
				case "clip_rect":
					clip := (*C.ClutterRect)(v.(unsafe.Pointer))
					C.clutter_actor_set_clip(actor,
						C.gfloat(clip.origin.x),
						C.gfloat(clip.origin.y),
						C.gfloat(clip.size.width),
						C.gfloat(clip.size.height))
				case "content":
					C.clutter_actor_set_content(actor, (*C.ClutterContent)(v.(unsafe.Pointer)))
				case "content_gravity":
					switch v.(string) {
					case "top-left":
						C.clutter_actor_set_content_gravity(actor, C.CLUTTER_CONTENT_GRAVITY_TOP_LEFT)
					case "top":
						C.clutter_actor_set_content_gravity(actor, C.CLUTTER_CONTENT_GRAVITY_TOP)
					case "top-right":
						C.clutter_actor_set_content_gravity(actor, C.CLUTTER_CONTENT_GRAVITY_TOP_RIGHT)
					case "left":
						C.clutter_actor_set_content_gravity(actor, C.CLUTTER_CONTENT_GRAVITY_LEFT)
					case "center":
						C.clutter_actor_set_content_gravity(actor, C.CLUTTER_CONTENT_GRAVITY_CENTER)
					case "right":
						C.clutter_actor_set_content_gravity(actor, C.CLUTTER_CONTENT_GRAVITY_RIGHT)
					case "bottom-left":
						C.clutter_actor_set_content_gravity(actor, C.CLUTTER_CONTENT_GRAVITY_BOTTOM_LEFT)
					case "bottom":
						C.clutter_actor_set_content_gravity(actor, C.CLUTTER_CONTENT_GRAVITY_BOTTOM)
					case "bottom-right":
						C.clutter_actor_set_content_gravity(actor, C.CLUTTER_CONTENT_GRAVITY_BOTTOM_RIGHT)
					case "resize-fill":
						C.clutter_actor_set_content_gravity(actor, C.CLUTTER_CONTENT_GRAVITY_RESIZE_FILL)
					case "resize-aspect":
						C.clutter_actor_set_content_gravity(actor, C.CLUTTER_CONTENT_GRAVITY_RESIZE_ASPECT)
					default:
						log.Fatalf("unknown content gravity: %s", v.(string))
					}
				case "content_repeat":
					switch v.(string) {
					case "none":
						C.clutter_actor_set_content_repeat(actor, C.CLUTTER_REPEAT_NONE)
					case "x", "x-axis":
						C.clutter_actor_set_content_repeat(actor, C.CLUTTER_REPEAT_X_AXIS)
					case "y", "y-axis":
						C.clutter_actor_set_content_repeat(actor, C.CLUTTER_REPEAT_Y_AXIS)
					case "both":
						C.clutter_actor_set_content_repeat(actor, C.CLUTTER_REPEAT_BOTH)
					default:
						log.Fatalf("unknown content repeat: %s", v.(string))
					}
				case "x", "fixed_x":
					C.clutter_actor_set_x(actor, C.gfloat(v.(float64)))
				case "y", "fixed_y":
					C.clutter_actor_set_y(actor, C.gfloat(v.(float64)))
				case "height":
					C.clutter_actor_set_height(actor, C.gfloat(v.(float64)))
				case "layout", "layout_manager":
					C.clutter_actor_set_layout_manager(actor, (*C.ClutterLayoutManager)(v.(unsafe.Pointer)))
				case "mag_filter", "magnification_filter":
					magFilter = (*C.ClutterScalingFilter)(v.(unsafe.Pointer))
					C.clutter_actor_set_content_scaling_filters(actor, *minFilter, *magFilter)
				case "margin_bottom":
					C.clutter_actor_set_margin_bottom(actor, C.gfloat(v.(float64)))
				case "margin_left":
					C.clutter_actor_set_margin_left(actor, C.gfloat(v.(float64)))
				case "margin_right":
					C.clutter_actor_set_margin_right(actor, C.gfloat(v.(float64)))
				case "margin_top":
					C.clutter_actor_set_margin_top(actor, C.gfloat(v.(float64)))
				//TODO min height
				//TODO min width
				case "min_filter", "minification_filter":
					minFilter = (*C.ClutterScalingFilter)(v.(unsafe.Pointer))
					C.clutter_actor_set_content_scaling_filters(actor, *minFilter, *magFilter)
				case "name":
					C.clutter_actor_set_name(actor, toGStr(v.(string)))
				//TODO natural height
				//TODO natural width
				case "offscreen_redirect":
					switch v.(string) {
					case "auto", "automatic-for-opacity":
						C.clutter_actor_set_offscreen_redirect(actor, C.CLUTTER_OFFSCREEN_REDIRECT_AUTOMATIC_FOR_OPACITY)
					case "always":
						C.clutter_actor_set_offscreen_redirect(actor, C.CLUTTER_OFFSCREEN_REDIRECT_ALWAYS)
					default:
						log.Fatalf("unknown offscreen redirect option: %s", v.(string))
					}
				case "opacity":
					C.clutter_actor_set_opacity(actor, C.guint8(uint8(v.(float64))))
				case "pivot_point":
					point := (*C.ClutterPoint)(v.(unsafe.Pointer))
					C.clutter_actor_set_pivot_point(actor, C.gfloat(point.x), C.gfloat(point.y))
				case "pivot_point_z":
					C.clutter_actor_set_pivot_point_z(actor, C.gfloat(v.(float64)))
				case "position":
					point := (*C.ClutterPoint)(v.(unsafe.Pointer))
					C.clutter_actor_set_position(actor, C.gfloat(point.x), C.gfloat(point.y))
				case "reactive":
					b := C.FALSE
					if v.(bool) {
						b = C.TRUE
					}
					C.clutter_actor_set_reactive(actor, C.gboolean(b))
				case "request_mode":
					switch v.(string) {
					case "height", "height_for_width":
						C.clutter_actor_set_request_mode(actor, C.CLUTTER_REQUEST_HEIGHT_FOR_WIDTH)
					case "width", "width_for_height":
						C.clutter_actor_set_request_mode(actor, C.CLUTTER_REQUEST_WIDTH_FOR_HEIGHT)
					default:
						log.Fatalf("unknown request mode: %s", v.(string))
					}
				case "rotation_angle_x":
					C.clutter_actor_set_rotation_angle(actor, C.CLUTTER_X_AXIS, C.gdouble(v.(float64)))
				case "rotation_angle_y":
					C.clutter_actor_set_rotation_angle(actor, C.CLUTTER_Y_AXIS, C.gdouble(v.(float64)))
				case "rotation_angle_z":
					C.clutter_actor_set_rotation_angle(actor, C.CLUTTER_Z_AXIS, C.gdouble(v.(float64)))
				case "scale_x":
					scaleX = C.gdouble(v.(float64))
					C.clutter_actor_set_scale(actor, scaleX, scaleY)
				case "scale_y":
					scaleY = C.gdouble(v.(float64))
					C.clutter_actor_set_scale(actor, scaleX, scaleY)
				case "scale_z":
					C.clutter_actor_set_scale_z(actor, C.gdouble(v.(float64)))
				case "size":
					size := (*C.ClutterSize)(v.(unsafe.Pointer))
					C.clutter_actor_set_size(actor, C.gfloat(size.width), C.gfloat(size.height))
				case "text_direction", "text_dir":
					switch v.(string) {
					case "default":
						C.clutter_actor_set_text_direction(actor, C.CLUTTER_TEXT_DIRECTION_DEFAULT)
					case "left", "left-to-right", "ltr":
						C.clutter_actor_set_text_direction(actor, C.CLUTTER_TEXT_DIRECTION_LTR)
					case "right", "right-to-left", "rtl":
						C.clutter_actor_set_text_direction(actor, C.CLUTTER_TEXT_DIRECTION_RTL)
					default:
						log.Fatalf("unknown text direction: %s", v.(string))
					}
				//TODO transform
				case "translation_x":
					translationX = C.gfloat(v.(float64))
					C.clutter_actor_set_translation(actor, translationX, translationY, translationZ)
				case "translation_y":
					translationY = C.gfloat(v.(float64))
					C.clutter_actor_set_translation(actor, translationX, translationY, translationZ)
				case "translation_z":
					translationZ = C.gfloat(v.(float64))
					C.clutter_actor_set_translation(actor, translationX, translationY, translationZ)
				case "visible":
					if v.(bool) {
						C.clutter_actor_show(actor)
					} else {
						C.clutter_actor_hide(actor)
					}
				case "width":
					C.clutter_actor_set_width(actor, C.gfloat(v.(float64)))
				case "x_align":
					switch v.(string) {
					case "fill":
						C.clutter_actor_set_x_align(actor, C.CLUTTER_ACTOR_ALIGN_FILL)
					case "start":
						C.clutter_actor_set_x_align(actor, C.CLUTTER_ACTOR_ALIGN_START)
					case "center":
						C.clutter_actor_set_x_align(actor, C.CLUTTER_ACTOR_ALIGN_CENTER)
					case "end":
						C.clutter_actor_set_x_align(actor, C.CLUTTER_ACTOR_ALIGN_END)
					default:
						log.Fatalf("unknown x align: %s", v.(string))
					}
				case "x_expand":
					b := C.FALSE
					if v.(bool) {
						b = C.TRUE
					}
					C.clutter_actor_set_x_expand(actor, C.gboolean(b))
				case "y_align":
					switch v.(string) {
					case "fill":
						C.clutter_actor_set_y_align(actor, C.CLUTTER_ACTOR_ALIGN_FILL)
					case "start":
						C.clutter_actor_set_y_align(actor, C.CLUTTER_ACTOR_ALIGN_START)
					case "center":
						C.clutter_actor_set_y_align(actor, C.CLUTTER_ACTOR_ALIGN_CENTER)
					case "end":
						C.clutter_actor_set_y_align(actor, C.CLUTTER_ACTOR_ALIGN_END)
					default:
						log.Fatalf("unknown y align: %s", v.(string))
					}
				case "y_expand":
					b := C.FALSE
					if v.(bool) {
						b = C.TRUE
					}
					C.clutter_actor_set_y_expand(actor, C.gboolean(b))
				case "z", "z_position":
					C.clutter_actor_set_z_position(actor, C.gfloat(v.(float64)))
				}
			case float64:
				switch value := v.(type) {
				case unsafe.Pointer:
					//TODO add tests
					if IsActor(value) { // actor child
						C.clutter_actor_add_child(actor, (*C.ClutterActor)(value))
					} else if IsAction(value) { // action
						C.clutter_actor_add_action(actor, (*C.ClutterAction)(value))
					} else if IsConstraint(value) { // constraint
						C.clutter_actor_add_constraint(actor, (*C.ClutterConstraint)(value))
					} else if IsEffect(value) { // effect
						C.clutter_actor_add_effect(actor, (*C.ClutterEffect)(value))
					} else {
						log.Fatalf("unknown subelement type")
					}
				}
			}
		}
		return pointer
	}

	processBoxArgs := func(box *C.ClutterLayoutManager, args map[string]interface{}) {
		//TODO
	}

	lua.RegisterFunctions(map[string]interface{}{

		// actors

		"Actor": func(args map[interface{}]interface{}) unsafe.Pointer {
			actor := C.clutter_actor_new()
			return processActorArgs(actor, args)
		},

		"Stage": func(args map[interface{}]interface{}) unsafe.Pointer {
			window := C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL)
			embed := C.gtk_clutter_embed_new()
			C.gtk_container_add((*C.GtkContainer)(unsafe.Pointer(window)), embed)
			actor := C.gtk_clutter_embed_get_stage((*C.GtkClutterEmbed)(unsafe.Pointer(embed)))
			C.clutter_actor_show(actor)
			C.gtk_widget_show_all((*C.GtkWidget)(unsafe.Pointer(window)))
			pointer := processActorArgs(actor, args)
			stage := (*C.ClutterStage)(unsafe.Pointer(actor))
			for k, v := range args {
				//TODO other properties
				switch key := k.(type) {
				case string:
					switch key {
					case "title":
						C.clutter_stage_set_title(stage, toGStr(v.(string)))
					}
				}
			}
			return pointer
		},

		"Text": func(args map[interface{}]interface{}) unsafe.Pointer {
			actor := C.clutter_text_new()
			pointer := processActorArgs(actor, args)
			text := (*C.ClutterText)(unsafe.Pointer(actor))
			for k, v := range args {
				//TODO other properties
				switch key := k.(type) {
				case string:
					switch key {
					case "text":
						C.clutter_text_set_text(text, toGStr(v.(string)))
					case "use_markup":
						b := C.FALSE
						if v.(bool) {
							b = C.TRUE
						}
						C.clutter_text_set_use_markup(text, C.gboolean(b))
					case "markup":
						C.clutter_text_set_markup(text, toGStr(v.(string)))
					case "color":
						C.clutter_text_set_color(text, NewColorFromString(v.(string)))
					}
				case float64:
				}
			}
			return pointer
		},

		// data structures

		"Point": func(args []float64) unsafe.Pointer {
			var point C.ClutterPoint
			point.x = C.float(args[0])
			point.y = C.float(args[1])
			return unsafe.Pointer(&point)
		},

		"Size": func(args []float64) unsafe.Pointer {
			var size C.ClutterSize
			size.width = C.float(args[0])
			size.height = C.float(args[1])
			return unsafe.Pointer(&size)
		},

		"Rect": func(args []float64) unsafe.Pointer {
			var rect C.ClutterRect
			var point C.ClutterPoint
			var size C.ClutterSize
			point.x = C.float(args[0])
			point.y = C.float(args[1])
			size.width = C.float(args[2])
			size.height = C.float(args[3])
			rect.origin = point
			rect.size = size
			return unsafe.Pointer(&rect)
		},

		// contents

		"Image": func(args []string) unsafe.Pointer {
			//TODO set data
			image := C.clutter_image_new()
			return unsafe.Pointer(image)
		},

		// layouts

		"Box": func(args map[string]interface{}) unsafe.Pointer {
			box := C.clutter_box_layout_new()
			processBoxArgs(box, args)
			return unsafe.Pointer(box)
		},

		"HBox": func(args map[string]interface{}) unsafe.Pointer {
			box := C.clutter_box_layout_new()
			C.clutter_box_layout_set_orientation((*C.ClutterBoxLayout)(unsafe.Pointer(box)), C.CLUTTER_ORIENTATION_HORIZONTAL)
			processBoxArgs(box, args)
			return unsafe.Pointer(box)
		},

		"VBox": func(args map[string]interface{}) unsafe.Pointer {
			box := C.clutter_box_layout_new()
			C.clutter_box_layout_set_orientation((*C.ClutterBoxLayout)(unsafe.Pointer(box)), C.CLUTTER_ORIENTATION_VERTICAL)
			processBoxArgs(box, args)
			return unsafe.Pointer(box)
		},

		// effects

		"Blur": func(args map[string]interface{}) unsafe.Pointer {
			effect := C.clutter_blur_effect_new()
			return unsafe.Pointer(effect)
		},

		// constraints
		"Align": func(args map[string]interface{}) unsafe.Pointer {
			constraint := C.clutter_align_constraint_new(nil, C.CLUTTER_ALIGN_X_AXIS, 0)
			align := (*C.ClutterAlignConstraint)(unsafe.Pointer(constraint))
			for key, v := range args {
				switch key {
				case "source":
					C.clutter_align_constraint_set_source(align, (*C.ClutterActor)(bindings[v.(string)]))
				case "axis":
					switch v.(string) {
					case "x", "X":
						C.clutter_align_constraint_set_align_axis(align, C.CLUTTER_ALIGN_X_AXIS)
					case "y", "Y":
						C.clutter_align_constraint_set_align_axis(align, C.CLUTTER_ALIGN_Y_AXIS)
					case "both", "BOTH", "Both":
						C.clutter_align_constraint_set_align_axis(align, C.CLUTTER_ALIGN_BOTH)
					}
				case "factor":
					C.clutter_align_constraint_set_factor(align, C.gfloat(v.(float64)))
				}
			}
			return unsafe.Pointer(constraint)
		},
	})
	lua.RunString(code)
	return bindings
}
示例#12
0
func (c *container) setParent(p *controlParent) {
	C.gtk_container_add(p.c, c.layoutwidget)
}
示例#13
0
文件: linux_gtk.go 项目: axet/desktop
func gtk_container_add(container GtkWidget, widget GtkWidget) {
	C.gtk_container_add(Arg(container), Arg(widget))
}
示例#14
0
func basesetParent(c controlPrivate, p *controlParent) {
	widget := c.widget() // avoid multiple interface lookups
	C.gtk_container_add(p.c, widget)
	// make sure the new widget is shown if not explicitly hidden
	C.gtk_widget_show_all(widget)
}
示例#15
0
func (s *scroller) setParent(p *controlParent) {
	C.gtk_container_add(p.c, s.addShowWhich)
	// see basesetParent() above for why we call gtk_widget_show_all()
	C.gtk_widget_show_all(s.addShowWhich)
}
示例#16
0
文件: main.go 项目: reusee/oraoraora
func main() {
	// init gtk
	var argc C.int
	C.gtk_init(&argc, nil)

	// root window
	win := C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL)
	connect(win, "destroy", func() { // quit gtk when window is closed
		C.gtk_main_quit()
	})

	// root grid
	grid := C.gtk_grid_new()
	C.gtk_container_add(asContainer(win), grid)

	// webview container
	pages := C.gtk_notebook_new()
	C.gtk_grid_attach(asGrid(grid), pages, 0, 0, 1, 1)
	C.gtk_widget_set_vexpand(pages, C.gtk_true())
	C.gtk_widget_set_hexpand(pages, C.gtk_true())
	C.gtk_notebook_set_tab_pos(asNotebook(pages), C.GTK_POS_LEFT)

	// new view constructor
	var newView func() *View
	newView = func() *View {
		view := NewView()

		label := C.gtk_label_new(nil)
		C.gtk_label_set_use_markup(asLabel(label), C.gtk_true())
		C.gtk_misc_set_alignment(asMisc(label), 0, 0.5)

		C.gtk_notebook_append_page(asNotebook(pages), view.Widget, label)

		// new view is requested
		connect(view.View, "create", func() *C.GtkWidget {
			return newView().Widget
		})

		// set tab label to page title
		connect(view.View, "notify::title", func() {
			var title string
			// trim long title
			for _, r := range fromGStr(C.webkit_web_view_get_title(view.View)) {
				if len(title) > 32 {
					break
				}
				title += string(r)
			}
			C.gtk_label_set_markup(asLabel(label), toGStr(fmt.Sprintf(`<span font="10">%s</span>`, title)))
		})

		return view
	}

	// first view
	view := newView()
	C.webkit_web_view_load_uri(view.View, toGStr("http://www.bilibili.tv"))

	// show window and run
	C.gtk_widget_show_all(win)
	C.gtk_main()
}
示例#17
0
func (c *controlSingleWidget) xsetParent(p *controlParent) {
	C.gtk_container_add(p.c, c.widget)
	// make sure the new widget is shown if not explicitly hidden
	// TODO why did I have this again?
	C.gtk_widget_show_all(c.widget)
}
示例#18
0
func gtk_container_add(container *C.GtkWidget, widget *C.GtkWidget) {
	C.gtk_container_add(togtkcontainer(container), widget)
}
示例#19
0
func gtkAddWidgetToLayout(container *C.GtkWidget, widget *C.GtkWidget) {
	layout := C.gtk_bin_get_child((*C.GtkBin)(unsafe.Pointer(container)))
	C.gtk_container_add((*C.GtkContainer)(unsafe.Pointer(layout)), widget)
}
示例#20
0
文件: container.go 项目: ziutek/gtk
func (k *Container) Add(w *Widget) {
	C.gtk_container_add(k.g(), w.g())
}