Closed EasiestSoft closed 4 years ago
Try this:
import wNim/[wApp, wFrame, wPanel, wTextCtrl, wStatusBar, wFont]
let app = App()
let frame = Frame(title = "TextCtrl Fit Height", size=(432,321),
style=wDefaultFrameStyle or wDoubleBuffered)
let panel = Panel(frame)
let text = TextCtrl(panel, size=frame.clientSize, style = wBorderStatic or wTeMultiLine or wTeRich or wTeReadOnly)
text.setFont(Font(12))
text.value =
"""
wNim is Nim's Windows GUI Framework, based on winim
Layout DSL is powered by Yuriy Glukhov's Kiwi constraint solving library
Basic code structure:
import wNim
let app = App()
let frame = Frame(title="Hello World", size=(400, 300))
frame.center()
frame.show()
app.mainLoop()"""
discard StatusBar(frame)
text.fit()
frame.clientSize = text.size
frame.center()
frame.show()
app.mainLoop()
Thanks There are controls under the text control. This is sample code. Can it be improved?
import wNim/[wApp, wFrame, wPanel, wTextCtrl, wStatusBar, wStaticText, wFont]
let app = App()
let frame = Frame(title = "TextCtrl Fit Height", size=(432,321),
style=wDefaultFrameStyle or wDoubleBuffered)
let panel = Panel(frame)
let text = TextCtrl(panel, size=frame.clientSize, style = wBorderStatic or wTeMultiLine or wTeRich or wTeReadOnly)
let infoA = StaticText(panel, label = "information A", style = wAlignLeft or wAlignMiddle)
let infoB = StaticText(panel, label = "information B", style = wAlignLeft or wAlignMiddle)
text.setFont(Font(12))
text.value =
"""
wNim is Nim's Windows GUI Framework, based on winim
Layout DSL is powered by Yuriy Glukhov's Kiwi constraint solving library
Basic code structure:
import wNim
let app = App()
let frame = Frame(title="Hello World", size=(400, 300))
frame.center()
frame.show()
app.mainLoop()"""
discard StatusBar(frame)
proc layout() =
panel.autolayout: """
H:|[text]|
H:|-[infoA(infoB)]-[infoB]-|
V:|[text]-[infoA,infoB]-|
"""
panel.wEvent_size do():
layout()
text.fit()
var text_size = text.size
text_size.height = text_size.height + 20 # add spacing size
text.size = text_size
var frame_size = text.size
frame_size.height = frame_size.height + infoA.size.height
frame.clientSize = frame_size
frame.center()
frame.show()
app.mainLoop()
Improve which part?
wNim is amazing, thanks for your help
Is there a way to calculate the height required by TextCtrl and automatically adjust the height to fit the text?
Today, I tested a program on a low-resolution screen, and the last line was not completely displayed. If the program can automatically calculate the height required for TextCtrl, then I do n’t have to worry about the screen resolution