NiGui icon indicating copy to clipboard operation
NiGui copied to clipboard

BackgroundColor

Open qqtop opened this issue 6 years ago • 4 comments

I do something like this:

# setup for queryButton
var queryButton = newButton(" Run Query ")
queryButton.fontSize = 18
queryButton.textColor = rgb(30,144,255)     # color ok
queryButton.backGroundcolor = rgb(0,255,0)  # no effect ?
rightMenuContainer.add(queryButton)

textColor method works for button and labels only other controls eg textBox does not show any text or background color changes at all.

PS.: nigui is really nice and hopefully there will be a comboBox widget I am using it to display output from sql queries. Here running under openSuse Tumbleweed .

qqtop avatar Jul 17 '17 09:07 qqtop

As far as I know, the underlying platforms Gtk and WinAPI do not allow to change the background color of a button (resp. it has no effect). This is something which should be mentioned in the upcoming NiGui documentation.

If you want to have a button with a specific background color, you can create a custom control based on the type Button. Here an example implementation of a custom button. The main program has to use newToolbarButton() instead of newButton().

type ToolbarButton* = ref object of Button

proc newToolbarButton*(text = ""): ToolbarButton =
  result = new ToolbarButton
  result.init()
  result.text = text

method handleDrawEvent*(control: ToolbarButton, event: DrawEvent) =
  let canvas = event.control.canvas
  canvas.areaColor = control.backgroundColor
  canvas.textColor = control.textColor
  canvas.lineColor = control.textColor
  canvas.drawRectArea(0, 0, control.width, control.height)
  canvas.drawTextCentered(control.text)
  canvas.drawRectOutline(0, 0, control.width, control.height)

Thanks for your feedback :)

simonkrauter avatar Jul 17 '17 20:07 simonkrauter

Well in Gtk you can do this: https://stackoverflow.com/questions/1706550/gtk-modifying-background-color-of-gtkbutton, and for WinAPI you have this: http://winprog.org/tutorial/dlgfaq.html

PMunch avatar Jul 18 '17 16:07 PMunch

Is this issue still up to date?

theAkito avatar Jul 31 '22 22:07 theAkito

Yes. Same issue than #152.

simonkrauter avatar Aug 01 '22 19:08 simonkrauter