blt::htext(3tcl)

✨ htext β€” create and manipulate hypertext widgets πŸ’–

okay bestie, buckle up, this one's from the BLT Built-In Commands set (the manual page lives as blt::htext(3tcl)), and it's literally the blueprint for the hypertext widget. it's giving "text widget that went to geometry-manager school". let's go πŸ’…


🌸 NAME 🌸

htext β€” Create and manipulate hypertext widgets


πŸŽ€ SYNOPSIS πŸŽ€

htext pathName ?option value?...

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so the htext command makes a whole new window (that's your pathName argument, bestie) and turns it into an htext widget. you can also pass extra options, described above, either on the command line or in the option database, to configure stuff like its color and font. important: at the moment you invoke this command, there must not already be a window named pathName β€” but pathName's parent must exist. and then htext hands you back its pathName. slay.

the htext widget is a hybrid β€” no cap β€” of a non-editable text widget and a geometry manager (like, think the packer). it displays text (optionally read from a file) in a window. you can scroll that text either horizontally or vertically, using the htext window as a viewport. and it gets better: Tcl commands can be embedded right into the text, and they get evaluated as the text is parsed. any text sitting between the special double characters (by default, percent signs %%) gets immediately passed to the Tcl interpreter to be evaluated. iconic behaviour tbh.

plus β€” and this is the main character energy part β€” any widget or widget hierarchy can be packed in-line and made to appear on the current line of the text. widgets get packed using the htext append command. all widgets must be children of the htext window and must already exist before packing. once a widget has been packed it cannot be moved to a different position within the text. widgets can be resized, but they'll stay at the same position within the text. periodt.

here's a lil fact that saves you so much grief: before a file or text string is parsed by the htext widget, all the widget's current children are destroyed. so you can reload files or text without worrying about unmapping or destroying each child window beforehand. we love a self-cleaning king 🫢

setting either the -filename or -text configuration option will adjust the value of the other. if both options are set, the file takes precedence. when a new file is read using the -filename option, the value of the -text option is reset to the empty string. likewise, when the -text option is set, the string representing the -filename option is cleared. (they're linked, bestie, one always cancels the other out πŸ’€)


πŸ“ FILE FORMAT πŸ“

the format of an htext text file is typically ASCII text. text enclosed by special double characters (by default, percent signs %%) is interpreted and executed as Tcl commands. the special character can be specified by the -specialchar option.

in the following example of a htext file, a button widget is appended to the text between the words "a" and "which". the pathName of the htext widget is .ht.

This will be displayed as normal text.
But this will become a %%
  button .ht.button -text "button" -fg red
  .ht append .ht.button
%% which can invoke a Tcl command.

🧚 INDICES 🧚

some of the widget operations (selection, gotoline, search, etc.) take one or more indices as arguments. an index is just a string that points at a particular place within the text β€” like, say, the first and last characters in a range you wanna select. πŸ“

an index must have one of the following forms:

  • line.char β€” indicates the char'th character on line line. both lines and characters are numbered from 0, so "0.0" is the very first beginning of the text. char may be undesignated β€” in that case a character position of 0 is assumed.
  • @x,y β€” indicates the character that covers the pixel whose x and y coordinates within the text's window are x and y.
  • end β€” indicates the end of the text.
  • anchor β€” indicates the anchor point for the selection, which is set with the selection operation.
  • sel.first β€” indicates the first character in the selection. it's an error to use this form if the selection isn't in the entry window. πŸ™ˆ
  • sel.last β€” indicates the character just after the last one in the selection. it's an error to use this form if the selection isn't in the entry window.

πŸ’œ VARIABLES πŸ’œ

the following global Tcl variables are maintained when an htext file is parsed:

  • htext(widget) β€” is the pathname of the htext widget.
  • htext(file) β€” is the name of the file the htext widget is currently parsing. it is the empty string when the -text option is used.
  • htext(line) β€” is the current line number in the text.

this information might be used to construct hyper links between different files and/or lines. iykyk ✨


⭐ SYNTAX ⭐

the htext command creates a new Tcl command whose name is pathName. this command may be used to invoke various operations on the widget. it has the following general form:

pathName oper ?args?

Oper and args determine the exact behavior of the command.


πŸ‘‘ OPERATIONS πŸ‘‘

the following operations are available for htext widgets:

  • pathName append window ?option value?... β€” embeds the widget window into the htext widget. window is the pathname of the widget to be embedded, which must be a child of pathName. window will be positioned in the htext widget at the current location of the text. if option and value pairs are present, they configure various aspects of how window appears in pathName. the following options are available:
    • -anchor anchorPos β€” specifies how window will be arranged if there's any extra space in the cavity surrounding the window. for example, if anchorPos is center then the window is centered in the cavity; if anchorPos is w then the window will be drawn such that it touches the leftmost edge of the cavity. the default is center.
    • -fill style β€” specifies how the window should be stretched to occupy the extra space in the cavity surrounding it (if any exists). style is none, x, y, both. if style is x, the width of window is expanded to fill the cavity. if style is y, the height is expanded. the default is none.
    • -height pixels β€” sets the height of the cavity surrounding window. if pixels is zero, the height of the cavity will be the same as the requested height of window. if pixels is less than the requested height of window, window will be reduced to fit the cavity. the default is 0.
    • -ipadx pad β€” sets the amount of internal padding to be added to the width of window. pad can be a list of one or two numbers. if pad has two elements, the left side of window is extended by the first value and the right side by the second value. if pad is just one value, both the left and right sides are padded evenly by the value. the default is 0.
    • -ipady pad β€” sets an amount of internal padding to be added to the height of window. pad can be a list of one or two numbers. if pad has two elements, the top of window is padded by the first value and the bottom by the second value. if pad is just one number, both the top and bottom are padded evenly by the value. the default is 0.
    • -justify justify β€” justifies window vertically within the cavity containing it in relation to the line of text. justify is top, bottom, or center. if justify is center the widget is centered along the baseline of the line of text. the default is center.
    • -padx pad β€” sets the padding on the left and right sides of window. pad can be a list of one or two numbers. if pad has two elements, the left side of window is padded by the first value and the right side by the second value. if pad has just one value, both the left and right sides are padded evenly by the value. the default is 0.
    • -pady pad β€” sets the padding above and below window. pad can be a list of one or two numbers. if pad has two elements, the area above window is padded by the first value and the area below by the second value. if pad is just one number, both the top and bottom are padded by the value. the default is 0.
    • -relheight value β€” specifies the height of the cavity containing window relative to the height of pathName. value is a real number indicating the ratio of the height of the cavity to the height of pathName. as the height of pathName changes, so will the height of window. if value is 0.0 or less, the height of the cavity is the requested height of window. the default is 0.0.
    • -relwidth value β€” specifies the width of the cavity containing window relative to the width of pathName. value is a real number indicating the ratio of the width of the cavity to the width of IpathName. as the height of pathName changes, so will the height of window. if value is 0.0 or less, the width of the cavity is the requested width of window. the default is 0.0.
    • -width value β€” species the width of the cavity containing the child window. value must be in a form accepted by Tk_GetPixels. if value is greater than zero, the cavity is resized to that width. if the requested window width is greater than the cavity's width, the window will be reduced to fit the cavity. by default, the cavity is the requested width of the child window.
  • pathName configure ?window? ?option? ?value option value ...? β€” queries or modifies the configuration options of the text widget or one of its embedded widgets. if no window argument is present, the htext widget itself is configured. otherwise window is the pathname of a widget already embedded into the htext widget β€” and then this command configures the options for the embedded widget.

if option isn't specified, a list describing all of the current options for pathName or window is returned. if option is specified, but not value, then a list describing the option option is returned. if one or more option and value pairs are specified, then for each pair, the htext or embedded window option option is set to value.

the following options are valid for the htext widget.

✨ OPTIONS ✨

okay so these are the options, bestie. Each one is a little knob you can turn to make your htext widget do the thing. Slay. πŸ’–

  • -background color β€” sets the background of the htext widget to color. The default is white. So clean. ✨
  • -cursor cursor β€” picks the cursor for the htext widget. The default cursor is pencil ✏️. It's giving study buddy.
  • -filename fileName β€” tells the widget which htext file to display. If you set it to the empty string (""), then the -text option is used instead. No cap. For the full tea on the file format, check the FILE FORMAT section. πŸ“
  • -font fontName β€” sets the font of the text in the htext widget to fontName. The default is *-Helvetica-Bold-R-Normal-*-12-120-*. Periodt. πŸ’…
  • -foreground color β€” sets the foreground of the htext widget to color. This is literally the color of the text. The default is <black>black</black>. πŸ–€
  • -height pixels β€” specifies the height of the htext widget window. In pixels, bestie. πŸ“
  • -linespacing pixels β€” specifies the spacing between each line of text. The value must be in a form accepted by Tk_GetPixels. The default value is 1 pixel. So cozy. 🧡
  • -specialchar number β€” specifies the ASCII value of the special double character delimiters. In htext files, the text between these special characters is evaluated as a block of Tcl commands. The default special character is 0x25 (the percent sign). It's giving magic. ✨
  • -text text β€” specifies the text to be displayed in the htext widget. Text can be any valid string of characters. See FILE FORMAT for the description. πŸ“
  • -xscrollcommand string β€” specifies the prefix for a command used to communicate with horizontal scrollbars. When the view in the htext widget's window changes (or whenever anything else occurs that could change the display in a scrollbar, such as a change in the total size of the widget's contents), the widget invokes string concatenated by two numbers. Each of the numbers is a fraction between 0 and 1, which indicates a position in the document. If this option is not specified, then no command will be executed. πŸ›ž
  • -yscrollcommand string β€” specifies the prefix for a command used to communicate with vertical scrollbars. When the view in the htext widget's window changes (or whenever anything else occurs that could change the display in a scrollbar, such as a change in the total size of the widget's contents), the widget invokes string concatenated by two numbers. Each of the numbers is a fraction between 0 and 1, which indicates a position in the document. If this option is not specified, then no command will be executed. ⬆️⬇️
  • -width pixels β€” specifies the desired width of the viewport window. If pixels is less than one, the window will grow to accommodate the widest line of text. Flexible queen. πŸ“
  • -xscrollunits pixels β€” specifies the horizontal scrolling distance. The default is 10 pixels. ↔️
  • -yscrollunits pixels β€” specifies the vertical scrolling distance. The default is 10 pixels. ↕️

✨ COMMANDS ✨

now the commands, bestie. These are how you actually talk to your widget. πŸ’¬

  • pathName gotoline ?index? β€” sets the top line of the text to index. index must be a valid text index (the character offset is ignored). If an index isn't provided, the current line number is returned. πŸ“
  • pathName scan mark position β€” records position and the current view in the text window; used in conjunction with later scan dragto commands. position must be in the form @x,y, where x and y are window coordinates. Typically this command is associated with a mouse button press in the widget. It returns an empty string. πŸ–±οΈ
  • pathName scan dragto position β€” computes the difference between position and the position registered in the last scan mark command for the widget. The view is then adjusted up or down by 10 times the difference in coordinates. This command can be associated with mouse motion events to produce the effect of dragging the text at high speed through the window. position must be in the form @x,y, where x and y are window coordinates. The command returns an empty string. πŸš€
  • pathName search pattern ?from? ?to? β€” returns the number of the next line matching pattern. pattern is a string which obeys the matching rules of Tcl_StringMatch. from and to are text line numbers (inclusive) which bound the search. If no match for pattern can be found, -1 is returned. πŸ”
  • pathName xview ?position? β€” moves the viewport horizontally to the new text x-coordinate position. position is the offset from the left side of the text to the current position and must be in a form accepted by Tk_GetPixels. If position is not present, the current text position is returned. ↔️
  • pathName yview ?position? β€” moves the viewport vertically to the new text y-coordinate position. position is the offset from the top of the text to the current position and must be in a form accepted by Tk_GetPixels. If position is not present, the current text position is returned. ↕️

πŸ’€ BUGS πŸ’€

Text with embedded tabs can be obscured by child windows when scrolled horizontally. Not the vibe, but we move. 😭

πŸ”‘ KEYWORDS πŸ”‘

hypertext, widget


and that's the whole page, bestie! this was from BLT 2.5, blt::htext(3tcl). love u, bye! πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from