// UpdateText repaints the text to an image associated with a particular // CycleChoice. The text is retrieved by calling CycleChoice.CycleText. func (ci *CycleItem) UpdateText() { t := ci.cycle.theme txt := ci.choice.CycleText() err := text.DrawText(ci.text, t.Font, t.FontSize, t.FontColor, t.BgColor, txt) if err != nil { logger.Warning.Printf("(*CycleItem).UpdateText: "+ "Could not render text: %s", err) } }
func (si *SelectItem) UpdateText() { t := si.slct.theme si.text = si.choice.SelectText() // Always have some text. if len(si.text) == 0 { si.text = "N/A" } err := text.DrawText(si.regular, t.Font, t.FontSize, t.FontColor, t.BgColor, si.text) if err != nil { logger.Warning.Printf("(*SelectItem).UpdateText: "+ "Could not render text: %s", err) } err = text.DrawText(si.highlighted, t.Font, t.FontSize, t.ActiveFontColor, t.ActiveBgColor, si.text) if err != nil { logger.Warning.Printf("(*SelectItem).UpdateText: "+ "Could not render text: %s", err) } }
func (si *SelectGroupItem) UpdateText() { t := si.slct.theme txt := si.group.SelectGroupText() // Create a one pixel window and exit if there's no text. if len(txt) == 0 { si.win.Resize(1, 1) return } err := text.DrawText(si.win, t.GroupFont, t.GroupFontSize, t.GroupFontColor, t.GroupBgColor, txt) if err != nil { logger.Warning.Printf("(*SelectGroupItem).UpdateText: "+ "Could not render text: %s", err) } }
func (inp *Input) Show(workarea xrect.Rect, label string, do func(inp *Input, text string), canceled func(inp *Input)) bool { if inp.showing { return false } inp.win.Stack(xproto.StackModeAbove) inp.input.Reset() text.DrawText(inp.label, inp.theme.Font, inp.theme.FontSize, inp.theme.FontColor, inp.theme.BgColor, label) pad, bs := inp.theme.Padding, inp.theme.BorderSize width := (pad * 2) + (bs * 2) + inp.label.Geom.Width() + inp.theme.InputWidth height := (pad * 2) + (bs * 2) + inp.label.Geom.Height() // position the damn window based on its width/height (i.e., center it) posx := workarea.X() + workarea.Width()/2 - width/2 posy := workarea.Y() + workarea.Height()/2 - height/2 inp.win.MoveResize(posx, posy, width, height) inp.label.Move(bs+pad, pad+bs) inp.bInp.MoveResize(pad+inp.label.Geom.X()+inp.label.Geom.Width(), 0, bs, height) inp.bTop.Resize(width, bs) inp.bBot.MoveResize(0, height-bs, width, bs) inp.bLft.Resize(bs, height) inp.bRht.MoveResize(width-bs, 0, bs, height) inp.input.Move(inp.bInp.Geom.X()+inp.bInp.Geom.Width(), bs) inp.showing = true inp.do = do inp.canceled = canceled inp.win.Map() inp.input.Focus() inp.historyIndex = len(inp.history) return true }
func (msg *Message) Show(workarea xrect.Rect, message string, duration time.Duration, hidden func(msg *Message)) bool { if msg.showing { return false } msg.win.Stack(xproto.StackModeAbove) pad, bs := msg.theme.Padding, msg.theme.BorderSize height := pad + bs width := 0 for _, line := range strings.Split(strings.TrimSpace(message), "\n") { textWin := xwindow.Must(xwindow.Create(msg.X, msg.win.Id)) msg.textWins = append(msg.textWins, textWin) if len(line) == 0 { line = " " } textWin.Map() textWin.Move(bs+pad, height) text.DrawText(textWin, msg.theme.Font, msg.theme.FontSize, msg.theme.FontColor, msg.theme.BgColor, line) height += textWin.Geom.Height() if w := textWin.Geom.Width(); w > width { width = w } } height += pad + bs width += pad*2 + bs*2 // position the damn window based on its width/height (i.e., center it) posx := workarea.X() + workarea.Width()/2 - width/2 posy := workarea.Y() + workarea.Height()/2 - height/2 msg.win.MoveResize(posx, posy, width, height) msg.bTop.Resize(width, bs) msg.bBot.MoveResize(0, height-bs, width, bs) msg.bLft.Resize(bs, height) msg.bRht.MoveResize(width-bs, 0, bs, height) msg.showing = true msg.duration = duration msg.hidden = hidden msg.win.Map() msg.lastShow = time.Now() // If the duration is non-zero, then wait for that amount of time and // automatically hide the popup. Otherwise, focus the window and wait // for user interaction. if duration == 0 { msg.bTop.Focus() } else { go func() { // If `Hide` is called before the timeout expires, we'll // cancel the timeout. select { case <-time.After(duration): msg.Hide() case <-msg.cancelTimeout: } }() } return true }