Esempio n. 1
0
static void ScaleDoLayout(void *clientData)
{
    WidgetCore *corePtr = clientData;
    Ttk_Element slider = Ttk_FindElement(corePtr->layout, "slider");

    Ttk_PlaceLayout(corePtr->layout,corePtr->state,Ttk_WinBox(corePtr->tkwin));

    /* Adjust the slider position:
     */
    if (slider) {
	Scale *scalePtr = clientData;
	Ttk_Box troughBox = TroughBox(scalePtr);
	Ttk_Box sliderBox = Ttk_ElementParcel(slider);
	double value = 0.0;
	double fraction;
	int range;

	Tcl_GetDoubleFromObj(NULL, scalePtr->scale.valueObj, &value);
	fraction = ScaleFraction(scalePtr, value);

	if (scalePtr->scale.orient == TTK_ORIENT_HORIZONTAL) {
	    range = troughBox.width - sliderBox.width;
	    sliderBox.x += (int)(fraction * range);
	} else {
	    range = troughBox.height - sliderBox.height;
	    sliderBox.y += (int)(fraction * range);
	}
	Ttk_PlaceElement(corePtr->layout, slider, sliderBox);
    }
}
static void
SquareDoLayout(void *clientData)
{
    WidgetCore *corePtr = (WidgetCore *)clientData;
    Ttk_Box winBox;
    Ttk_Element squareNode;

    squareNode = Ttk_FindElement(corePtr->layout, "square");
    winBox = Ttk_WinBox(corePtr->tkwin);
    Ttk_PlaceLayout(corePtr->layout, corePtr->state, winBox);

    /*
     * Adjust the position of the square element within the widget according
     * to the -anchor option.
     */

    if (squareNode) {
	Square *squarePtr = clientData;
	Tk_Anchor anchor = TK_ANCHOR_CENTER;
	Ttk_Box b;

	b = Ttk_ElementParcel(squareNode);
	if (squarePtr->square.anchorObj != NULL)
	    Tk_GetAnchorFromObj(NULL, squarePtr->square.anchorObj, &anchor);
	b = Ttk_AnchorBox(winBox, b.width, b.height, anchor);

	Ttk_PlaceElement(corePtr->layout, squareNode, b);
    }
}
Esempio n. 3
0
/*
 * ScrollbarDoLayout --
 * 	Layout hook.  Adjusts the position of the scrollbar thumb.
 *
 * Side effects:
 * 	Sets sb->troughBox and sb->minSize.
 */
static void ScrollbarDoLayout(void *recordPtr)
{
    Scrollbar *sb = recordPtr;
    WidgetCore *corePtr = &sb->core;
    Ttk_Element thumb;
    Ttk_Box thumbBox;
    int thumbWidth, thumbHeight;
    double first, last, size;
    int minSize;

    /*
     * Use generic layout manager to compute initial layout:
     */
    Ttk_PlaceLayout(corePtr->layout,corePtr->state,Ttk_WinBox(corePtr->tkwin));

    /*
     * Locate thumb element, extract parcel and requested minimum size:
     */
    thumb = Ttk_FindElement(corePtr->layout, "thumb");
    if (!thumb)	/* Something has gone wrong -- bail */
	return;

    sb->scrollbar.troughBox = thumbBox = Ttk_ElementParcel(thumb);
    Ttk_LayoutNodeReqSize(
	corePtr->layout, thumb, &thumbWidth,&thumbHeight);

    /*
     * Adjust thumb element parcel:
     */
    first = sb->scrollbar.first;
    last  = sb->scrollbar.last;

    if (sb->scrollbar.orient == TTK_ORIENT_VERTICAL) {
	minSize = thumbHeight;
	size = thumbBox.height - minSize;
	thumbBox.y += (int)(size * first);
	thumbBox.height = (int)(size * last) + minSize - (int)(size * first);
    } else {
	minSize = thumbWidth;
	size = thumbBox.width - minSize;
	thumbBox.x += (int)(size * first);
	thumbBox.width = (int)(size * last) + minSize - (int)(size * first);
    }
    sb->scrollbar.minSize = minSize;
    Ttk_PlaceElement(corePtr->layout, thumb, thumbBox);
}
Esempio n. 4
0
/*
 * TroughRange --
 * 	Return the value area of the trough element, adjusted
 * 	for slider size.
 */
static Ttk_Box TroughRange(Scale *scalePtr)
{
    Ttk_Box troughBox = TroughBox(scalePtr);
    Ttk_Element slider = Ttk_FindElement(scalePtr->core.layout,"slider");

    /*
     * If this is a scale widget, adjust range for slider:
     */
    if (slider) {
	Ttk_Box sliderBox = Ttk_ElementParcel(slider);
	if (scalePtr->scale.orient == TTK_ORIENT_HORIZONTAL) {
	    troughBox.x += sliderBox.width / 2;
	    troughBox.width -= sliderBox.width;
	} else {
	    troughBox.y += sliderBox.height / 2;
	    troughBox.height -= sliderBox.height;
	}
    }

    return troughBox;
}