Skip to content

Commit

Permalink
Improved the appearance of the Treeitem.indicator element.
Browse files Browse the repository at this point in the history
  • Loading branch information
csaba committed Sep 21, 2024
1 parent 24b099e commit e57fccc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
9 changes: 5 additions & 4 deletions generic/ttk/ttkDefaultTheme.c
Original file line number Diff line number Diff line change
Expand Up @@ -1249,14 +1249,14 @@ static Ttk_ElementSpec SliderElementSpec = {
typedef struct {
Tcl_Obj *colorObj;
Tcl_Obj *marginObj;
Tcl_Obj *diameterObj;
Tcl_Obj *sizeObj;
} TreeitemIndicator;

static Ttk_ElementOptionSpec TreeitemIndicatorOptions[] = {
{ "-foreground", TK_OPTION_COLOR,
Tk_Offset(TreeitemIndicator,colorObj), DEFAULT_FOREGROUND },
{ "-diameter", TK_OPTION_PIXELS,
Tk_Offset(TreeitemIndicator,diameterObj), "9" },
Tk_Offset(TreeitemIndicator,sizeObj), "9" },
{ "-indicatormargins", TK_OPTION_STRING,
Tk_Offset(TreeitemIndicator,marginObj), "2 2 4 2" },
{ NULL, TK_OPTION_BOOLEAN, 0, NULL }
Expand All @@ -1274,7 +1274,8 @@ static void TreeitemIndicatorSize(
int size = 0;
Ttk_Padding margins;

Tk_GetPixelsFromObj(NULL, tkwin, indicator->diameterObj, &size);
Tk_GetPixelsFromObj(NULL, tkwin, indicator->sizeObj, &size);
if (size % 2 == 0) --size; /* An odd size is better for the indicator. */
Ttk_GetPaddingFromObj(NULL, tkwin, indicator->marginObj, &margins);
*widthPtr = size + Ttk_PaddingWidth(margins);
*heightPtr = size + Ttk_PaddingHeight(margins);
Expand All @@ -1297,7 +1298,7 @@ static void TreeitemIndicatorDraw(
return;
}

Ttk_GetPaddingFromObj(NULL,tkwin,indicator->marginObj,&padding);
Ttk_GetPaddingFromObj(NULL, tkwin, indicator->marginObj, &padding);
b = Ttk_PadBox(b, padding);

XDrawRectangle(Tk_Display(tkwin), d, gc,
Expand Down
27 changes: 23 additions & 4 deletions generic/ttk/ttkTreeview.c
Original file line number Diff line number Diff line change
Expand Up @@ -3501,12 +3501,12 @@ static void TreeitemIndicatorSize(
TCL_UNUSED(Ttk_Padding *))
{
TreeitemIndicator *indicator = (TreeitemIndicator *)elementRecord;
Ttk_Padding margins;
int size = 0;
Ttk_Padding margins;

Ttk_GetPaddingFromObj(NULL, tkwin, indicator->marginsObj, &margins);
Tk_GetPixelsFromObj(NULL, tkwin, indicator->sizeObj, &size);
if (size % 2 == 0) --size; /* An odd size is better for the arrow. */
if (size % 2 == 0) --size; /* An odd size is better for the indicator. */
Ttk_GetPaddingFromObj(NULL, tkwin, indicator->marginsObj, &margins);

*widthPtr = size + Ttk_PaddingWidth(margins);
*heightPtr = size + Ttk_PaddingHeight(margins);
Expand All @@ -3524,15 +3524,34 @@ static void TreeitemIndicatorDraw(
ArrowDirection direction =
(state & TTK_STATE_OPEN) ? ARROW_DOWN : ARROW_RIGHT;
Ttk_Padding margins;
int cx, cy;
XColor *borderColor = Tk_GetColorFromObj(tkwin, indicator->colorObj);
XGCValues gcvalues; GC gc; unsigned mask;

if (state & TTK_STATE_LEAF) /* don't draw anything */
return;

Ttk_GetPaddingFromObj(NULL,tkwin,indicator->marginsObj,&margins);
Ttk_GetPaddingFromObj(NULL, tkwin, indicator->marginsObj, &margins);
b = Ttk_PadBox(b, margins);

switch (direction) {
case ARROW_DOWN:
TtkArrowSize(b.width/2, direction, &cx, &cy);
if ((b.height - cy) % 2 == 1) {
++cy;
}
break;
case ARROW_RIGHT:
default:
TtkArrowSize(b.height/2, direction, &cx, &cy);
if ((b.width - cx) % 2 == 1) {
++cx;
}
break;
}

b = Ttk_AnchorBox(b, cx, cy, TK_ANCHOR_CENTER);

gcvalues.foreground = borderColor->pixel;
gcvalues.line_width = 1;
mask = GCForeground | GCLineWidth;
Expand Down

0 comments on commit e57fccc

Please sign in to comment.