func NewProjectOpener(theme gxui.Theme, projPane gxui.Control) *ProjectOpener { return &ProjectOpener{ statusKeeper: statusKeeper{theme: theme}, name: theme.CreateTextBox(), projPane: projPane, } }
func NewGotoLine(theme gxui.Theme) *GotoLine { input := theme.CreateTextBox() input.OnTextChanged(func([]gxui.TextBoxEdit) { runes := []rune(input.Text()) for index := 0; index < len(runes); index++ { if !unicode.IsDigit(runes[index]) { runes = append(runes[:index], runes[index+1:]...) index-- } } text := string(runes) if text != input.Text() { input.SetText(text) } }) return &GotoLine{ statusKeeper: statusKeeper{theme: theme}, lineNumInput: input, } }
// Create implements gxui.TreeNode. func (n *node) Create(theme gxui.Theme) gxui.Control { layout := theme.CreateLinearLayout() layout.SetDirection(gxui.LeftToRight) label := theme.CreateLabel() label.SetText(n.name) textbox := theme.CreateTextBox() textbox.SetText(n.name) textbox.SetPadding(math.ZeroSpacing) textbox.SetMargin(math.ZeroSpacing) addButton := theme.CreateButton() addButton.SetText("+") addButton.OnClick(func(gxui.MouseEvent) { n.add("<new>") }) edit := func() { layout.RemoveAll() layout.AddChild(textbox) layout.AddChild(addButton) gxui.SetFocus(textbox) } commit := func() { n.name = textbox.Text() label.SetText(n.name) layout.RemoveAll() layout.AddChild(label) layout.AddChild(addButton) } // When the user clicks the label, replace it with an editable text-box label.OnClick(func(gxui.MouseEvent) { edit() }) // When the text-box loses focus, replace it with a label again. textbox.OnLostFocus(commit) layout.AddChild(label) layout.AddChild(addButton) return layout }