Update code for layouts, objects
This commit is contained in:
107
scrollbar.go
107
scrollbar.go
@@ -35,19 +35,20 @@ func newScrollbar (orient string) *Scrollbar {
|
||||
this.Add(this.handle)
|
||||
this.SetFocusable(true)
|
||||
|
||||
this.CaptureDND(true)
|
||||
this.CaptureMouse(true)
|
||||
this.CaptureScroll(true)
|
||||
this.CaptureKeyboard(true)
|
||||
this.CatchDND(true)
|
||||
this.CatchMouse(true)
|
||||
|
||||
this.OnKeyUp(this.handleKeyUp)
|
||||
this.OnKeyDown(this.handleKeyDown)
|
||||
this.OnMouseDown(this.handleMouseDown)
|
||||
this.OnMouseUp(this.handleMouseUp)
|
||||
this.OnButtonDown(this.handleButtonDown)
|
||||
this.OnButtonUp(this.handleButtonUp)
|
||||
this.OnMouseMove(this.handleMouseMove)
|
||||
this.OnScroll(this.handleScroll)
|
||||
|
||||
this.handle.SetRole(tomo.R("objects", "SliderHandle", orient))
|
||||
this.SetRole(tomo.R("objects", "Slider", orient))
|
||||
this.handle.SetRole(tomo.R("objects", "SliderHandle"))
|
||||
this.handle.SetTag(orient, true)
|
||||
this.SetRole(tomo.R("objects", "Slider"))
|
||||
this.SetTag(orient, true)
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -120,22 +121,48 @@ func (this *Scrollbar) OnValueChange (callback func ()) event.Cookie {
|
||||
return this.on.valueChange.Connect(callback)
|
||||
}
|
||||
|
||||
func (this *Scrollbar) handleKeyDown (key input.Key, numpad bool) {
|
||||
// PageSize returns the scroll distance of a page.
|
||||
func (this *Scrollbar) PageSize () int {
|
||||
if this.layout.linked == nil { return 0 }
|
||||
viewport := this.layout.linked.GetBox().InnerBounds()
|
||||
if this.layout.vertical {
|
||||
return viewport.Dy()
|
||||
} else {
|
||||
return viewport.Dx()
|
||||
}
|
||||
}
|
||||
|
||||
// StepSize returns the scroll distance of a step.
|
||||
func (this *Scrollbar) StepSize () int {
|
||||
// FIXME: this should not be hardcoded, need to get base font metrics
|
||||
// from tomo somehow. should be (emspace, lineheight)
|
||||
return 16
|
||||
}
|
||||
|
||||
func (this *Scrollbar) handleKeyUp (catch func (), key input.Key, numpad bool) {
|
||||
catch()
|
||||
}
|
||||
|
||||
func (this *Scrollbar) handleKeyDown (catch func (), key input.Key, numpad bool) {
|
||||
catch()
|
||||
|
||||
var increment float64; if this.layout.vertical {
|
||||
increment = -0.05
|
||||
} else {
|
||||
increment = 0.05
|
||||
}
|
||||
|
||||
modifiers := this.Window().Modifiers()
|
||||
|
||||
switch key {
|
||||
case input.KeyUp, input.KeyLeft:
|
||||
if this.Modifiers().Alt {
|
||||
if modifiers.Alt {
|
||||
this.SetValue(0)
|
||||
} else {
|
||||
this.SetValue(this.Value() - increment)
|
||||
}
|
||||
case input.KeyDown, input.KeyRight:
|
||||
if this.Modifiers().Alt {
|
||||
if modifiers.Alt {
|
||||
this.SetValue(1)
|
||||
} else {
|
||||
this.SetValue(this.Value() + increment)
|
||||
@@ -147,8 +174,10 @@ func (this *Scrollbar) handleKeyDown (key input.Key, numpad bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func (this *Scrollbar) handleMouseDown (button input.Button) {
|
||||
pointer := this.MousePosition()
|
||||
func (this *Scrollbar) handleButtonDown (catch func (), button input.Button) {
|
||||
catch()
|
||||
|
||||
pointer := this.Window().MousePosition()
|
||||
handle := this.handle.Bounds()
|
||||
|
||||
within := pointer.In(handle)
|
||||
@@ -173,20 +202,21 @@ func (this *Scrollbar) handleMouseDown (button input.Button) {
|
||||
}
|
||||
case input.ButtonMiddle:
|
||||
if above {
|
||||
this.scrollBy(this.pageSize())
|
||||
this.scrollBy(this.PageSize())
|
||||
} else {
|
||||
this.scrollBy(-this.pageSize())
|
||||
this.scrollBy(-this.PageSize())
|
||||
}
|
||||
case input.ButtonRight:
|
||||
if above {
|
||||
this.scrollBy(this.stepSize())
|
||||
this.scrollBy(this.StepSize())
|
||||
} else {
|
||||
this.scrollBy(-this.stepSize())
|
||||
this.scrollBy(-this.StepSize())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (this *Scrollbar) handleMouseUp (button input.Button) {
|
||||
func (this *Scrollbar) handleButtonUp (catch func (), button input.Button) {
|
||||
catch()
|
||||
if button != input.ButtonLeft || !this.dragging { return }
|
||||
this.dragging = false
|
||||
}
|
||||
@@ -196,7 +226,8 @@ func (this *Scrollbar) handleMouseMove () {
|
||||
this.drag()
|
||||
}
|
||||
|
||||
func (this *Scrollbar) handleScroll (x, y float64) {
|
||||
func (this *Scrollbar) handleScroll (catch func(), x, y float64) {
|
||||
catch()
|
||||
if this.layout.linked == nil { return }
|
||||
this.layout.linked.ScrollTo (
|
||||
this.layout.linked.ContentBounds().Min.
|
||||
@@ -204,7 +235,7 @@ func (this *Scrollbar) handleScroll (x, y float64) {
|
||||
}
|
||||
|
||||
func (this *Scrollbar) drag () {
|
||||
pointer := this.MousePosition().Sub(this.dragOffset)
|
||||
pointer := this.Window().MousePosition().Sub(this.dragOffset)
|
||||
gutter := this.InnerBounds()
|
||||
handle := this.handle.Bounds()
|
||||
|
||||
@@ -229,22 +260,6 @@ func (this *Scrollbar) fallbackDragOffset () image.Point {
|
||||
}
|
||||
}
|
||||
|
||||
func (this *Scrollbar) pageSize () int {
|
||||
if this.layout.linked == nil { return 0 }
|
||||
viewport := this.layout.linked.GetBox().InnerBounds()
|
||||
if this.layout.vertical {
|
||||
return viewport.Dy()
|
||||
} else {
|
||||
return viewport.Dx()
|
||||
}
|
||||
}
|
||||
|
||||
func (this *Scrollbar) stepSize () int {
|
||||
// FIXME: this should not be hardcoded, need to get base font metrics
|
||||
// from tomo.somehow. should be (emspace, lineheight)
|
||||
return 16
|
||||
}
|
||||
|
||||
func (this *Scrollbar) scrollBy (distance int) {
|
||||
if this.layout.linked == nil { return }
|
||||
var vector image.Point; if this.layout.vertical {
|
||||
@@ -283,14 +298,14 @@ type scrollbarLayout struct {
|
||||
linked tomo.ContentObject
|
||||
}
|
||||
|
||||
func (scrollbarLayout) MinimumSize (hints tomo.LayoutHints, boxes []tomo.Box) image.Point {
|
||||
if len(boxes) != 1 { return image.Pt(0, 0) }
|
||||
return boxes[0].MinimumSize()
|
||||
func (scrollbarLayout) MinimumSize (hints tomo.LayoutHints, boxes tomo.BoxQuerier) image.Point {
|
||||
if boxes.Len() != 1 { return image.Pt(0, 0) }
|
||||
return boxes.MinimumSize(0)
|
||||
}
|
||||
|
||||
func (this scrollbarLayout) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
||||
if len(boxes) != 1 { return }
|
||||
handle := image.Rectangle { Max: boxes[0].MinimumSize() }
|
||||
func (this scrollbarLayout) Arrange (hints tomo.LayoutHints, boxes tomo.BoxArranger) {
|
||||
if boxes.Len() != 1 { return }
|
||||
handle := image.Rectangle { Max: boxes.MinimumSize(0) }
|
||||
gutter := hints.Bounds
|
||||
|
||||
var gutterLength float64;
|
||||
@@ -311,7 +326,7 @@ func (this scrollbarLayout) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
||||
// and we shouldn't be adding and removing boxes, so this is
|
||||
// really the only good way to hide things.
|
||||
// TODO perhaps have a "Hidden" rectangle in the Tomo API?
|
||||
boxes[0].SetBounds(image.Rect(-16, -16, 0, 0))
|
||||
boxes.SetBounds(0, image.Rect(-32, -32, -16, -16))
|
||||
return
|
||||
}
|
||||
if this.vertical {
|
||||
@@ -331,15 +346,15 @@ func (this scrollbarLayout) Arrange (hints tomo.LayoutHints, boxes []tomo.Box) {
|
||||
handle = handle.Sub(handleOffset).Add(gutter.Min)
|
||||
|
||||
// place handle
|
||||
boxes[0].SetBounds(handle)
|
||||
boxes.SetBounds(0, handle)
|
||||
|
||||
}
|
||||
|
||||
func (this scrollbarLayout) RecommendedHeight (hints tomo.LayoutHints, boxes []tomo.Box, width int) int {
|
||||
func (this scrollbarLayout) RecommendedHeight (hints tomo.LayoutHints, boxes tomo.BoxQuerier, width int) int {
|
||||
return this.MinimumSize(hints, boxes).X
|
||||
}
|
||||
|
||||
func (this scrollbarLayout) RecommendedWidth (hints tomo.LayoutHints, boxes []tomo.Box, height int) int {
|
||||
func (this scrollbarLayout) RecommendedWidth (hints tomo.LayoutHints, boxes tomo.BoxQuerier, height int) int {
|
||||
return this.MinimumSize(hints, boxes).Y
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user