diff options
author | Camil Staps | 2019-10-28 09:24:11 +0100 |
---|---|---|
committer | Camil Staps | 2019-10-28 09:24:11 +0100 |
commit | 1af27a3bb964caad3a1fd5ec80e94e681ae57e10 (patch) | |
tree | 32a6c8f597001c919bda8cd6895511b7f3c48d0d /src/Gtk/Widgets.icl | |
parent | Add many functions for action bars, buttons, list stores, tree views, and more (diff) |
Add GtkLabel, GtkGrid, and alignment tuning for GtkWidget
Diffstat (limited to 'src/Gtk/Widgets.icl')
-rw-r--r-- | src/Gtk/Widgets.icl | 56 |
1 files changed, 46 insertions, 10 deletions
diff --git a/src/Gtk/Widgets.icl b/src/Gtk/Widgets.icl index 4bf537b..c63eabf 100644 --- a/src/Gtk/Widgets.icl +++ b/src/Gtk/Widgets.icl @@ -148,19 +148,44 @@ where toPtr f = f fromPtr f = f -newFrame :: !GtkLabel !w -> GtkM GtkFrame | gtkWidget w -newFrame label widget = - toStateR (gtk_frame_new (case label of Label l -> Just l; _ -> Nothing)) >>= \frame -> - (case label of - Label _ -> toState (gtk_frame_set_label_align frame 0.02 0.5) - NoLabel -> pure ()) >>| +newFrame :: !GtkTitle !w -> GtkM GtkFrame | gtkWidget w +newFrame (Title title) widget = + toStateR (gtk_frame_new (case title of "" -> Nothing; _ -> Just title)) >>= \frame -> + (case title of + "" -> pure () + _ -> toState (gtk_frame_set_label_align frame 0.02 0.5)) >>| addToContainer frame widget >>| show frame -framed :: !GtkLabel !(GtkM w) -> GtkM (w, GtkFrame) | gtkWidget w -framed label widgetf = +framed :: !GtkTitle !(GtkM w) -> GtkM (w, GtkFrame) | gtkWidget w +framed title widgetf = widgetf >>= \widget -> - tuple widget <$> newFrame label widget + tuple widget <$> newFrame title widget + +:: GtkGrid :== Pointer + +instance gtkWidget GtkGrid where gtkWidget g = g + +newGrid :: GtkM GtkGrid +newGrid = toStateR gtk_grid_new >>= show + +attachGrid :: !GtkGrid !(!Int,!Int) !(!Int,!Int) !w -> GtkM w | gtkWidget w +attachGrid grid (left,top) (width,height) widget = + toState (gtk_grid_attach grid (gtkWidget widget) left top width height) >>| + pure widget + +:: GtkLabel :== Pointer + +instance gtkWidget GtkLabel where gtkWidget l = l + +newLabel :: GtkM GtkLabel +newLabel = toStateR gtk_label_new >>= show + +instance tune GtkLabel GtkText +where + tune (Text text) label = + toState (gtk_label_set_markup label text) >>| + pure label :: GtkListStore :== Pointer @@ -392,7 +417,10 @@ where instance gtkWidget GtkTreeView where gtkWidget tv = tv newTreeView :: !GtkListStore -> GtkM GtkTreeView -newTreeView store = toStateR (gtk_tree_view_new_with_model store) >>= show +newTreeView store = + toStateR (gtk_tree_view_new_with_model store) >>= \view -> + toState (g_object_unref store) >>| + show view appendColumnToTreeView :: !String !Int !GtkExpand !GtkTreeView -> GtkM GtkTreeView appendColumnToTreeView title col expand tree_view = @@ -478,6 +506,14 @@ where toState (gtk_widget_set_sensitive (gtkWidget widget) sens=:Sensitive) >>| pure widget +instance tune w (GtkAlign,GtkAlign) | gtkWidget w +where + tune (halign,valign) widget = + let ptr = gtkWidget widget in + toState (gtk_widget_set_halign ptr (toInt halign)) >>| + toState (gtk_widget_set_valign ptr (toInt valign)) >>| + pure widget + :: GtkWindow :== Pointer instance gtkWidget GtkWindow where gtkWidget w = w |