summaryrefslogtreecommitdiff
path: root/src/Gtk/Widgets.icl
diff options
context:
space:
mode:
authorCamil Staps2019-10-21 08:57:56 +0200
committerCamil Staps2019-10-21 08:57:56 +0200
commit5165b27ba2a1bb2129788a2e1de310ee6a347e4d (patch)
treeffc504b7844e47cced682bc38725bc74f7629673 /src/Gtk/Widgets.icl
parentAdd tune class for margins (diff)
Add CSS support
Diffstat (limited to 'src/Gtk/Widgets.icl')
-rw-r--r--src/Gtk/Widgets.icl28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/Gtk/Widgets.icl b/src/Gtk/Widgets.icl
index ba0ed6d..7fda320 100644
--- a/src/Gtk/Widgets.icl
+++ b/src/Gtk/Widgets.icl
@@ -8,6 +8,7 @@ import Control.Monad.Identity
import Control.Monad.State
import Data.Functor
import Data.Tuple
+import System.FilePath
import System._Pointer
import qualified Gtk.Internal as I
@@ -19,6 +20,16 @@ import Gtk.Types
instance gtkWidget GtkWidget where gtkWidget w = w
instance ptr GtkWidget where ptr w = w
+addCSSClass :: !GtkCSSClass !w -> GtkM () | gtkWidget w
+addCSSClass (Class cls) widget =
+ toStateR ('I'.gtk_widget_get_style_context (gtkWidget widget)) >>= \context ->
+ toState ('I'.gtk_style_context_add_class context cls)
+
+removeCSSClass :: !GtkCSSClass !w -> GtkM () | gtkWidget w
+removeCSSClass (Class cls) widget =
+ toStateR ('I'.gtk_widget_get_style_context (gtkWidget widget)) >>= \context ->
+ toState ('I'.gtk_style_context_remove_class context cls)
+
setMargins :: !GtkMargins !w -> GtkM () | gtkWidget w
setMargins {left,top,right,bottom} widget` =
let widget = gtkWidget widget` in
@@ -130,3 +141,20 @@ new_window_or_popup is_popup title size =
Nothing -> pure ()
Just (h,v) -> toState ('I'.gtk_widget_set_size_request window h v)) >>|
show window
+
+// NB: it is also possible to attach CSS to one widget in particular (excluding
+// children widgets). You then use gtk_widget_get_style_context and gtk_style_
+// context_add_provider instead of gtk_widget_get_screen and gtk_style_context_
+// add_provider_for_screen. This functionality has not been added to this
+// library yet, but there is no reason to not provide it. To be clear that this
+// style is global, we only allow it on GtkWindow, even though it would work on
+// any GtkWidget.
+addCSSFromFile :: !GtkStylePriority !FilePath !GtkWindow -> GtkM Bool
+addCSSFromFile priority path window =
+ toStateR 'I'.gtk_css_provider_new >>= \provider ->
+ toStateR ('I'.gtk_css_provider_load_from_path provider path 0) >>= \ok
+ | not ok -> pure ok
+ | otherwise ->
+ toStateR ('I'.gtk_widget_get_screen window) >>= \screen ->
+ toState ('I'.gtk_style_context_add_provider_for_screen screen provider (toInt priority)) >>|
+ pure True