khchen / wNim

Nim's Windows GUI Framework
MIT License
327 stars 17 forks source link

textCtrl size should change according to font size #34

Closed sk-Prime closed 5 years ago

sk-Prime commented 5 years ago
let textentry = TextCtrl(panel, value="", style=wBorderSunken)
textentry.font = Font(20, faceName="consolas")

in this example, textCtrl can not show font properly because the font size is bigger than textCtrl size.

Q: how to change textCtrl size manualy, as textentry.fit() make textCtrl size smallest because init value is = "", and i don't want to change textCtrl length, i want it to be fixed length. if there are 4 char in textCtrl, the fit() make it small and show only 4 char.

khchen commented 5 years ago
  1. You can change the font of the panel before wTextCtrl creation. Because the font is inheritable, the wTextCtrl will get the correct size when creation.

  2. If you change the font of a control after creation. You can set the size to its getDefaultSize(). And this is what wWindow.suit() does. For example: textentry.suit() or textentry.size = textentry.defaultSize, it in actually is textentry.setSize(textentry.getDefaultSize()).

  3. For current implementation, getDefaultSize() for wTextCtrl use a fix width. You can also change it after suit() but keep the height. For example: textentry.size = (200, wDefault).

sk-Prime commented 5 years ago

thanks it solves the problem.