283 Рефакторинг

This commit is contained in:
prospero78su 2019-05-07 10:58:24 +03:00
parent 605b0a69fc
commit 54e360d5f2
7 changed files with 104 additions and 103 deletions

View File

@ -191,8 +191,8 @@ func CreateSelectDialog(title string, items []string, selectedItem int, typ мК
dlg.View.SetModal(true) dlg.View.SetModal(true)
dlg.View.SetPack(мКнст.Vertical) dlg.View.SetPack(мКнст.Vertical)
if typ == SelectDialogList { if typ == мКнст.SelectDialogList {
fList := CreateFrame(dlg.View, 1, 1, BorderNone, 1) fList := CreateFrame(dlg.View, 1, 1, мКнст.BorderNone, 1)
fList.SetPaddings(1, 1) fList.SetPaddings(1, 1)
fList.SetGaps(0, 0) fList.SetGaps(0, 0)
dlg.list = CreateListBox(fList, 15, 5, 1) dlg.list = CreateListBox(fList, 15, 5, 1)
@ -202,14 +202,14 @@ func CreateSelectDialog(title string, items []string, selectedItem int, typ мК
if selectedItem >= 0 && selectedItem < len(items) { if selectedItem >= 0 && selectedItem < len(items) {
dlg.list.SelectItem(selectedItem) dlg.list.SelectItem(selectedItem)
} }
} else if typ == SelectDialogEdit { } else if typ == мКнст.SelectDialogEdit {
CreateFrame(dlg.View, 1, 1, BorderNone, Fixed) CreateFrame(dlg.View, 1, 1, мКнст.BorderNone, мКнст.Fixed)
lb := CreateLabel(dlg.View, 10, 3, items[0], 1) lb := CreateLabel(dlg.View, 10, 3, items[0], 1)
lb.SetMultiline(true) lb.SetMultiline(true)
fWidth, _ := dlg.View.Size() fWidth, _ := dlg.View.Size()
dlg.edit = CreateEditField(dlg.View, fWidth-2, items[1], AutoSize) dlg.edit = CreateEditField(dlg.View, fWidth-2, items[1], мКнст.AutoSize)
CreateFrame(dlg.View, 1, 1, BorderNone, Fixed) CreateFrame(dlg.View, 1, 1, мКнст.BorderNone, мКнст.Fixed)
dlg.edit.OnKeyPress(func(key term.Key, r rune) bool { dlg.edit.OnKeyPress(func(key term.Key, r rune) bool {
var input string var input string
@ -217,7 +217,7 @@ func CreateSelectDialog(title string, items []string, selectedItem int, typ мК
input = dlg.edit.Title() input = dlg.edit.Title()
dlg.edtResult = input dlg.edtResult = input
dlg.value = -1 dlg.value = -1
dlg.result = DialogButton1 dlg.result = мКнст.DialogButton1
WindowManager().DestroyWindow(dlg.View) WindowManager().DestroyWindow(dlg.View)
if dlg.onClose != nil { if dlg.onClose != nil {
@ -228,13 +228,13 @@ func CreateSelectDialog(title string, items []string, selectedItem int, typ мК
return false return false
}) })
} else { } else {
fRadio := CreateFrame(dlg.View, 1, 1, BorderNone, Fixed) fRadio := CreateFrame(dlg.View, 1, 1, мКнст.BorderNone, мКнст.Fixed)
fRadio.SetPaddings(1, 1) fRadio.SetPaddings(1, 1)
fRadio.SetGaps(0, 0) fRadio.SetGaps(0, 0)
fRadio.SetPack(Vertical) fRadio.SetPack(мКнст.Vertical)
dlg.rg = CreateRadioGroup() dlg.rg = CreateRadioGroup()
for _, item := range items { for _, item := range items {
r := CreateRadio(fRadio, AutoSize, item, Fixed) r := CreateRadio(fRadio, мКнст.AutoSize, item, мКнст.Fixed)
dlg.rg.AddItem(r) dlg.rg.AddItem(r)
} }
if selectedItem >= 0 && selectedItem < len(items) { if selectedItem >= 0 && selectedItem < len(items) {
@ -242,14 +242,14 @@ func CreateSelectDialog(title string, items []string, selectedItem int, typ мК
} }
} }
frm1 := CreateFrame(dlg.View, 16, 4, BorderNone, Fixed) frm1 := CreateFrame(dlg.View, 16, 4, мКнст.BorderNone, мКнст.Fixed)
CreateFrame(frm1, 1, 1, BorderNone, 1) CreateFrame(frm1, 1, 1, мКнст.BorderNone, 1)
btn1 := CreateButton(frm1, AutoSize, AutoSize, "OK", Fixed) btn1 := CreateButton(frm1, мКнст.AutoSize, мКнст.AutoSize, "OK", мКнст.Fixed)
btn1.OnClick(func(ev Event) { btn1.OnClick(func(ev мКнст.Event) {
dlg.result = DialogButton1 dlg.result = мКнст.DialogButton1
if dlg.typ == SelectDialogList { if dlg.typ == мКнст.SelectDialogList {
dlg.value = dlg.list.SelectedItem() dlg.value = dlg.list.SelectedItem()
} else if dlg.typ == SelectDialogEdit { } else if dlg.typ == мКнст.SelectDialogEdit {
dlg.edtResult = dlg.edit.Title() dlg.edtResult = dlg.edit.Title()
dlg.value = -1 dlg.value = -1
} else { } else {
@ -261,10 +261,10 @@ func CreateSelectDialog(title string, items []string, selectedItem int, typ мК
} }
}) })
CreateFrame(frm1, 1, 1, BorderNone, 1) CreateFrame(frm1, 1, 1, мКнст.BorderNone, 1)
btn2 := CreateButton(frm1, AutoSize, AutoSize, "Cancel", Fixed) btn2 := CreateButton(frm1, мКнст.AutoSize, мКнст.AutoSize, "Cancel", мКнст.Fixed)
btn2.OnClick(func(ev Event) { btn2.OnClick(func(ev мКнст.Event) {
dlg.result = DialogButton2 dlg.result = мКнст.DialogButton2
dlg.edtResult = "" dlg.edtResult = ""
dlg.value = -1 dlg.value = -1
WindowManager().DestroyWindow(dlg.View) WindowManager().DestroyWindow(dlg.View)
@ -273,16 +273,16 @@ func CreateSelectDialog(title string, items []string, selectedItem int, typ мК
} }
}) })
if typ == SelectDialogEdit { if typ == мКнст.SelectDialogEdit {
ActivateControl(dlg.View, dlg.edit) ActivateControl(dlg.View, dlg.edit)
} else { } else {
ActivateControl(dlg.View, btn2) ActivateControl(dlg.View, btn2)
} }
CreateFrame(frm1, 1, 1, BorderNone, 1) CreateFrame(frm1, 1, 1, мКнст.BorderNone, 1)
dlg.View.OnClose(func(ev Event) bool { dlg.View.OnClose(func(ev мКнст.Event) bool {
if dlg.result == DialogAlive { if dlg.result == мКнст.DialogAlive {
dlg.result = DialogClosed dlg.result = мКнст.DialogClosed
if ev.X != 1 { if ev.X != 1 {
WindowManager().DestroyWindow(dlg.View) WindowManager().DestroyWindow(dlg.View)
} }

16
edit.go
View File

@ -32,7 +32,7 @@ func (e *EditField) setTitleInternal(title string) {
e.title = title e.title = title
if e.onChange != nil { if e.onChange != nil {
ev := Event{Msg: title} ev := мКнст.Event{Msg: title}
e.onChange(ev) e.onChange(ev)
} }
} }
@ -54,7 +54,7 @@ func (e *EditField) Draw() {
x, y := e.Pos() x, y := e.Pos()
w, _ := e.Size() w, _ := e.Size()
parts := []rune(SysObject(ObjEdit)) parts := []rune(SysObject(мКнст.ObjEdit))
chLeft, chRight := string(parts[0]), string(parts[1]) chLeft, chRight := string(parts[0]), string(parts[1])
chStar := "*" chStar := "*"
if len(parts) > 3 { if len(parts) > 3 {
@ -100,11 +100,11 @@ func (e *EditField) Draw() {
} }
} }
fg, bg := RealColor(e.fg, e.Style(), ColorEditText), RealColor(e.bg, e.Style(), ColorEditBack) fg, bg := RealColor(e.fg, e.Style(), мКнст.ColorEditText), RealColor(e.bg, e.Style(), мКнст.ColorEditBack)
if !e.Enabled() { if !e.Enabled() {
fg, bg = RealColor(e.fg, e.Style(), ColorDisabledText), RealColor(e.fg, e.Style(), ColorDisabledBack) fg, bg = RealColor(e.fg, e.Style(), мКнст.ColorDisabledText), RealColor(e.fg, e.Style(), мКнст.ColorDisabledBack)
} else if e.Active() { } else if e.Active() {
fg, bg = RealColor(e.fg, e.Style(), ColorEditActiveText), RealColor(e.bg, e.Style(), ColorEditActiveBack) fg, bg = RealColor(e.fg, e.Style(), мКнст.ColorEditActiveText), RealColor(e.bg, e.Style(), мКнст.ColorEditActiveBack)
} }
SetTextColor(fg) SetTextColor(fg)
@ -253,14 +253,14 @@ func (e *EditField) MaxWidth() int {
// Method does nothing if new size is less than minimal size // Method does nothing if new size is less than minimal size
// EditField height cannot be changed - it equals 1 always // EditField height cannot be changed - it equals 1 always
func (e *EditField) SetSize(width, height int) { func (e *EditField) SetSize(width, height int) {
if width != KeepValue && (width > 1000 || width < e.minW) { if width != мКнст.KeepValue && (width > 1000 || width < e.minW) {
return return
} }
if height != KeepValue && (height > 200 || height < e.minH) { if height != мКнст.KeepValue && (height > 200 || height < e.minH) {
return return
} }
if width != KeepValue { if width != мКнст.KeepValue {
e.width = width e.width = width
} }

View File

@ -46,7 +46,7 @@ func CreateEditField(parent Control, width int, text string, scale int) *EditFie
e.SetTitle(text) e.SetTitle(text)
e.SetEnabled(true) e.SetEnabled(true)
if width == AutoSize { if width == мКнст.AutoSize {
width = xs.Len(text) + 1 width = xs.Len(text) + 1
} }
@ -79,11 +79,11 @@ func (e *EditField) ProcessEvent(event мКнст.Event) bool {
return false return false
} }
if event.Type == EventActivate && event.X == 0 { if event.Type == мКнст.EventActivate && event.X == 0 {
term.HideCursor() term.HideCursor()
} }
if event.Type == EventKey && event.Key != term.KeyTab { if event.Type == мКнст.EventKey && event.Key != term.KeyTab {
if e.onKeyPress != nil { if e.onKeyPress != nil {
res := e.onKeyPress(event.Key, event.Ch) res := e.onKeyPress(event.Key, event.Ch)
if res { if res {

View File

@ -8,6 +8,7 @@ import (
"strings" "strings"
term "github.com/nsf/termbox-go" term "github.com/nsf/termbox-go"
мКнст "./пакКонстанты"
) )
// FileSelectDialog is a dialog to select a file or directory. // FileSelectDialog is a dialog to select a file or directory.
@ -215,34 +216,34 @@ func CreateFileSelectDialog(title, fileMasks, initPath string, selectDir, mustEx
defer WindowManager().EndUpdate() defer WindowManager().EndUpdate()
dlg.View.SetModal(true) dlg.View.SetModal(true)
dlg.View.SetPack(Vertical) dlg.View.SetPack(мКнст.Vertical)
dlg.currPath = initPath dlg.currPath = initPath
dlg.detectPath() dlg.detectPath()
dlg.curDir = CreateLabel(dlg.View, AutoSize, AutoSize, "", Fixed) dlg.curDir = CreateLabel(dlg.View, мКнст.AutoSize, мКнст.AutoSize, "", мКнст.Fixed)
dlg.curDir.SetTextDisplay(AlignRight) dlg.curDir.SetTextDisplay(мКнст.AlignRight)
flist := CreateFrame(dlg.View, 1, 1, BorderNone, 1) flist := CreateFrame(dlg.View, 1, 1, мКнст.BorderNone, 1)
flist.SetPaddings(1, 1) flist.SetPaddings(1, 1)
flist.SetPack(Horizontal) flist.SetPack(мКнст.Horizontal)
dlg.listBox = CreateListBox(flist, 16, ch-20, 1) dlg.listBox = CreateListBox(flist, 16, ch-20, 1)
fselected := CreateFrame(dlg.View, 1, 1, BorderNone, Fixed) fselected := CreateFrame(dlg.View, 1, 1, мКнст.BorderNone, мКнст.Fixed)
// text + edit field to enter name manually // text + edit field to enter name manually
fselected.SetPack(Vertical) fselected.SetPack(мКнст.Vertical)
fselected.SetPaddings(1, 0) fselected.SetPaddings(1, 0)
CreateLabel(fselected, AutoSize, AutoSize, "Selected object:", 1) CreateLabel(fselected, мКнст.AutoSize, мКнст.AutoSize, "Selected object:", 1)
dlg.edFile = CreateEditField(fselected, cw-22, "", 1) dlg.edFile = CreateEditField(fselected, cw-22, "", 1)
// buttons at the right // buttons at the right
blist := CreateFrame(flist, 1, 1, BorderNone, Fixed) blist := CreateFrame(flist, 1, 1, мКнст.BorderNone, мКнст.Fixed)
blist.SetPack(Vertical) blist.SetPack(мКнст.Vertical)
blist.SetPaddings(1, 1) blist.SetPaddings(1, 1)
btnOpen := CreateButton(blist, AutoSize, AutoSize, "Open", Fixed) btnOpen := CreateButton(blist, мКнст.AutoSize, мКнст.AutoSize, "Open", мКнст.Fixed)
btnSelect := CreateButton(blist, AutoSize, AutoSize, "Select", Fixed) btnSelect := CreateButton(blist, мКнст.AutoSize, мКнст.AutoSize, "Select", мКнст.Fixed)
btnCancel := CreateButton(blist, AutoSize, AutoSize, "Cancel", Fixed) btnCancel := CreateButton(blist, мКнст.AutoSize, мКнст.AutoSize, "Cancel", мКнст.Fixed)
btnCancel.OnClick(func(ev Event) { btnCancel.OnClick(func(ev мКнст.Event) {
WindowManager().DestroyWindow(dlg.View) WindowManager().DestroyWindow(dlg.View)
WindowManager().BeginUpdate() WindowManager().BeginUpdate()
dlg.Selected = false dlg.Selected = false
@ -253,7 +254,7 @@ func CreateFileSelectDialog(title, fileMasks, initPath string, selectDir, mustEx
} }
}) })
btnSelect.OnClick(func(ev Event) { btnSelect.OnClick(func(ev мКнст.Event) {
WindowManager().DestroyWindow(dlg.View) WindowManager().DestroyWindow(dlg.View)
WindowManager().BeginUpdate() WindowManager().BeginUpdate()
dlg.Selected = true dlg.Selected = true
@ -272,9 +273,9 @@ func CreateFileSelectDialog(title, fileMasks, initPath string, selectDir, mustEx
} }
}) })
dlg.View.OnClose(func(ev Event) bool { dlg.View.OnClose(func(ev мКнст.Event) bool {
if dlg.result == DialogAlive { if dlg.result == мКнст.DialogAlive {
dlg.result = DialogClosed dlg.result = мКнст.DialogClosed
if ev.X != 1 { if ev.X != 1 {
WindowManager().DestroyWindow(dlg.View) WindowManager().DestroyWindow(dlg.View)
} }
@ -285,7 +286,7 @@ func CreateFileSelectDialog(title, fileMasks, initPath string, selectDir, mustEx
return true return true
}) })
dlg.listBox.OnSelectItem(func(ev Event) { dlg.listBox.OnSelectItem(func(ev мКнст.Event) {
item := ev.Msg item := ev.Msg
if item == ".." { if item == ".." {
btnSelect.SetEnabled(false) btnSelect.SetEnabled(false)
@ -312,7 +313,7 @@ func CreateFileSelectDialog(title, fileMasks, initPath string, selectDir, mustEx
} }
}) })
btnOpen.OnClick(func(ev Event) { btnOpen.OnClick(func(ev мКнст.Event) {
s := dlg.listBox.SelectedItemText() s := dlg.listBox.SelectedItemText()
if s != ".." && (s == "" || !strings.HasSuffix(s, string(os.PathSeparator))) { if s != ".." && (s == "" || !strings.HasSuffix(s, string(os.PathSeparator))) {
return return
@ -325,7 +326,7 @@ func CreateFileSelectDialog(title, fileMasks, initPath string, selectDir, mustEx
} }
}) })
dlg.edFile.OnChange(func(ev Event) { dlg.edFile.OnChange(func(ev мКнст.Event) {
s := "" s := ""
lowCurrText := strings.ToLower(dlg.listBox.SelectedItemText()) lowCurrText := strings.ToLower(dlg.listBox.SelectedItemText())
lowEditText := strings.ToLower(dlg.edFile.Title()) lowEditText := strings.ToLower(dlg.edFile.Title())

View File

@ -22,7 +22,7 @@ type Frame struct {
} }
/* /*
NewFrame creates a new frame. CreateFrame creates a new frame.
view - is a View that manages the control view - is a View that manages the control
parent - is container that keeps the control. The same View can be a view and a parent at the same time. parent - is container that keeps the control. The same View can be a view and a parent at the same time.
width and heigth - are minimal size of the control. width and heigth - are minimal size of the control.
@ -34,15 +34,15 @@ func CreateFrame(parent Control, width, height int, bs мКнст.BorderStyle, s
f := new(Frame) f := new(Frame)
f.BaseControl = NewBaseControl() f.BaseControl = NewBaseControl()
if width == AutoSize { if width == мКнст.AutoSize {
width = 5 width = 5
} }
if height == AutoSize { if height == мКнст.AutoSize {
height = 3 height = 3
} }
if bs == BorderAuto { if bs == мКнст.BorderAuto {
bs = BorderNone bs = мКнст.BorderNone
} }
f.SetSize(width, height) f.SetSize(width, height)
@ -53,7 +53,7 @@ func CreateFrame(parent Control, width, height int, bs мКнст.BorderStyle, s
f.scale = scale f.scale = scale
f.gapX, f.gapY = 0, 0 f.gapX, f.gapY = 0, 0
if bs == BorderNone { if bs == мКнст.BorderNone {
f.padX, f.padY = 0, 0 f.padX, f.padY = 0, 0
} else { } else {
f.padX, f.padY = 1, 1 f.padX, f.padY = 1, 1
@ -65,19 +65,19 @@ func CreateFrame(parent Control, width, height int, bs мКнст.BorderStyle, s
return f return f
} }
//SetScrollable --
func (f *Frame) SetScrollable(scrollable bool) { func (f *Frame) SetScrollable(scrollable bool) {
f.scrollable = scrollable f.scrollable = scrollable
if scrollable { if scrollable {
px, py := f.Paddings() px, py := f.Paddings()
if f.Pack() == Vertical { if f.Pack() == мКнст.Vertical {
px += 1 px++
} }
if f.Pack() == Horizontal { if f.Pack() == мКнст.Horizontal {
py += 1 py++
} }
f.SetPaddings(px, py) f.SetPaddings(px, py)
@ -85,12 +85,12 @@ func (f *Frame) SetScrollable(scrollable bool) {
f.SetClipped(scrollable) f.SetClipped(scrollable)
} }
//Scrollable --
func (f *Frame) Scrollable() bool { func (f *Frame) Scrollable() bool {
return f.scrollable return f.scrollable
} }
// Repaint draws the control on its View surface //Draw Repaint draws the control on its View surface
func (f *Frame) Draw() { func (f *Frame) Draw() {
if f.hidden { if f.hidden {
return return
@ -132,10 +132,10 @@ func (f *Frame) Draw() {
DrawScrollBar(x+w, y, 1, h, f.lastScrollProp) DrawScrollBar(x+w, y, 1, h, f.lastScrollProp)
} }
fg, bg := RealColor(f.fg, f.Style(), ColorViewText), RealColor(f.bg, f.Style(), ColorViewBack) fg, bg := RealColor(f.fg, f.Style(), мКнст.ColorViewText), RealColor(f.bg, f.Style(), мКнст.ColorViewBack)
if f.border == BorderNone { if f.border == мКнст.BorderNone {
if bg != ColorDefault { if bg != мКнст.ColorDefault {
SetBackColor(bg) SetBackColor(bg)
FillRect(x, y, w, h, ' ') FillRect(x, y, w, h, ' ')
} }
@ -173,9 +173,9 @@ func (f *Frame) ScrollTo(x int, y int) {
f.ResizeChildren() f.ResizeChildren()
f.PlaceChildren() f.PlaceChildren()
} }
//ProcessEvent --
func (f *Frame) ProcessEvent(ev мКнст.Event) bool { func (f *Frame) ProcessEvent(ev мКнст.Event) bool {
if ev.Type != EventActivateChild || (!f.scrollable || ev.Target == nil) { if ev.Type != мКнст.EventActivateChild || (!f.scrollable || ev.Target == nil) {
return false return false
} }

View File

@ -33,10 +33,10 @@ func CreateLabel(parent Control, w, h int, title string, scale int) *Label {
c := new(Label) c := new(Label)
c.BaseControl = NewBaseControl() c.BaseControl = NewBaseControl()
if w == AutoSize { if w == мКнст.AutoSize {
w = xs.Len(title) w = xs.Len(title)
} }
if h == AutoSize { if h == мКнст.AutoSize {
h = 1 h = 1
} }
@ -47,7 +47,7 @@ func CreateLabel(parent Control, w, h int, title string, scale int) *Label {
c.SetConstraints(w, h) c.SetConstraints(w, h)
c.SetScale(scale) c.SetScale(scale)
c.tabSkip = true c.tabSkip = true
c.textDisplay = AlignLeft c.textDisplay = мКнст.AlignLeft
if parent != nil { if parent != nil {
parent.AddChild(c) parent.AddChild(c)
@ -74,9 +74,9 @@ func (l *Label) Draw() {
PushAttributes() PushAttributes()
defer PopAttributes() defer PopAttributes()
fg, bg := RealColor(l.fg, l.Style(), ColorText), RealColor(l.bg, l.Style(), ColorBack) fg, bg := RealColor(l.fg, l.Style(), мКнст.ColorText), RealColor(l.bg, l.Style(), мКнст.ColorBack)
if !l.Enabled() { if !l.Enabled() {
fg = RealColor(l.fg, l.Style(), ColorDisabledText) fg = RealColor(l.fg, l.Style(), мКнст.ColorDisabledText)
} }
SetTextColor(fg) SetTextColor(fg)
@ -104,17 +104,17 @@ func (l *Label) Draw() {
SetBackColor(elem.Bg) SetBackColor(elem.Bg)
putCharUnsafe(xx, yy, elem.Ch) putCharUnsafe(xx, yy, elem.Ch)
if l.direction == Horizontal { if l.direction == мКнст.Horizontal {
xx += 1 xx++
if xx >= l.x+l.width { if xx >= l.x+l.width {
xx = l.x xx = l.x
yy += 1 yy++
} }
} else { } else {
yy += 1 yy++
if yy >= l.y+l.height { if yy >= l.y+l.height {
yy = l.y yy = l.y
xx += 1 xx++
} }
} }
} }
@ -122,7 +122,7 @@ func (l *Label) Draw() {
elem = parser.NextElement() elem = parser.NextElement()
} }
} else { } else {
if l.direction == Horizontal { if l.direction == мКнст.Horizontal {
shift, str := AlignColorizedText(l.title, l.width, l.align) shift, str := AlignColorizedText(l.title, l.width, l.align)
if str != l.title && l.align != l.textDisplay { if str != l.title && l.align != l.textDisplay {
shift, str = AlignColorizedText(l.title, l.width, l.textDisplay) shift, str = AlignColorizedText(l.title, l.width, l.textDisplay)
@ -165,7 +165,7 @@ func (l *Label) TextDisplay() мКнст.Align {
// for the property. Any other value does is skipped and does not affect // for the property. Any other value does is skipped and does not affect
// displaying the title // displaying the title
func (l *Label) SetTextDisplay(align мКнст.Align) { func (l *Label) SetTextDisplay(align мКнст.Align) {
if align != AlignLeft && align != AlignRight { if align != мКнст.AlignLeft && align != мКнст.AlignRight {
return return
} }

View File

@ -41,10 +41,10 @@ func CreateListBox(parent Control, width, height int, scale int) *ListBox {
l := new(ListBox) l := new(ListBox)
l.BaseControl = NewBaseControl() l.BaseControl = NewBaseControl()
if height == AutoSize { if height == мКнст.AutoSize {
height = 3 height = 3
} }
if width == AutoSize { if width == мКнст.AutoSize {
width = 5 width = 5
} }
@ -88,11 +88,11 @@ func (l *ListBox) drawItems() {
maxDy := l.height - 1 maxDy := l.height - 1
maxWidth := l.width - 1 maxWidth := l.width - 1
fg, bg := RealColor(l.fg, l.Style(), ColorEditText), RealColor(l.bg, l.Style(), ColorEditBack) fg, bg := RealColor(l.fg, l.Style(), мКнст.ColorEditText), RealColor(l.bg, l.Style(), мКнст.ColorEditBack)
if l.Active() { if l.Active() {
fg, bg = RealColor(l.fg, l.Style(), ColorEditActiveText), RealColor(l.bg, l.Style(), ColorEditActiveBack) fg, bg = RealColor(l.fg, l.Style(), мКнст.ColorEditActiveText), RealColor(l.bg, l.Style(), мКнст.ColorEditActiveBack)
} }
fgSel, bgSel := RealColor(l.fgActive, l.Style(), ColorSelectionText), RealColor(l.bgActive, l.Style(), ColorSelectionBack) fgSel, bgSel := RealColor(l.fgActive, l.Style(), мКнст.ColorSelectionText), RealColor(l.bgActive, l.Style(), мКнст.ColorSelectionBack)
for curr <= maxCurr && dy <= maxDy { for curr <= maxCurr && dy <= maxDy {
f, b := fg, bg f, b := fg, bg
@ -123,9 +123,9 @@ func (l *ListBox) Draw() {
x, y := l.Pos() x, y := l.Pos()
w, h := l.Size() w, h := l.Size()
fg, bg := RealColor(l.fg, l.Style(), ColorEditText), RealColor(l.bg, l.Style(), ColorEditBack) fg, bg := RealColor(l.fg, l.Style(), мКнст.ColorEditText), RealColor(l.bg, l.Style(), мКнст.ColorEditBack)
if l.Active() { if l.Active() {
fg, bg = RealColor(l.fg, l.Style(), ColorEditActiveText), RealColor(l.bg, l.Style(), ColorEditActiveBack) fg, bg = RealColor(l.fg, l.Style(), мКнст.ColorEditActiveText), RealColor(l.bg, l.Style(), мКнст.ColorEditActiveBack)
} }
SetTextColor(fg) SetTextColor(fg)
SetBackColor(bg) SetBackColor(bg)
@ -145,7 +145,7 @@ func (l *ListBox) home() {
l.topLine = 0 l.topLine = 0
if l.onSelectItem != nil { if l.onSelectItem != nil {
ev := Event{Y: l.currSelection, Msg: l.SelectedItemText()} ev := мКнст.Event{Y: l.currSelection, Msg: l.SelectedItemText()}
l.onSelectItem(ev) l.onSelectItem(ev)
} }
} }
@ -163,7 +163,7 @@ func (l *ListBox) end() {
} }
if l.onSelectItem != nil { if l.onSelectItem != nil {
ev := Event{Y: l.currSelection, Msg: l.SelectedItemText()} ev := мКнст.Event{Y: l.currSelection, Msg: l.SelectedItemText()}
l.onSelectItem(ev) l.onSelectItem(ev)
} }
} }
@ -189,7 +189,7 @@ func (l *ListBox) moveUp(dy int) {
l.EnsureVisible() l.EnsureVisible()
if l.onSelectItem != nil { if l.onSelectItem != nil {
ev := Event{Y: l.currSelection, Msg: l.SelectedItemText()} ev :=мКнст.Event{Y: l.currSelection, Msg: l.SelectedItemText()}
l.onSelectItem(ev) l.onSelectItem(ev)
} }
} }
@ -210,7 +210,7 @@ func (l *ListBox) moveDown(dy int) {
l.EnsureVisible() l.EnsureVisible()
if l.onSelectItem != nil { if l.onSelectItem != nil {
ev := Event{Y: l.currSelection, Msg: l.SelectedItemText()} ev := мКнст.Event{Y: l.currSelection, Msg: l.SelectedItemText()}
l.onSelectItem(ev) l.onSelectItem(ev)
} }
} }
@ -287,7 +287,7 @@ func (l *ListBox) processMouseClick(ev мКнст.Event) bool {
onSelFunc := l.onSelectItem onSelFunc := l.onSelectItem
WindowManager().EndUpdate() WindowManager().EndUpdate()
if onSelFunc != nil { if onSelFunc != nil {
ev := Event{Y: l.topLine + dy, Msg: l.SelectedItemText()} ev := мКнст.Event{Y: l.topLine + dy, Msg: l.SelectedItemText()}
onSelFunc(ev) onSelFunc(ev)
} }
@ -316,7 +316,7 @@ func (l *ListBox) ProcessEvent(event мКнст.Event) bool {
} }
switch event.Type { switch event.Type {
case EventKey: case мКнст.EventKey:
if l.onKeyPress != nil { if l.onKeyPress != nil {
res := l.onKeyPress(event.Key) res := l.onKeyPress(event.Key)
if res { if res {
@ -345,13 +345,13 @@ func (l *ListBox) ProcessEvent(event мКнст.Event) bool {
return true return true
case term.KeyCtrlM: case term.KeyCtrlM:
if l.currSelection != -1 && l.onSelectItem != nil { if l.currSelection != -1 && l.onSelectItem != nil {
ev := Event{Y: l.currSelection, Msg: l.SelectedItemText()} ev := мКнст.Event{Y: l.currSelection, Msg: l.SelectedItemText()}
l.onSelectItem(ev) l.onSelectItem(ev)
} }
default: default:
return false return false
} }
case EventMouse: case мКнст.EventMouse:
return l.processMouseClick(event) return l.processMouseClick(event)
} }