support for GTK 3.98.3
This commit is contained in:
parent
e20c95abf5
commit
a725770ff0
15 changed files with 386 additions and 193 deletions
|
|
@ -1,6 +1,8 @@
|
|||
# https://github.com/GNOME/gtk/blob/mainline/tests/testheaderbar.c
|
||||
# this is still based on the original testheaderbar.c, which was recently replaced by testheaderbar2.c
|
||||
# and testheaderbar.c is not a very good Nim GTK4 example unfortunately -- too comlicated and strange code.
|
||||
# nim c headerbar.nim
|
||||
import gintro/[gtk4, glib, gobject, gio]
|
||||
import gintro/[gtk4, glib, gobject]
|
||||
|
||||
const
|
||||
Css = """
|
||||
|
|
@ -22,7 +24,7 @@ const
|
|||
# we try to avoid use of global header variable as done in C code
|
||||
type
|
||||
MyWindow = ref object of gtk4.Window
|
||||
header: gtk4.Headerbar
|
||||
header: gtk4.Widget
|
||||
|
||||
proc response(d: gtk4.FileChooserDialog; responseID: int) = gtk4.destroy(d)
|
||||
|
||||
|
|
@ -34,11 +36,11 @@ proc onBookmarkClicked(button: Button; data: MyWindow) =
|
|||
chooser.connect("response", response)
|
||||
chooser.show
|
||||
|
||||
proc changeSubtitle(button: Button; w: MyWindow) =
|
||||
if w.header.subtitle == "":
|
||||
w.header.setSubtitle("(subtle subtitle)")
|
||||
else:
|
||||
w.header.setSubtitle("") # can we pass nil?
|
||||
#proc changeSubtitle(button: Button; w: MyWindow) =
|
||||
# if w.header.subtitle == "":
|
||||
# w.header.setSubtitle("(subtle subtitle)")
|
||||
# else:
|
||||
# w.header.setSubtitle("") # can we pass nil?
|
||||
|
||||
proc toggleFullscreen(button: Button; window: MyWindow) =
|
||||
var fullscreen {.global.}: bool
|
||||
|
|
@ -54,65 +56,82 @@ proc toIntVal(i: int): Value =
|
|||
discard init(result, gtype)
|
||||
setInt(result, i)
|
||||
|
||||
proc quit(b: Button) = gtk4.mainQuit()
|
||||
var done = false
|
||||
|
||||
proc quit_cb(b: Button) = # we can not pass a var parameter
|
||||
#gtk4.mainQuit()
|
||||
done = true
|
||||
wakeup(defaultMainContext()) # g_main_context_wakeup (NULL);
|
||||
|
||||
proc changeHeader(button: ToggleButton; window: MyWindow) =
|
||||
if button != nil and button.getActive:
|
||||
window.header = cast[HeaderBar](newBox(gtk4.Orientation.horizontal,
|
||||
10)) # intended cast, see C code!
|
||||
addClass(getStyleContext(window.header), "titlebar")
|
||||
addClass(getStyleContext(window.header), "header-bar")
|
||||
window.header.setProperty("margin", toIntVal(10))
|
||||
window.header = (newBox(gtk4.Orientation.horizontal,
|
||||
10))
|
||||
addCssClass(window.header, "titlebar")
|
||||
addCssClass(window.header, "header-bar")
|
||||
#window.header.setProperty("margin_start", toIntVal(10))
|
||||
#window.header.setProperty("margin_end", toIntVal(10))
|
||||
#window.header.setProperty("margin_top", toIntVal(10))
|
||||
#window.header.setProperty("margin_bottom", toIntVal(10))
|
||||
window.header.setMarginStart(10)
|
||||
window.header.setMarginEnd(10)
|
||||
window.header.setMarginTop(10)
|
||||
window.header.setMarginBottom(10)
|
||||
let label = newLabel("Label")
|
||||
window.header.add(label)
|
||||
gtk4.Box(window.header).append(label)
|
||||
let levelBar = newLevelBar()
|
||||
levelBar.setValue(0.4)
|
||||
levelBar.setHexpand
|
||||
window.header.add(levelBar)
|
||||
gtk4.Box(window.header).append(levelBar)
|
||||
else:
|
||||
window.header = newHeaderBar()
|
||||
addClass(getStyleContext(window.header), "titlebar")
|
||||
window.header.setTitle("Example header")
|
||||
#addClass(getStyleContext(window.header), "titlebar")
|
||||
addCssClass(window.header, "titlebar")
|
||||
#window.header.setTitle("Example header")
|
||||
var button = newButton("_Close")
|
||||
button.setUseUnderline
|
||||
addClass(getStyleContext(button), "suggested-action")
|
||||
button.connect("clicked", quit)
|
||||
window.header.packEnd(button)
|
||||
addCssClass(button, "suggested-action")
|
||||
button.connect("clicked", quit_cb)
|
||||
gtk4.HeaderBar(window.header).packEnd(button)
|
||||
button = newButton()
|
||||
let image = newImageFromIconName("bookmark-new-symbolic")
|
||||
button.connect("clicked", onBookmarkClicked, window)
|
||||
button.add(image)
|
||||
window.header.packStart(button)
|
||||
button.setChild(image)
|
||||
gtk4.HeaderBar(window.header).packStart(button)
|
||||
window.setTitlebar(window.header)
|
||||
|
||||
proc main =
|
||||
gtk4.init()
|
||||
var window: MyWindow
|
||||
initWindow(window)
|
||||
addClass(getStyleContext(window), "main")
|
||||
#var window: MyWindow
|
||||
let window = newWindow(MyWindow)
|
||||
addCssClass(window, "main") # gtk_widget_add_css_class (window, "main");
|
||||
let provider = newCssProvider()
|
||||
provider.loadFromData(Css)
|
||||
addProviderForDisplay(getDisplay(window), provider, STYLE_PROVIDER_PRIORITY_USER)
|
||||
changeHeader(nil, window)
|
||||
let box = newBox(Orientation.vertical, 0)
|
||||
window.add(box)
|
||||
window.setChild(box) # gtk_window_set_child (GTK_WINDOW (window), box);
|
||||
#window.add(box)
|
||||
let content = newImageFromIconName("start-here-symbolic")
|
||||
content.setPixelSize(512)
|
||||
box.add(content)
|
||||
content.setVexpand
|
||||
box.append(content)
|
||||
let footer = newActionBar()
|
||||
footer.setCenterWidget(newCheckButtonWithLabel("Middle"))
|
||||
let button = newToggleButtonWithLabel("Custom")
|
||||
button.connect("clicked", changeHeader, window)
|
||||
footer.packStart(button)
|
||||
var button1 = newButton("Subtitle")
|
||||
button1.connect("clicked", changeSubtitle, window)
|
||||
footer.packEnd(button1)
|
||||
button1 = newButton("Fullscreen")
|
||||
#var button1 = newButton("Subtitle")
|
||||
#button1.connect("clicked", changeSubtitle, window)
|
||||
#footer.packEnd(button1)
|
||||
var button1 = newButton("Fullscreen")
|
||||
footer.packEnd(button1)
|
||||
button1.connect("clicked", toggleFullscreen, window)
|
||||
box.add(footer)
|
||||
box.append(footer)
|
||||
window.show
|
||||
gtk4.main()
|
||||
#gtk4.main()
|
||||
while not done:
|
||||
discard iteration(defaultMainContext(), true) # g_main_context_iteration (NULL, TRUE);
|
||||
destroy(window) # this is special for this example, see https://discourse.gnome.org/t/tests-testgaction-c/2232/6
|
||||
|
||||
main() # 118 lines
|
||||
main() # 137 lines
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue