示例#1
0
文件: label.go 项目: twstrike/gotk3
// LabelNew is a wrapper around gtk_label_new().
func LabelNew(str string) (*Label, error) {
	cstr := C.CString(str)
	defer C.free(unsafe.Pointer(cstr))
	c := C.gtk_label_new((*C.gchar)(cstr))
	if c == nil {
		return nil, nilPtrErr
	}
	obj := wrapObject(unsafe.Pointer(c))
	return wrapLabel(obj), nil
}
示例#2
0
文件: label_unix.go 项目: sjn1978/ui
func newLabel(text string) Label {
	ctext := togstr(text)
	defer freegstr(ctext)
	widget := C.gtk_label_new(ctext)
	l := &label{
		controlSingleWidget: newControlSingleWidget(widget),
		misc:                (*C.GtkMisc)(unsafe.Pointer(widget)),
		label:               (*C.GtkLabel)(unsafe.Pointer(widget)),
	}
	return l
}
示例#3
0
func finishNewLabel(text string, standalone bool) *label {
	ctext := togstr(text)
	defer freegstr(ctext)
	widget := C.gtk_label_new(ctext)
	l := &label{
		_widget:    widget,
		misc:       (*C.GtkMisc)(unsafe.Pointer(widget)),
		label:      (*C.GtkLabel)(unsafe.Pointer(widget)),
		standalone: standalone,
	}
	return l
}
示例#4
0
文件: label.go 项目: napsy/go-gtk3
func NewLabel(str string) *Label {
	l := &Label{}

	s := gobject.GString(str)
	defer s.Free()

	o := C.gtk_label_new((*C.gchar)(s.GetPtr()))

	l.Widget = NewWidget(unsafe.Pointer(o))
	l.object = C.to_GtkLabel(unsafe.Pointer(o))

	return l
}
示例#5
0
func gtk_label_new() *C.GtkWidget {
	label := C.gtk_label_new(emptystring)
	C.gtk_label_set_line_wrap(togtklabel(label), C.FALSE) // turn off line wrap
	// don't call gtk_label_set_line_wrap_mode(); there's no "wrap none" value there anyway
	C.gtk_label_set_ellipsize(togtklabel(label), C.PANGO_ELLIPSIZE_NONE) // turn off ellipsizing; this + line wrapping above will guarantee cutoff as documented
	// there's a function gtk_label_set_justify() that indicates GTK_JUSTIFY_LEFT is the default
	// but this actually is NOT the control justification, just the multi-line justification
	// so we need to do THIS instead
	// this will also valign to the top
	// thanks to mclasen in irc.gimp.net/#gtk+
	C.gtk_misc_set_alignment((*C.GtkMisc)(unsafe.Pointer(label)), 0, 0)
	return label
}
示例#6
0
func gtk_label_new() *C.GtkWidget {
	label := C.gtk_label_new(emptystring)
	C.gtk_label_set_line_wrap(togtklabel(label), C.FALSE) // turn off line wrap
	// don't call gtk_label_set_line_wrap_mode(); there's no "wrap none" value there anyway
	C.gtk_label_set_ellipsize(togtklabel(label), C.PANGO_ELLIPSIZE_NONE) // turn off ellipsizing; this + line wrapping above will guarantee cutoff as documented
	// there's a function gtk_label_set_justify() that indicates GTK_JUSTIFY_LEFT is the default
	// but this actually is NOT the control justification, just the multi-line justification
	// so we need to do THIS instead
	// this will valign to the center, which is what the HIG says (https://developer.gnome.org/hig-book/3.4/design-text-labels.html.en) for all controls that label to the side; thankfully this means we don't need to do any extra positioning magic
	// this will also valign to the top
	// thanks to mclasen in irc.gimp.net/#gtk+
	gtk_misc_set_alignment(label, 0, 0.5)
	return label
}
示例#7
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()
}
示例#8
0
文件: linux_gtk.go 项目: axet/desktop
func gtk_label_new(s string) GtkWidget {
	n := C.CString(s)
	defer C.free(unsafe.Pointer(n))
	return GtkWidget(C.gtk_label_new(n))
}