forked from aparoksha/adwaita-swift
Add support for custom CSS
This commit is contained in:
parent
f53c194045
commit
239f025508
@ -64,4 +64,23 @@ extension View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Add CSS classes to the app as soon as the view appears.
|
||||||
|
/// - Parameter getString: Get the CSS.
|
||||||
|
/// - Returns: A view.
|
||||||
|
public func css(_ getString: @escaping () -> String) -> View {
|
||||||
|
inspectOnAppear { _ in
|
||||||
|
let provider = gtk_css_provider_new()
|
||||||
|
gtk_css_provider_load_from_string(
|
||||||
|
provider,
|
||||||
|
getString()
|
||||||
|
)
|
||||||
|
let display = gdk_display_get_default()
|
||||||
|
gtk_style_context_add_provider_for_display(
|
||||||
|
display,
|
||||||
|
provider?.opaque(),
|
||||||
|
.init(GTK_STYLE_PROVIDER_PRIORITY_APPLICATION)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,6 +28,14 @@ struct DiceDemo: View {
|
|||||||
}
|
}
|
||||||
.pill()
|
.pill()
|
||||||
.suggested()
|
.suggested()
|
||||||
|
.style("dice-button")
|
||||||
|
.css {
|
||||||
|
"""
|
||||||
|
.dice-button {
|
||||||
|
background-color: @green_5;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
}
|
||||||
.frame(maxWidth: 100)
|
.frame(maxWidth: 100)
|
||||||
}
|
}
|
||||||
.valign(.center)
|
.valign(.center)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user