Geometry(3tk)
π NAME π
okay so bestie, welcome to Geometry(3tk) β the Tk themed geometry utilities manual, and it's giving extremely useful if you're out here doing widget layouts. It covers:
Ttk_MakeBox, Ttk_PadBox, Ttk_ExpandBox, Ttk_PackBox, Ttk_StickBox, Ttk_PlaceBox, Ttk_BoxContains, Ttk_MakePadding, Ttk_UniformPadding, Ttk_AddPadding, Ttk_RelievePadding, Ttk_GetPaddingFromObj, Ttk_GetBorderFromObj, Ttk_GetStickyFromObj
β¨ Tk themed geometry utilities β¨ β that's the whole vibe, no cap.
πΈ SYNOPSIS πΈ
#include <tkTheme.h>
Ttk_Box
Ttk_MakeBox(int x, int y, int width, int height);
Ttk_Box
Ttk_PadBox(Ttk_Box parcel, Ttk_Padding padding);
Ttk_Box
Ttk_ExpandBox(Ttk_Box parcel, Ttk_Padding padding);
Ttk_Box
Ttk_PackBox(Ttk_Box *cavity, int width, int height, Ttk_Side side);
Ttk_Box
Ttk_StickBox(Ttk_Box parcel, int width, int height, unsigned sticky);
Ttk_Box
Ttk_PlaceBox(Ttk_Box *cavity, int width, int height, Ttk_Side side, unsigned sticky);
Ttk_Box
Ttk_AnchorBox(Ttk_Box parcel, int width, int height, Tk_Anchor anchor);
Ttk_Padding
Ttk_MakePadding(short left, short top, short right, short bottom);
Ttk_Padding
Ttk_UniformPadding(short border);
Ttk_Padding
Ttk_AddPadding(Ttk_Padding padding1, Ttk_Padding padding2;
Ttk_Padding
Ttk_RelievePadding(Ttk_Padding padding, int relief);
int
Ttk_BoxContains(Ttk_Box box, int x, int y);
int
Ttk_GetPaddingFromObj(Tcl_Interp *interp, Tk_Window tkwin, Tcl_Obj *objPtr, Ttk_Padding *padding_rtn);
int
Ttk_GetBorderFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, Ttk_Padding *padding_rtn);
int
Ttk_GetStickyFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, int *sticky_rtn);
π¦ ARGUMENTS π¦
okay so here's the whole cast of characters, each one labeled with its direction, bestie:
Tk_Anchor anchor(in) β one of the symbolic constantsTK_ANCHOR_N,TK_ANCHOR_NE, etc. Go peepTk_GetAnchorFromObj(3tk)for the full lore.Ttk_Box * cavity(in/out) β a rectangular region that a parcel gets allocated out of. She's both input and output, main character energy fr.short border(in) β extra padding, in pixels, added uniformly to every single side of a region.short bottom(in) β extra padding, in pixels, tacked onto the bottom of a region.Ttk_Box box(in) β specifies a rectangular region.Ttk_Box * box_rtn(out) β a rectangular region. (She's the output, the result, the payoff π )int height(in) β the height in pixels of a region.Tcl_Interp * interp(in) β used to store error messages.int left(in) β extra padding, in pixels, added to the left side of a region.Tcl_Obj * objPtr(in) β the string value holds a symbolic name that gets converted into an enumerated value or a bitmask.Ttk_Padding padding(in) β extra padding to add on the inside of a region.Ttk_Padding * padding_rtn(out) β the padding that's present on the inside of a region.Ttk_Box parcel(in) β a rectangular region, allocated from a cavity.int relief(in) β one of the standard Tk relief options (TK_RELIEF_RAISED,TK_RELIEF_SUNKEN, etc.). SeeTk_GetReliefFromObj.short right(in) β extra padding, in pixels, added to the right side of a region.Ttk_Side side(in) β one ofTTK_SIDE_LEFT,TTK_SIDE_TOP,TTK_SIDE_RIGHT, orTTK_SIDE_BOTTOM.unsigned sticky(in) β a bitmask holding one or more of the bitsTTK_STICK_W(west, aka left),TTK_STICK_E(east, aka right),TTK_STICK_N(north, aka top), andTTK_STICK_S(south, aka bottom). Also:TTK_FILL_Xis defined as a synonym for(TTK_STICK_W|TTK_STICK_E),TTK_FILL_Yis a synonym for(TTK_STICK_N|TTK_STICK_S), andTTK_FILL_BOTHis a synonym for(TTK_FILL_X|TTK_FILL_Y). Also also: go seegrid(3tk).Tk_Window tkwin(in) β the window whose screen geometry decides how absolute units convert into pixels.short top(in) β extra padding at the top of a region.int width(in) β the width in pixels of a region.int x(in) β X coordinate of the upper-left corner of the region.int y(in) β Y coordinate of the upper-left corner of the region.
π«Ά tiny lil heads-up bestie: with objPtr, the internal rep may be modified to cache the corresponding value. That's not me being dramatic, that's literally what it says.
π¦ BOXES π¦
The Ttk_Box structure represents a rectangular region of a window:
typedef struct {
int x;
int y;
int width;
int height;
} Ttk_Box;
All coordinates are relative to the window. β¨
Ttk_MakeBoxβ the convenience routine, the little helper bestie. She constructs aTtk_Boxstructure for a region that'swidthpixels wide,heightpixels tall, sitting at the specifiedx,ycoordinates.Ttk_PadBoxβ returns a new box located inside the specifiedparcel, shrunken according to theleft,top,right, andbottommargins given bypadding.Ttk_ExpandBoxβ she's the inverse ofTtk_PadBoxπ« she returns a new box surrounding the specifiedparcel, expanded according to theleft,top,right, andbottommargins given bypadding.Ttk_PackBoxβ allocates a parcel that'swidthbyheightpixels, on the specifiedsideof thecavity, and then shrinks the cavity accordingly. She takes what she needs and the cavity gets smaller, periodt.Ttk_StickBoxβ places a box with the requestedwidthandheightinside theparcel, according to thestickybits.Ttk_PlaceBoxβ the collab we didn't know we needed π₯ she combinesTtk_PackBoxandTtk_StickBox: allocates a parcel on the specifiedsideof thecavity, places a box of the requested size inside the parcel according tosticky, and shrinks the cavity.Ttk_AnchorBoxβ places a box with the requestedwidthandheightinside theparcel, according to the specifiedanchoroption.Ttk_BoxContainsβ tests whether the specifiedx,ycoordinate lies within the rectangular regionbox. Is she in or is she out, that's the whole question.
π PADDDING π
(that's the section name, I don't make the rules, I just deliver them with flair)
The Ttk_Padding structure is used to represent borders, internal padding, and external margins:
typedef struct {
short left;
short top;
short right;
short bottom;
} Ttk_Padding;
Ttk_MakePaddingβ convenience routine, she constructs aTtk_Paddingstructure with the specifiedleft,top,right, andbottomcomponents.Ttk_UniformPaddingβ constructs aTtk_Paddingstructure where all components are equal to the specifiedborder.Ttk_AddPaddingβ adds twoTtk_Paddingstogether and hands you back a combined padding containing the sum of the individual padding components. Math but make it fashion πTtk_RelievePaddingβ adds an extra 2 pixels of padding topaddingaccording to the specifiedrelief:- if
reliefisTK_RELIEF_SUNKEN, adds two pixels at the top and left so the inner region is shifted down and to the left. - if it's
TK_RELIEF_RAISED, adds two pixels at the bottom and right so the inner region is shifted up and to the right. - otherwise, adds 1 pixel on all sides.
- if
This is typically used in element geometry procedures to simulate a "pressed-in" look for pushbuttons. iykyk. π
π CONVERSION ROUTINES π
Ttk_GetPaddingFromObjβ converts the string inobjPtrinto aTtk_Paddingstructure. The string representation is a list of up to four length specifications:βleft top right bottomβ. If fewer than four elements are specified,bottomdefaults totop,rightdefaults toleft, andtopdefaults toleft. For the syntax of length specifications, go seeTk_GetPixelsFromObj(3tk).Ttk_GetBorderFromObjβ same asTtk_GetPaddingFromObj, except the lengths are specified as integers (i.e., resolution-dependent values like3mare not allowed). Sorry bestie.Ttk_GetStickyFromObjβ converts the string inobjPtrinto a sticky bitmask. The string contains zero or more of the charactersn,s,e, orw. That's it, that's the whole alphabet of sticking.
π SEE ALSO π
Tk_GetReliefFromObj(3tk), Tk_GetPixelsFromObj(3tk), Tk_GetAnchorFromObj(3tk)
β KEYWORDS β
geometry, padding, margins, box, region, sticky, relief
and that's the whole page bestie, you ate it up π«Ά this was Tk 8.5, Geometry(3tk), the Tk themed geometry utilities manual β go build something iconic with your boxes and your padding, mwah πβ¨π
π¦ where this page comes from
- debian trixie: tk9.0-doc 9.0.1-3
- ubuntu questing: tk9.0-doc 9.0.2-1
- ubuntu resolute: tk9.0-doc 9.0.3-1
- ubuntu stonking: tk9.0-doc 9.0.4-1
- Copyright (c) 2004 Joe English
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms