Beispiel #1
0
func (l *ScrollLayout) LayoutChildren() {
	s := l.outer.Size().Contract(l.Padding())
	o := l.Padding().LT()

	var sxs, sys math.Size
	if l.canScrollX {
		sxs = l.scrollBarX.Control.DesiredSize(math.ZeroSize, s)
	}
	if l.canScrollY {
		sys = l.scrollBarY.Control.DesiredSize(math.ZeroSize, s)
	}

	l.scrollBarX.Layout(math.CreateRect(0, s.H-sxs.H, s.W-sys.W, s.H).Canon().Offset(o))
	l.scrollBarY.Layout(math.CreateRect(s.W-sys.W, 0, s.W, s.H-sxs.H).Canon().Offset(o))

	l.innerSize = s.Contract(math.Spacing{R: sys.W, B: sxs.H})

	if l.child != nil {
		max := l.innerSize
		if l.canScrollX {
			max.W = math.MaxSize.W
		}
		if l.canScrollY {
			max.H = math.MaxSize.H
		}
		cs := l.child.Control.DesiredSize(math.ZeroSize, max)
		l.child.Layout(cs.Rect().Offset(l.scrollOffset.Neg()).Offset(o))
		l.scrollBarX.Control.(gxui.ScrollBar).SetScrollLimit(cs.W)
		l.scrollBarY.Control.(gxui.ScrollBar).SetScrollLimit(cs.H)
	}

	l.SetScrollOffset(l.scrollOffset)
}
Beispiel #2
0
func (t *PanelTab) Paint(c gxui.Canvas) {
	s := t.Size()
	var style Style
	switch {
	case t.IsMouseDown(gxui.MouseButtonLeft) && t.IsMouseOver():
		style = t.theme.TabPressedStyle
	case t.IsMouseOver():
		style = t.theme.TabOverStyle
	default:
		style = t.theme.TabDefaultStyle
	}
	if l := t.Label(); l != nil {
		l.SetColor(style.FontColor)
	}

	c.DrawRoundedRect(s.Rect(), 5.0, 5.0, 0.0, 0.0, style.Pen, style.Brush)

	if t.HasFocus() {
		style = t.theme.FocusedStyle
		r := math.CreateRect(1, 1, s.W-1, s.H-1)
		c.DrawRoundedRect(r, 4.0, 4.0, 0.0, 0.0, style.Pen, style.Brush)
	}

	if t.active {
		style = t.theme.TabActiveHighlightStyle
		r := math.CreateRect(1, s.H-1, s.W-1, s.H)
		c.DrawRect(r, style.Brush)
	}

	t.Button.Paint(c)
}
Beispiel #3
0
func (l *SplitterLayout) LayoutChildren() {
	s := l.outer.Size().Contract(l.Padding())
	o := l.Padding().LT()

	children := l.outer.Children()

	splitterCount := len(children) / 2

	splitterWidth := l.splitterWidth
	if l.orientation.Horizontal() {
		s.W -= splitterWidth * splitterCount
	} else {
		s.H -= splitterWidth * splitterCount
	}

	netWeight := float32(0.0)
	for i, c := range children {
		if isSplitter := (i & 1) == 1; !isSplitter {
			netWeight += l.weights[c.Control]
		}
	}

	d := 0
	for i, c := range children {
		var cr math.Rect
		if isSplitter := (i & 1) == 1; !isSplitter {
			cm := c.Control.Margin()
			frac := l.weights[c.Control] / netWeight
			if l.orientation.Horizontal() {
				cw := int(float32(s.W) * frac)
				cr = math.CreateRect(d+cm.L, cm.T, d+cw-cm.R, s.H-cm.B)
				d += cw
			} else {
				ch := int(float32(s.H) * frac)
				cr = math.CreateRect(cm.L, d+cm.T, s.W-cm.R, d+ch-cm.B)
				d += ch
			}
		} else {
			if l.orientation.Horizontal() {
				cr = math.CreateRect(d, 0, d+splitterWidth, s.H)
			} else {
				cr = math.CreateRect(0, d, s.W, d+splitterWidth)
			}
			d += splitterWidth
		}
		c.Layout(cr.Offset(o).Canon())
	}
}
Beispiel #4
0
func (l *CodeEditorLine) PaintBorders(c gxui.Canvas, info CodeEditorLinePaintInfo) {
	start, _ := info.LineSpan.Span()
	offsets := info.GlyphOffsets
	for _, layer := range l.ce.layers {
		if layer != nil && layer.BorderColor() != nil {
			color := *layer.BorderColor()
			interval.Visit(layer.Spans(), info.LineSpan, func(vs, ve uint64, _ int) {
				s, e := vs-start, ve-start
				r := math.CreateRect(offsets[s].X, 0, offsets[e-1].X+info.GlyphWidth, info.LineHeight)
				c.DrawRoundedRect(r, 3, 3, 3, 3, gxui.CreatePen(0.5, color), gxui.TransparentBrush)
			})
		}
	}
}
Beispiel #5
0
func (t *TextBox) LayoutChildren() {
	t.List.LayoutChildren()
	if t.scrollBarEnabled {
		size := t.Size().Contract(t.Padding())
		scrollAreaSize := size
		scrollAreaSize.W -= t.scrollBar.Size().W

		offset := t.Padding().LT()
		barSize := t.horizScroll.DesiredSize(math.ZeroSize, scrollAreaSize)
		t.horizScrollChild.Layout(math.CreateRect(0, size.H-barSize.H, scrollAreaSize.W, size.H).Canon().Offset(offset))

		maxLineWidth := t.outer.MaxLineWidth()
		entireContentVisible := size.W > maxLineWidth
		t.horizScroll.SetVisible(!entireContentVisible)
	}
}
Beispiel #6
0
func (p *PanelHolder) LayoutChildren() {
	s := p.Size()

	tabHeight := p.tabLayout.DesiredSize(math.ZeroSize, s).H
	panelRect := math.CreateRect(0, tabHeight, s.W, s.H).Contract(p.Padding())

	for _, child := range p.Children() {
		if child.Control == p.tabLayout {
			child.Control.SetSize(math.Size{W: s.W, H: tabHeight})
			child.Offset = math.ZeroPoint
		} else {
			rect := panelRect.Contract(child.Control.Margin())
			child.Control.SetSize(rect.Size())
			child.Offset = rect.Min
		}
	}
}
Beispiel #7
0
func (l *CodeEditorLine) PaintBackgroundSpans(c gxui.Canvas, info CodeEditorLinePaintInfo) {
	start, _ := info.LineSpan.Span()
	offsets := info.GlyphOffsets
	remaining := interval.IntDataList{info.LineSpan}
	for _, layer := range l.ce.layers {
		if layer != nil && layer.BackgroundColor() != nil {
			color := *layer.BackgroundColor()
			for _, span := range layer.Spans().Overlaps(info.LineSpan) {
				interval.Visit(&remaining, span, func(vs, ve uint64, _ int) {
					s, e := vs-start, ve-start
					r := math.CreateRect(offsets[s].X, 0, offsets[e-1].X+info.GlyphWidth, info.LineHeight)
					c.DrawRoundedRect(r, 3, 3, 3, 3, gxui.TransparentPen, gxui.Brush{Color: color})
				})
				interval.Remove(&remaining, span)
			}
		}
	}
}
Beispiel #8
0
func (l *TableLayout) LayoutChildren() {
	s := l.outer.Size().Contract(l.outer.Padding())
	o := l.outer.Padding().LT()

	cw, ch := s.W/l.columns, s.H/l.rows

	var cr math.Rect

	for _, c := range l.outer.Children() {
		cm := c.Control.Margin()
		cell := l.grid[c.Control]

		x, y := cell.x*cw, cell.y*ch
		w, h := x+cell.w*cw, y+cell.h*ch

		cr = math.CreateRect(x+cm.L, y+cm.T, w-cm.R, h-cm.B)

		c.Layout(cr.Offset(o).Canon())
	}
}
Beispiel #9
0
func (p *glyphPage) add(face fnt.Face, r rune) bool {
	if _, found := p.entries[r]; found {
		panic("Glyph already added to glyph page")
	}

	b, mask, maskp, _, _ := face.Glyph(fixed.Point26_6{}, r)
	bounds := math.CreateRect(b.Min.X, b.Min.Y, b.Max.X, b.Max.Y)

	w, h := bounds.Size().WH()
	x, y := p.nextPoint.X, p.nextPoint.Y

	if x+w > p.size.W {
		// Row full, start new line
		x = 0
		y += p.rowHeight + glyphPadding
		p.rowHeight = 0
	}

	if y+h > p.size.H {
		return false // Page full
	}

	draw.Draw(p.image, image.Rect(x, y, x+w, y+h), mask, maskp, draw.Src)

	p.entries[r] = glyphEntry{
		offset: math.Point{X: x, Y: y}.Sub(bounds.Min),
		bounds: bounds,
	}
	p.nextPoint = math.Point{X: x + w + glyphPadding, Y: y}
	if h > p.rowHeight {
		p.rowHeight = h
	}
	p.tex = nil

	return true
}
Beispiel #10
0
func (v *viewport) drawFrameUpdate(ctx *context) {
	dx := (ctx.stats.frameCount * 10) & 0xFF
	r := math.CreateRect(dx-5, 0, dx+5, 3)
	ds := &drawState{}
	ctx.blitter.blitRect(ctx, r, gxui.White, ds)
}
Beispiel #11
0
func (l *List) LayoutChildren() {
	if l.adapter == nil {
		l.outer.RemoveAll()
		return
	}

	if !l.RelayoutSuspended() {
		// Disable relayout on AddChild / RemoveChild as we're performing layout here.
		l.SetRelayoutSuspended(true)
		defer l.SetRelayoutSuspended(false)
	}

	s := l.outer.Size().Contract(l.Padding())
	o := l.Padding().LT()

	var itemSize math.Size
	if l.orientation.Horizontal() {
		itemSize = math.Size{W: l.itemSize.W, H: s.H}
	} else {
		itemSize = math.Size{W: s.W, H: l.itemSize.H}
	}

	startIndex, endIndex := l.VisibleItemRange(true)
	majorAxisItemSize := l.MajorAxisItemSize()

	d := startIndex*majorAxisItemSize - l.scrollOffset

	mark := l.layoutMark
	l.layoutMark++

	for idx := startIndex; idx < endIndex; idx++ {
		item := l.adapter.ItemAt(idx)

		details, found := l.details[item]
		if found {
			if details.mark == mark {
				panic(fmt.Errorf("Adapter for control '%s' returned duplicate item (%v) for indices %v and %v",
					gxui.Path(l.outer), item, details.index, idx))
			}
		} else {
			control := l.adapter.Create(l.theme, idx)
			details.onClickSubscription = control.OnClick(func(ev gxui.MouseEvent) {
				l.ItemClicked(ev, item)
			})
			details.child = l.AddChildAt(0, control)
		}
		details.mark = mark
		details.index = idx
		l.details[item] = details

		c := details.child
		cm := c.Control.Margin()
		cs := itemSize.Contract(cm).Max(math.ZeroSize)
		if l.orientation.Horizontal() {
			c.Layout(math.CreateRect(d, cm.T, d+cs.W, cm.T+cs.H).Offset(o))
		} else {
			c.Layout(math.CreateRect(cm.L, d, cm.L+cs.W, d+cs.H).Offset(o))
		}
		d += majorAxisItemSize
	}

	// Reap unused items
	for item, details := range l.details {
		if details.mark != mark {
			details.onClickSubscription.Unlisten()
			l.RemoveChild(details.child.Control)
			delete(l.details, item)
		}
	}

	if l.scrollBarEnabled {
		ss := l.scrollBar.DesiredSize(math.ZeroSize, s)
		if l.Orientation().Horizontal() {
			l.scrollBarChild.Layout(math.CreateRect(0, s.H-ss.H, s.W, s.H).Canon().Offset(o))
		} else {
			l.scrollBarChild.Layout(math.CreateRect(s.W-ss.W, 0, s.W, s.H).Canon().Offset(o))
		}

		// Only show the scroll bar if needed
		entireContentVisible := startIndex == 0 && endIndex == l.itemCount
		l.scrollBar.SetVisible(!entireContentVisible)
	}

	l.UpdateItemMouseOver()
}