Tk_GetAnchorFromObj(3)
π NAME π
Tk_GetAnchorFromObj, Tk_GetAnchor, Tk_NameOfAnchor β the little trio that translates between strings and anchor positions. This is the Tk_GetAnchorFromObj(3) page from Tk Library Procedures, and bestie, itβs giving tiny API, very specific job, zero drama β¨
β¨ SYNOPSIS β¨
#include <tk.h>
int
Tk_GetAnchorFromObj(interp, objPtr, anchorPtr)
int
Tk_GetAnchor(interp, string, anchorPtr)
const char *
Tk_NameOfAnchor(anchor)
π ARGUMENTS π
Tcl_Interp *interp (in)β the interpreter used for error reporting, orNULL.Tcl_Obj *objPtr (in/out)β its string value holds the name of an anchor point:n,ne,e,se,s,sw,w,nw, orcenter. Its internal rep gets modified to cache the matchingTk_Anchor. Forcenteron input, a non-empty abbreviation of it is also allowed on input.const char *string (in)β same asobjPtr, except the anchor point description comes in as a string.int *anchorPtr (out)β pointer to where the anchor position matchingobjPtrorstringgets stored.Tk_Anchor anchor (in)β an anchor position, e.g.TCL_ANCHOR_CENTER.
π¦ DESCRIPTION π¦
Okay so Tk_GetAnchorFromObj drops into *anchorPtr an anchor position β thatβs an enumerated type, Tk_Anchor β matching the value inside objPtr. The result is one of TK_ANCHOR_N, TK_ANCHOR_NE, TK_ANCHOR_E, TK_ANCHOR_SE, TK_ANCHOR_S, TK_ANCHOR_SW, TK_ANCHOR_W, TK_ANCHOR_NW, or TK_ANCHOR_CENTER. These anchor positions usually tell you which point on an object gets used to position that object β for example, TK_ANCHOR_N means position the top center point of the object at a particular place. Precise queen behavior π―
Under normal circumstances the return value is TCL_OK, and interp is unused. If string does not contain a valid anchor position or an abbreviation of one of those names, then TCL_ERROR comes back, *anchorPtr stays unmodified, and an error message is stored in interp's result if interp is not NULL. Also, Tk_GetAnchorFromObj caches information about the return value in objPtr, which speeds up future calls to Tk_GetAnchorFromObj with that same objPtr. Caching? Obsessed. π
Tk_GetAnchor is identical to Tk_GetAnchorFromObj except that the description of the anchor is specified with a string instead of an object. That means Tk_GetAnchor cannot cache the return value, so it is less efficient than Tk_GetAnchorFromObj. Not me defending a string-only API, but facts are facts π
Tk_NameOfAnchor is the logical inverse of Tk_GetAnchor. Give it an anchor position like TK_ANCHOR_N and it returns a statically-allocated string corresponding to anchor. If anchor is not a legal anchor value, then the string unknown anchor position is returned. Iconic error string, honestly π
πΈ KEYWORDS πΈ
- anchor position
Source/version check, bestie: this page is from Tk 8.1, and the manual page is Tk_GetAnchorFromObj(3) π«Άπ
β¨
π¦ where this page comes from
- alpine 3.23: tk9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tk9-doc 9.0.3-r2 Β· TCL
- fedora 43: tk-devel 1:9.0.2-1.fc43 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 43: tk-devel 1:9.0.2-1.fc43 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 44: tk-devel 1:9.0.2-1.fc44 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 44: tk-devel 1:9.0.2-1.fc44 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- nixos 26.05: tk 9.0.3
- nixpkgs unstable: tk 9.1.0
- Copyright (c) 1990 The Regents of the University of California
- Copyright (c) 1994-1998 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms