1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
|
// Same copyright and license as the rest of the files in this project
// This file contains style related functions and structures
package gtk
// #include <gtk/gtk.h>
// #include "gtk.go.h"
import "C"
import (
"unsafe"
"github.com/gotk3/gotk3/pango"
"github.com/gotk3/gotk3/glib"
)
/*
* GtkLabel
*/
// Label is a representation of GTK's GtkLabel.
type Label struct {
Widget
}
// native returns a pointer to the underlying GtkLabel.
func (v *Label) native() *C.GtkLabel {
if v == nil || v.GObject == nil {
return nil
}
p := unsafe.Pointer(v.GObject)
return C.toGtkLabel(p)
}
func marshalLabel(p uintptr) (interface{}, error) {
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
obj := glib.Take(unsafe.Pointer(c))
return wrapLabel(obj), nil
}
func wrapLabel(obj *glib.Object) *Label {
if obj == nil {
return nil
}
return &Label{Widget{glib.InitiallyUnowned{obj}}}
}
// WidgetToLabel is a convience func that casts the given *Widget into a *Label.
func WidgetToLabel(widget *Widget) (*Label, error) {
obj := glib.Take(unsafe.Pointer(widget.GObject))
return wrapLabel(obj), nil
}
// 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 := glib.Take(unsafe.Pointer(c))
return wrapLabel(obj), nil
}
// SetText is a wrapper around gtk_label_set_text().
func (v *Label) SetText(str string) {
cstr := C.CString(str)
defer C.free(unsafe.Pointer(cstr))
C.gtk_label_set_text(v.native(), (*C.gchar)(cstr))
}
// TODO:
// gtk_label_set_text_with_mnemonic().
// gtk_label_get_attributes().
func (v *Label) SetAttributes(attributes *pango.AttrList) {
C.gtk_label_set_attributes(v.native(), (*C.PangoAttrList)(unsafe.Pointer(attributes.Native())))
}
// SetMarkup is a wrapper around gtk_label_set_markup().
func (v *Label) SetMarkup(str string) {
cstr := C.CString(str)
defer C.free(unsafe.Pointer(cstr))
C.gtk_label_set_markup(v.native(), (*C.gchar)(cstr))
}
// SetMarkupWithMnemonic is a wrapper around
// gtk_label_set_markup_with_mnemonic().
func (v *Label) SetMarkupWithMnemonic(str string) {
cstr := C.CString(str)
defer C.free(unsafe.Pointer(cstr))
C.gtk_label_set_markup_with_mnemonic(v.native(), (*C.gchar)(cstr))
}
// SetPattern is a wrapper around gtk_label_set_pattern().
func (v *Label) SetPattern(patern string) {
cstr := C.CString(patern)
defer C.free(unsafe.Pointer(cstr))
C.gtk_label_set_pattern(v.native(), (*C.gchar)(cstr))
}
// SetJustify is a wrapper around gtk_label_set_justify().
func (v *Label) SetJustify(jtype Justification) {
C.gtk_label_set_justify(v.native(), C.GtkJustification(jtype))
}
// SetEllipsize is a wrapper around gtk_label_set_ellipsize().
func (v *Label) SetEllipsize(mode pango.EllipsizeMode) {
C.gtk_label_set_ellipsize(v.native(), C.PangoEllipsizeMode(mode))
}
// GetWidthChars is a wrapper around gtk_label_get_width_chars().
func (v *Label) GetWidthChars() int {
c := C.gtk_label_get_width_chars(v.native())
return int(c)
}
// SetWidthChars is a wrapper around gtk_label_set_width_chars().
func (v *Label) SetWidthChars(nChars int) {
C.gtk_label_set_width_chars(v.native(), C.gint(nChars))
}
// GetMaxWidthChars is a wrapper around gtk_label_get_max_width_chars().
func (v *Label) GetMaxWidthChars() int {
c := C.gtk_label_get_max_width_chars(v.native())
return int(c)
}
// SetMaxWidthChars is a wrapper around gtk_label_set_max_width_chars().
func (v *Label) SetMaxWidthChars(nChars int) {
C.gtk_label_set_max_width_chars(v.native(), C.gint(nChars))
}
// GetLineWrap is a wrapper around gtk_label_get_line_wrap().
func (v *Label) GetLineWrap() bool {
c := C.gtk_label_get_line_wrap(v.native())
return gobool(c)
}
// SetLineWrap is a wrapper around gtk_label_set_line_wrap().
func (v *Label) SetLineWrap(wrap bool) {
C.gtk_label_set_line_wrap(v.native(), gbool(wrap))
}
// SetLineWrapMode is a wrapper around gtk_label_set_line_wrap_mode().
func (v *Label) SetLineWrapMode(wrapMode pango.WrapMode) {
C.gtk_label_set_line_wrap_mode(v.native(), C.PangoWrapMode(wrapMode))
}
// TODO:
// gtk_label_get_line_wrap_mode().
// gtk_label_get_layout_offsets().
// gtk_label_get_layout().
// gtk_label_get_mnemonic_widget().
// GetSelectable is a wrapper around gtk_label_get_selectable().
func (v *Label) GetSelectable() bool {
c := C.gtk_label_get_selectable(v.native())
return gobool(c)
}
// GetText is a wrapper around gtk_label_get_text().
func (v *Label) GetText() (string, error) {
c := C.gtk_label_get_text(v.native())
if c == nil {
return "", nilPtrErr
}
return C.GoString((*C.char)(c)), nil
}
// GetJustify is a wrapper around gtk_label_get_justify().
func (v *Label) GetJustify() Justification {
c := C.gtk_label_get_justify(v.native())
return Justification(c)
}
// GetEllipsize is a wrapper around gtk_label_get_ellipsize().
func (v *Label) GetEllipsize() pango.EllipsizeMode {
c := C.gtk_label_get_ellipsize(v.native())
return pango.EllipsizeMode(c)
}
// GetCurrentUri is a wrapper around gtk_label_get_current_uri().
func (v *Label) GetCurrentUri() string {
c := C.gtk_label_get_current_uri(v.native())
return C.GoString((*C.char)(c))
}
// GetTrackVisitedLinks is a wrapper around gtk_label_get_track_visited_links().
func (v *Label) GetTrackVisitedLinks() bool {
c := C.gtk_label_get_track_visited_links(v.native())
return gobool(c)
}
// SetTrackVisitedLinks is a wrapper around gtk_label_set_track_visited_links().
func (v *Label) SetTrackVisitedLinks(trackLinks bool) {
C.gtk_label_set_track_visited_links(v.native(), gbool(trackLinks))
}
// GetAngle is a wrapper around gtk_label_get_angle().
func (v *Label) GetAngle() float64 {
c := C.gtk_label_get_angle(v.native())
return float64(c)
}
// SetAngle is a wrapper around gtk_label_set_angle().
func (v *Label) SetAngle(angle float64) {
C.gtk_label_set_angle(v.native(), C.gdouble(angle))
}
// GetSelectionBounds is a wrapper around gtk_label_get_selection_bounds().
func (v *Label) GetSelectionBounds() (start, end int, nonEmpty bool) {
var cstart, cend C.gint
c := C.gtk_label_get_selection_bounds(v.native(), &cstart, &cend)
return int(cstart), int(cend), gobool(c)
}
// GetSingleLineMode is a wrapper around gtk_label_get_single_line_mode().
func (v *Label) GetSingleLineMode() bool {
c := C.gtk_label_get_single_line_mode(v.native())
return gobool(c)
}
// SetSingleLineMode is a wrapper around gtk_label_set_single_line_mode().
func (v *Label) SetSingleLineMode(mode bool) {
C.gtk_label_set_single_line_mode(v.native(), gbool(mode))
}
// GetUseMarkup is a wrapper around gtk_label_get_use_markup().
func (v *Label) GetUseMarkup() bool {
c := C.gtk_label_get_use_markup(v.native())
return gobool(c)
}
// SetUseMarkup is a wrapper around gtk_label_set_use_markup().
func (v *Label) SetUseMarkup(use bool) {
C.gtk_label_set_use_markup(v.native(), gbool(use))
}
// GetUseUnderline is a wrapper around gtk_label_get_use_underline().
func (v *Label) GetUseUnderline() bool {
c := C.gtk_label_get_use_underline(v.native())
return gobool(c)
}
// SetUseUnderline is a wrapper around gtk_label_set_use_underline().
func (v *Label) SetUseUnderline(use bool) {
C.gtk_label_set_use_underline(v.native(), gbool(use))
}
// LabelNewWithMnemonic is a wrapper around gtk_label_new_with_mnemonic().
func LabelNewWithMnemonic(str string) (*Label, error) {
cstr := C.CString(str)
defer C.free(unsafe.Pointer(cstr))
c := C.gtk_label_new_with_mnemonic((*C.gchar)(cstr))
if c == nil {
return nil, nilPtrErr
}
obj := glib.Take(unsafe.Pointer(c))
return wrapLabel(obj), nil
}
// SelectRegion is a wrapper around gtk_label_select_region().
func (v *Label) SelectRegion(startOffset, endOffset int) {
C.gtk_label_select_region(v.native(), C.gint(startOffset),
C.gint(endOffset))
}
// SetSelectable is a wrapper around gtk_label_set_selectable().
func (v *Label) SetSelectable(setting bool) {
C.gtk_label_set_selectable(v.native(), gbool(setting))
}
// SetLabel is a wrapper around gtk_label_set_label().
func (v *Label) SetLabel(str string) {
cstr := C.CString(str)
defer C.free(unsafe.Pointer(cstr))
C.gtk_label_set_label(v.native(), (*C.gchar)(cstr))
}
// GetLabel is a wrapper around gtk_label_get_label().
func (v *Label) GetLabel() string {
c := C.gtk_label_get_label(v.native())
if c == nil {
return ""
}
return C.GoString((*C.char)(c))
}
// GetMnemonicKeyval is a wrapper around gtk_label_get_mnemonic_keyval().
func (v *Label) GetMnemonicKeyval() uint {
return uint(C.gtk_label_get_mnemonic_keyval(v.native()))
}
// SetMnemonicWidget is a wrapper around gtk_label_set_mnemonic_widget().
func (v *Label) SetMnemonicWidget(widget IWidget) {
C.gtk_label_set_mnemonic_widget(v.native(), widget.toWidget())
}
|