closes #2 - button size includes shadow size

This commit is contained in:
Vladimir Markelov 2015-09-24 16:57:38 -07:00
parent d663414d76
commit a9f289b121
2 changed files with 22 additions and 17 deletions

View File

@ -35,8 +35,11 @@ func NewButton(parent Window, id WinId, x, y, width, height int, title string, p
b := new(Button)
b.SetEnabled(true)
b.SetPos(x, y)
if height < 1 {
height = 3
if height < 4 {
height = 4
}
if width < 6 {
width = 6
}
b.SetSize(width, height)
b.anchor = props.Anchors
@ -47,7 +50,7 @@ func NewButton(parent Window, id WinId, x, y, width, height int, title string, p
b.visible = true
b.tabStop = true
b.id = id
b.minW, b.minH = 5, 3
b.minW, b.minH = 6, 4
return b
}
@ -73,10 +76,10 @@ func (b *Button) GetConstraints() (int, int) {
}
func (b *Button) SetConstraints(minW, minH int) {
if minW >= 5 {
if minW >= 6 {
b.minW = minW
}
if minH >= 3 {
if minH >= 4 {
b.minH = minH
}
}
@ -123,14 +126,14 @@ func (b *Button) Redraw(canvas Canvas) {
shadow = tm.GetSysColor(ColorControlShadow)
}
dy := int(h / 2)
dy := int((h - 1) / 2)
if !b.pressed {
canvas.ClearRect(x+1, y+1, w, h, shadow)
canvas.ClearRect(x, y, w, h, bg)
canvas.DrawAlignedText(x, y+dy, w, b.title, fg, bg, AlignCenter)
canvas.ClearRect(x+1, y+1, w-1, h-1, shadow)
canvas.ClearRect(x, y, w-1, h-1, bg)
canvas.DrawAlignedText(x, y+dy, w-1, b.title, fg, bg, AlignCenter)
} else {
canvas.ClearRect(x+1, y+1, w, h, bg)
canvas.DrawAlignedText(x+1, y+1+dy, w, b.title, fg, bg, AlignCenter)
canvas.ClearRect(x+1, y+1, w-1, h-1, bg)
canvas.DrawAlignedText(x+1, y+1+dy, w-1, b.title, fg, bg, AlignCenter)
}
}

View File

@ -37,9 +37,11 @@ func createDynamicView(c *ui.Composer) {
packMain := wnd.AddPack(ui.PackHorizontal)
packLeft := packMain.AddPack(ui.PackVertical, 1)
packLeft.SetBorderStyle(ui.BorderSingle)
packLeft.SetText("Task Progress")
packRight := packMain.AddPack(ui.PackVertical, ui.DoNotScale)
packRight.SetBorderStyle(ui.BorderDouble)
packRight.SetText("Event List")
ts := packRight.PackTextScroll(30, 10, 1, ui.Props{})
// Here are a lot of additional Packers because it is not possible to mix
@ -62,14 +64,14 @@ func createDynamicView(c *ui.Composer) {
ts.AddItem(fmt.Sprintf("New ProgressBar value: %v", v))
updateProgress(v, pb)
})
packBtn.PackFrame(2, 1, "", 1, emptyProp)
btnStep := packBtn.PackButton(6, 3, "Step", ui.DoNotScale, emptyProp)
packBtn.PackFrame(1, 1, "", 1, emptyProp)
btnStep := packBtn.PackButton(7, 3, "Step", ui.DoNotScale, emptyProp)
btnStep.OnClick(func(ev ui.Event) {
go pb.Step()
ts.AddItem("ProgressBar step")
})
packBtn.PackFrame(2, 1, "", 1, emptyProp)
btnQuit := packBtn.PackButton(6, 3, "Quit", ui.DoNotScale, emptyProp)
packBtn.PackFrame(1, 1, "", 1, emptyProp)
btnQuit := packBtn.PackButton(7, 3, "Quit", ui.DoNotScale, emptyProp)
btnQuit.OnClick(func(ev ui.Event) {
go c.Stop()
})
@ -106,12 +108,12 @@ func createManualView(c *ui.Composer) {
updateProgress(v, pb)
})
btnStep := ui.CreateButton(wnd, 1+11+2, 6, 6, 3, "Step", ui.Props{Anchors: ui.AnchorBottom})
btnStep := ui.CreateButton(wnd, 1+11+1, 6, 7, 3, "Step", ui.Props{Anchors: ui.AnchorBottom})
btnStep.OnClick(func(ev ui.Event) {
go pb.Step()
ts.AddItem("ProgressBar step")
})
btnQuit := ui.CreateButton(wnd, 1+11+2+6+2, 6, 6, 3, "Quit", ui.Props{Anchors: ui.AnchorBottom | ui.AnchorRight})
btnQuit := ui.CreateButton(wnd, 1+11+1+7+1, 6, 7, 3, "Quit", ui.Props{Anchors: ui.AnchorBottom | ui.AnchorRight})
btnQuit.OnClick(func(ev ui.Event) {
go c.Stop()
})