-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CSS example with individual button styles (#57)
- Loading branch information
1 parent
d3ea2c5
commit 1ad006f
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# css-style.jl | ||
# Illustrate setting/changing individual button styles | ||
|
||
using Gtk4 | ||
|
||
css = """ | ||
window { | ||
background-color: teal; | ||
} | ||
button:hover { | ||
background-color: green; | ||
} | ||
.button2 { | ||
background: orange; | ||
color: purple; | ||
font-style: italic; | ||
} | ||
.button3 { | ||
background: grey; | ||
color: red; | ||
font-size: 18px; | ||
font-style: normal; | ||
font-weight: bold; | ||
} | ||
.button4 { | ||
background: #FFCB05; | ||
color: #00274C; | ||
} | ||
""" | ||
|
||
win = GtkWindow("Colorful Buttons") | ||
cssprov = GtkCssProvider(css) | ||
push!(Gtk4.display(win), cssprov) # applies CSS to all widgets | ||
|
||
b1 = GtkButton("Default style") | ||
b2 = GtkButton("Purple italiic") | ||
b3 = GtkButton("Bold red: Click me") | ||
add_css_class(b2, "button2") # goes with ".button2" in css | ||
add_css_class(b3, "button3") | ||
|
||
signal_connect(b3, "clicked") do widget | ||
add_css_class(widget, "button4") # change color on click | ||
widget.label = "Go Blue" # change label on click | ||
end | ||
|
||
box = GtkBox(:v) | ||
win[] = box | ||
push!(box, b1) | ||
push!(box, b2) | ||
push!(box, b3) |