add the Dijkstra's algorithm

add the Dijkstra's algorithm

{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE DataKinds #-}
module IGraph.Algorithms.Structure
    ( -- * Shortest Path Related Functions
      shortestPath
    , inducedSubgraph
    , isConnected
    , isStronglyConnected
    , decompose
    , isDag
    , topSort
    , topSortUnsafe
    ) where

import           Control.Monad
import           Data.Serialize            (Serialize)
import Data.List (foldl')
import           System.IO.Unsafe          (unsafePerformIO)
import Data.Maybe
import Data.Singletons (SingI)

import Foreign
import Foreign.C.Types

import           IGraph
import IGraph.Internal.C2HS
{#import IGraph.Internal #}
{#import IGraph.Internal.Constants #}

#include "haskell_igraph.h"

{#fun igraph_shortest_paths as ^
    { `IGraph'
    , castPtr `Ptr Matrix'
    , castPtr %`Ptr VertexSelector'
    , castPtr %`Ptr VertexSelector'
    , `Neimode'
    } -> `CInt' void- #}

-- Calculates and returns a single unweighted shortest path from a given vertex
-- to another one. If there are more than one shortest paths between the two
-- vertices, then an arbitrary one is returned.
shortestPath :: Serialize e
             => Graph d v e
             -> Node     -- ^ The id of the source vertex.
             -> Node     -- ^ The id of the target vertex.
             -> Maybe (e -> Double)  -- ^ A function to retrieve edge weights. If provied,
                                     -- the Dijkstra's algorithm will be used.
             -> [Node]
shortestPath gr s t getEdgeW = unsafePerformIO $ allocaVector $ \path -> do
    case getEdgeW of
        Nothing -> igraphGetShortestPath (_graph gr) path nullPtr s t IgraphOut
        Just f -> withList (map (f . snd) $ labEdges gr) $ \ws ->
            igraphGetShortestPathDijkstra (_graph gr) path nullPtr s t ws IgraphOut
    map truncate <$> toList path
{#fun igraph_get_shortest_path as ^
    { `IGraph'
    , castPtr `Ptr Vector'
    , castPtr `Ptr Vector'
    , `Int'
    , `Int'
    , `Neimode'
    } -> `CInt' void- #}
{#fun igraph_get_shortest_path_dijkstra as ^
    { `IGraph'
    , castPtr `Ptr Vector'
    , castPtr `Ptr Vector'
    , `Int'
    , `Int'
    , castPtr `Ptr Vector'
    , `Neimode'
    } -> `CInt' void- #}

inducedSubgraph :: (Ord v, Serialize v)
                => Graph d v e
                -> [Int]
                -> Graph d v e
inducedSubgraph gr nds = unsafePerformIO $ withVerticesList nds $ \vs ->
    igraphInducedSubgraph (_graph gr) vs IgraphSubgraphCreateFromScratch >>=
        (\g -> return $ Graph g $ mkLabelToId g)
{#fun igraph_induced_subgraph as ^
    { `IGraph'
    , allocaIGraph- `IGraph' addIGraphFinalizer*
    , castPtr %`Ptr VertexSelector'
    , `SubgraphImplementation'
    } -> `CInt' void- #}

-- | Decides whether the graph is weakly connected.
isConnected :: Graph d v e -> Bool
isConnected gr = igraphIsConnected (_graph gr) IgraphWeak

isStronglyConnected :: Graph 'D v e -> Bool
isStronglyConnected gr = igraphIsConnected (_graph gr) IgraphStrong

{#fun pure igraph_is_connected as ^
    { `IGraph'
    , alloca- `Bool' peekBool*
    , `Connectedness'
    } -> `CInt' void- #}

-- | Decompose a graph into connected components.
decompose :: (Ord v, Serialize v)
          => Graph d v e -> [Graph d v e]
decompose gr = unsafePerformIO $ allocaVectorPtr $ \ptr -> do
    igraphDecompose (_graph gr) ptr IgraphWeak (-1) 1
    n <- igraphVectorPtrSize ptr
    forM [0..n-1] $ \i -> do
        p <- igraphVectorPtrE ptr i
        addIGraphFinalizer (castPtr p) >>= (\g -> return $ Graph g $ mkLabelToId g)
{-# INLINE decompose #-}
{#fun igraph_decompose as ^
    { `IGraph'
    , castPtr `Ptr VectorPtr'
    , `Connectedness'
    , `Int'
    , `Int'
    } -> `CInt' void- #}

-- | Checks whether a graph is a directed acyclic graph (DAG) or not.
isDag :: Graph d v e -> Bool
isDag = igraphIsDag . _graph
{#fun pure igraph_is_dag as ^
    { `IGraph'
    , alloca- `Bool' peekBool*
    } -> `CInt' void- #}

-- | Calculate a possible topological sorting of the graph.
topSort :: Graph d v e -> [Node]
topSort gr | isDag gr = topSortUnsafe gr
           | otherwise = error "the graph is not acyclic"

-- | Calculate a possible topological sorting of the graph. If the graph is not
-- acyclic (it has at least one cycle), a partial topological sort is returned.
topSortUnsafe :: Graph d v e -> [Node]
topSortUnsafe gr = unsafePerformIO $ allocaVectorN n $ \res -> do
    igraphTopologicalSorting (_graph gr) res IgraphOut
    map truncate <$> toList res
  where
    n = nNodes gr
{#fun igraph_topological_sorting as ^
    { `IGraph'
    , castPtr `Ptr Vector'
    , `Neimode'
    } -> `CInt' void- #}

{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE DataKinds #-}
module IGraph.Algorithms.Structure
    ( -- * Shortest Path Related Functions
      getShortestPath
    , inducedSubgraph
    , isConnected
    , isStronglyConnected
    , decompose
    , isDag
    , topSort
    , topSortUnsafe
    ) where

import           Control.Monad
import           Data.Serialize            (Serialize)
import Data.List (foldl')
import           System.IO.Unsafe          (unsafePerformIO)
import Data.Maybe
import Data.Singletons (SingI)

import Foreign
import Foreign.C.Types

import           IGraph
import IGraph.Internal.C2HS
{#import IGraph.Internal #}
{#import IGraph.Internal.Constants #}

#include "haskell_igraph.h"

{#fun igraph_shortest_paths as ^
    { `IGraph'
    , castPtr `Ptr Matrix'
    , castPtr %`Ptr VertexSelector'
    , castPtr %`Ptr VertexSelector'
    , `Neimode'
    } -> `CInt' void- #}

-- Calculates and returns a single unweighted shortest path from a given vertex
-- to another one. If there are more than one shortest paths between the two
-- vertices, then an arbitrary one is returned.
getShortestPath :: Graph d v e
                -> Node     -- ^ The id of the source vertex.
                -> Node     -- ^ The id of the target vertex.
                -> [Node]
getShortestPath gr s t = unsafePerformIO $ allocaVector $ \path -> do
    igraphGetShortestPath (_graph gr) path nullPtr s t IgraphOut
    map truncate <$> toList path
{#fun igraph_get_shortest_path as ^
    { `IGraph'
    , castPtr `Ptr Vector'
    , castPtr `Ptr Vector'
    , `Int'
    , `Int'
    , `Neimode'
    } -> `CInt' void- #}

inducedSubgraph :: (Ord v, Serialize v)
                => Graph d v e
                -> [Int]
                -> Graph d v e
inducedSubgraph gr nds = unsafePerformIO $ withVerticesList nds $ \vs ->
    igraphInducedSubgraph (_graph gr) vs IgraphSubgraphCreateFromScratch >>=
        (\g -> return $ Graph g $ mkLabelToId g)
{#fun igraph_induced_subgraph as ^
    { `IGraph'
    , allocaIGraph- `IGraph' addIGraphFinalizer*
    , castPtr %`Ptr VertexSelector'
    , `SubgraphImplementation'
    } -> `CInt' void- #}

-- | Decides whether the graph is weakly connected.
isConnected :: Graph d v e -> Bool
isConnected gr = igraphIsConnected (_graph gr) IgraphWeak

isStronglyConnected :: Graph 'D v e -> Bool
isStronglyConnected gr = igraphIsConnected (_graph gr) IgraphStrong

{#fun pure igraph_is_connected as ^
    { `IGraph'
    , alloca- `Bool' peekBool*
    , `Connectedness'
    } -> `CInt' void- #}

-- | Decompose a graph into connected components.
decompose :: (Ord v, Serialize v)
          => Graph d v e -> [Graph d v e]
decompose gr = unsafePerformIO $ allocaVectorPtr $ \ptr -> do
    igraphDecompose (_graph gr) ptr IgraphWeak (-1) 1
    n <- igraphVectorPtrSize ptr
    forM [0..n-1] $ \i -> do
        p <- igraphVectorPtrE ptr i
        addIGraphFinalizer (castPtr p) >>= (\g -> return $ Graph g $ mkLabelToId g)
{-# INLINE decompose #-}
{#fun igraph_decompose as ^
    { `IGraph'
    , castPtr `Ptr VectorPtr'
    , `Connectedness'
    , `Int'
    , `Int'
    } -> `CInt' void- #}

-- | Checks whether a graph is a directed acyclic graph (DAG) or not.
isDag :: Graph d v e -> Bool
isDag = igraphIsDag . _graph
{#fun pure igraph_is_dag as ^
    { `IGraph'
    , alloca- `Bool' peekBool*
    } -> `CInt' void- #}

-- | Calculate a possible topological sorting of the graph.
topSort :: Graph d v e -> [Node]
topSort gr | isDag gr = topSortUnsafe gr
           | otherwise = error "the graph is not acyclic"

-- | Calculate a possible topological sorting of the graph. If the graph is not
-- acyclic (it has at least one cycle), a partial topological sort is returned.
topSortUnsafe :: Graph d v e -> [Node]
topSortUnsafe gr = unsafePerformIO $ allocaVectorN n $ \res -> do
    igraphTopologicalSorting (_graph gr) res IgraphOut
    map truncate <$> toList res
  where
    n = nNodes gr
{#fun igraph_topological_sorting as ^
    { `IGraph'
    , castPtr `Ptr Vector'
    , `Neimode'
    } -> `CInt' void- #}


Remove unnecessary OverlappingInstances pragma.

{-# LANGUAGE CPP, ExistentialQuantification, TypeSynonymInstances, FlexibleInstances, MultiParamTypeClasses, FlexibleContexts, ScopedTypeVariables #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Graphics.UI.FLTK.LowLevel.Spinner
    (
     -- * Constructor
     spinnerNew,
     SpinnerType(..)
     -- * Hierarchy
     --
     -- $hierarchy

     -- * Functions
     --
     -- $Spinnerfunctions
     --
    )
where
#include "Fl_ExportMacros.h"
#include "Fl_Types.h"
#include "Fl_SpinnerC.h"
#include "Fl_WidgetC.h"
import C2HS hiding (cFromEnum, cFromBool, cToBool,cToEnum)
import Foreign.C.Types
import Graphics.UI.FLTK.LowLevel.Fl_Enumerations
import Graphics.UI.FLTK.LowLevel.Fl_Types
import Graphics.UI.FLTK.LowLevel.Utils
import Graphics.UI.FLTK.LowLevel.Hierarchy
import Graphics.UI.FLTK.LowLevel.Dispatch
#c
enum SpinnerType {
  IntSpinnerType = FL_INT_INPUTC,
  FloatSpinnerType = FL_FLOAT_INPUTC
};
#endc
{#enum SpinnerType {} deriving (Show, Eq) #}
{# fun Fl_Spinner_New as spinnerNew' { `Int',`Int',`Int',`Int' } -> `Ptr ()' id #}
{# fun Fl_Spinner_New_WithLabel as spinnerNewWithLabel' { `Int',`Int',`Int',`Int', unsafeToCString `String'} -> `Ptr ()' id #}
spinnerNew :: Rectangle -> Maybe String -> IO (Ref Spinner)
spinnerNew rectangle l'=
    let (x_pos, y_pos, width, height) = fromRectangle rectangle
    in case l' of
        Nothing -> spinnerNew' x_pos y_pos width height >>=
                             toRef
        Just l -> spinnerNewWithLabel' x_pos y_pos width height l >>=
                               toRef

{#fun Fl_Spinner_handle as spinnerHandle' { id `Ptr ()', id `CInt' } -> `Int' #}
instance (impl ~ (Event -> IO Int)) => Op (Handle ()) Spinner orig impl where
  runOp _ _ spinner event = withRef spinner (\p -> spinnerHandle' p (fromIntegral . fromEnum $ event))
{# fun Fl_Spinner_set_textfont as setTextfont' { id `Ptr ()',cFromFont `Font' } -> `()' #}
instance (impl ~ (Font ->  IO ())) => Op (SetTextfont ()) Spinner orig impl where
  runOp _ _ spinner text = withRef spinner $ \spinnerPtr -> setTextfont' spinnerPtr text
{# fun Fl_Spinner_textfont as textfont' { id `Ptr ()' } -> `Font' cToFont #}
instance (impl ~ ( IO (Font))) => Op (GetTextfont ()) Spinner orig impl where
  runOp _ _ spinner = withRef spinner $ \spinnerPtr -> textfont' spinnerPtr
{# fun Fl_Spinner_set_textsize as setTextsize' { id `Ptr ()', id `CInt' } -> `()' #}
instance (impl ~ (FontSize ->  IO ())) => Op (SetTextsize ()) Spinner orig impl where
  runOp _ _ spinner (FontSize text) = withRef spinner $ \spinnerPtr -> setTextsize' spinnerPtr text
{# fun Fl_Spinner_textsize as textsize' { id `Ptr ()' } -> `CInt' id #}
instance (impl ~ ( IO (FontSize))) => Op (GetTextsize ()) Spinner orig impl where
  runOp _ _ spinner = withRef spinner $ \spinnerPtr -> textsize' spinnerPtr >>= return . FontSize
{# fun Fl_Spinner_set_textcolor as setTextcolor' { id `Ptr ()',cFromColor `Color' } -> `()' #}
instance (impl ~ (Color ->  IO ())) => Op (SetTextcolor ()) Spinner orig impl where
  runOp _ _ spinner text = withRef spinner $ \spinnerPtr -> setTextcolor' spinnerPtr text
{# fun Fl_Spinner_textcolor as textcolor' { id `Ptr ()' } -> `Color' cToColor #}
instance (impl ~ ( IO (Color))) => Op (GetTextcolor ()) Spinner orig impl where
  runOp _ _ spinner = withRef spinner $ \spinnerPtr -> textcolor' spinnerPtr
{# fun Fl_Spinner_set_type as setType' { id `Ptr ()',`Word8' } -> `()' supressWarningAboutRes #}
instance (impl ~ (SpinnerType ->  IO ())) => Op (SetType ()) Spinner orig impl where
  runOp _ _ widget t = withRef widget $ \widgetPtr -> setType' widgetPtr (fromInteger $ toInteger $ fromEnum t)
{# fun Fl_Spinner_type as type' { id `Ptr ()' } -> `Word8' #}
instance (impl ~ IO (SpinnerType)) => Op (GetType_ ()) Spinner orig impl where
  runOp _ _ widget = withRef widget $ \widgetPtr -> type' widgetPtr >>= return . toEnum . fromInteger . toInteger
{# fun Fl_Spinner_set_format as set_format' { id `Ptr ()', `String' } -> `()' supressWarningAboutRes #}
instance (impl ~ (String ->  IO ())) => Op (SetFormat ()) Spinner orig impl where
  runOp _ _ spinner f = withRef spinner $ \spinnerPtr -> set_format' spinnerPtr f
{# fun Fl_Spinner_format as format' { id `Ptr ()' } -> `String' unsafeFromCString #}
instance (impl ~ ( IO (Maybe String))) => Op (GetFormat ()) Spinner orig impl where
   runOp _ _ spinner = withRef spinner $ \spinnerPtr -> format' spinnerPtr >>= \s ->
     if (null s) then return Nothing else return (Just s)
{# fun Fl_Spinner_value as value' { id `Ptr ()' } -> `Double' #}
instance (impl ~ ( IO (Double))) => Op (GetValue ()) Spinner orig impl where
  runOp _ _ spinner = withRef spinner $ \spinnerPtr -> value' spinnerPtr
{# fun Fl_Spinner_set_value as setValue' { id `Ptr ()',`Double' } -> `()' supressWarningAboutRes #}
instance (impl ~ (Double ->  IO ())) => Op (SetValue ()) Spinner orig impl where
  runOp _ _ spinner v = withRef spinner $ \spinnerPtr -> setValue' spinnerPtr v
{# fun Fl_Spinner_set_step as setStep' { id `Ptr ()', `Double'} -> `()' supressWarningAboutRes #}
instance (impl ~ (Double -> IO ())) => Op (SetStep ()) Spinner orig impl where
  runOp _ _ spinner r = withRef spinner $ \spinnerPtr -> setStep' spinnerPtr r
{# fun Fl_Spinner_step as step' { id `Ptr ()' } -> `Double' #}
instance (impl ~ ( IO (Double))) => Op (GetStep ()) Spinner orig impl where
  runOp _ _ spinner = withRef spinner $ \spinnerPtr -> step' spinnerPtr
{# fun Fl_Spinner_maximum as maximum' { id `Ptr ()' } -> `Double' #}
instance (impl ~ ( IO (Double))) => Op (GetMaximum ()) Spinner orig impl where
  runOp _ _ valuator = withRef valuator $ \valuatorPtr -> maximum' valuatorPtr
{# fun Fl_Spinner_set_maximum as setMaximum' { id `Ptr ()',`Double' } -> `()' supressWarningAboutRes #}
instance (impl ~ (Double ->  IO ())) => Op (SetMaximum ()) Spinner orig impl where
  runOp _ _ valuator a = withRef valuator $ \valuatorPtr -> setMaximum' valuatorPtr a
{# fun Fl_Spinner_minimum as minimum' { id `Ptr ()' } -> `Double' #}
instance (impl ~ ( IO (Double))) => Op (GetMinimum ()) Spinner orig impl where
  runOp _ _ valuator = withRef valuator $ \valuatorPtr -> minimum' valuatorPtr
{# fun Fl_Spinner_set_minimum as setMinimum' { id `Ptr ()',`Double' } -> `()' supressWarningAboutRes #}
instance (impl ~ (Double ->  IO ())) => Op (SetMinimum ()) Spinner orig impl where
  runOp _ _ valuator a = withRef valuator $ \valuatorPtr -> setMinimum' valuatorPtr a
{# fun Fl_Spinner_range as range' { id `Ptr ()',`Double',`Double' } -> `()' supressWarningAboutRes #}
instance (impl ~ (Double -> Double ->  IO ())) => Op (Range ()) Spinner orig impl where
  runOp _ _ valuator a b = withRef valuator $ \valuatorPtr -> range' valuatorPtr a b

-- $hierarchy
-- @
--
-- "Graphics.UI.FLTK.LowLevel.Widget"
--  |
--  v
-- "Graphics.UI.FLTK.LowLevel.Group"
--  |
--  v
-- "Graphics.UI.FLTK.LowLevel.Spinner"
--
-- @

-- $functions
-- @
-- getFormat :: 'Ref' 'Spinner' -> 'IO' ('Maybe' 'String')
--
-- getMaximum :: 'Ref' 'Spinner' -> 'IO' ('Double')
--
-- getMinimum :: 'Ref' 'Spinner' -> 'IO' ('Double')
--
-- getStep :: 'Ref' 'Spinner' -> 'IO' ('Double')
--
-- getTextcolor :: 'Ref' 'Spinner' -> 'IO' ('Color')
--
-- getTextfont :: 'Ref' 'Spinner' -> 'IO' ('Font')
--
-- getTextsize :: 'Ref' 'Spinner' -> 'IO' ('FontSize')
--
-- getType_ :: 'Ref' 'Spinner' -> 'IO' ('SpinnerType')
--
-- getValue :: 'Ref' 'Spinner' -> 'IO' ('Double')
--
-- handle :: 'Ref' 'Spinner' -> 'Event' -> 'IO' 'Int'
--
-- range :: 'Ref' 'Spinner' -> 'Double' -> 'Double' -> 'IO' ()
--
-- setFormat :: 'Ref' 'Spinner' -> 'String' -> 'IO' ()
--
-- setMaximum :: 'Ref' 'Spinner' -> 'Double' -> 'IO' ()
--
-- setMinimum :: 'Ref' 'Spinner' -> 'Double' -> 'IO' ()
--
-- setStep :: 'Ref' 'Spinner' -> 'Double' -> 'IO' ()
--
-- setTextcolor :: 'Ref' 'Spinner' -> 'Color' -> 'IO' ()
--
-- setTextfont :: 'Ref' 'Spinner' -> 'Font' -> 'IO' ()
--
-- setTextsize :: 'Ref' 'Spinner' -> 'FontSize' -> 'IO' ()
--
-- setType :: 'Ref' 'Spinner' -> 'SpinnerType' -> 'IO' ()
--
-- setValue :: 'Ref' 'Spinner' -> 'Double' -> 'IO' ()
--
-- @

{-# LANGUAGE CPP, ExistentialQuantification, TypeSynonymInstances, FlexibleInstances, MultiParamTypeClasses, FlexibleContexts, ScopedTypeVariables, OverlappingInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Graphics.UI.FLTK.LowLevel.Spinner
    (
     -- * Constructor
     spinnerNew,
     SpinnerType(..)
     -- * Hierarchy
     --
     -- $hierarchy

     -- * Functions
     --
     -- $Spinnerfunctions
     --
    )
where
#include "Fl_ExportMacros.h"
#include "Fl_Types.h"
#include "Fl_SpinnerC.h"
#include "Fl_WidgetC.h"
import C2HS hiding (cFromEnum, cFromBool, cToBool,cToEnum)
import Foreign.C.Types
import Graphics.UI.FLTK.LowLevel.Fl_Enumerations
import Graphics.UI.FLTK.LowLevel.Fl_Types
import Graphics.UI.FLTK.LowLevel.Utils
import Graphics.UI.FLTK.LowLevel.Hierarchy
import Graphics.UI.FLTK.LowLevel.Dispatch
#c
enum SpinnerType {
  IntSpinnerType = FL_INT_INPUTC,
  FloatSpinnerType = FL_FLOAT_INPUTC
};
#endc
{#enum SpinnerType {} deriving (Show, Eq) #}
{# fun Fl_Spinner_New as spinnerNew' { `Int',`Int',`Int',`Int' } -> `Ptr ()' id #}
{# fun Fl_Spinner_New_WithLabel as spinnerNewWithLabel' { `Int',`Int',`Int',`Int', unsafeToCString `String'} -> `Ptr ()' id #}
spinnerNew :: Rectangle -> Maybe String -> IO (Ref Spinner)
spinnerNew rectangle l'=
    let (x_pos, y_pos, width, height) = fromRectangle rectangle
    in case l' of
        Nothing -> spinnerNew' x_pos y_pos width height >>=
                             toRef
        Just l -> spinnerNewWithLabel' x_pos y_pos width height l >>=
                               toRef

{#fun Fl_Spinner_handle as spinnerHandle' { id `Ptr ()', id `CInt' } -> `Int' #}
instance (impl ~ (Event -> IO Int)) => Op (Handle ()) Spinner orig impl where
  runOp _ _ spinner event = withRef spinner (\p -> spinnerHandle' p (fromIntegral . fromEnum $ event))
{# fun Fl_Spinner_set_textfont as setTextfont' { id `Ptr ()',cFromFont `Font' } -> `()' #}
instance (impl ~ (Font ->  IO ())) => Op (SetTextfont ()) Spinner orig impl where
  runOp _ _ spinner text = withRef spinner $ \spinnerPtr -> setTextfont' spinnerPtr text
{# fun Fl_Spinner_textfont as textfont' { id `Ptr ()' } -> `Font' cToFont #}
instance (impl ~ ( IO (Font))) => Op (GetTextfont ()) Spinner orig impl where
  runOp _ _ spinner = withRef spinner $ \spinnerPtr -> textfont' spinnerPtr
{# fun Fl_Spinner_set_textsize as setTextsize' { id `Ptr ()', id `CInt' } -> `()' #}
instance (impl ~ (FontSize ->  IO ())) => Op (SetTextsize ()) Spinner orig impl where
  runOp _ _ spinner (FontSize text) = withRef spinner $ \spinnerPtr -> setTextsize' spinnerPtr text
{# fun Fl_Spinner_textsize as textsize' { id `Ptr ()' } -> `CInt' id #}
instance (impl ~ ( IO (FontSize))) => Op (GetTextsize ()) Spinner orig impl where
  runOp _ _ spinner = withRef spinner $ \spinnerPtr -> textsize' spinnerPtr >>= return . FontSize
{# fun Fl_Spinner_set_textcolor as setTextcolor' { id `Ptr ()',cFromColor `Color' } -> `()' #}
instance (impl ~ (Color ->  IO ())) => Op (SetTextcolor ()) Spinner orig impl where
  runOp _ _ spinner text = withRef spinner $ \spinnerPtr -> setTextcolor' spinnerPtr text
{# fun Fl_Spinner_textcolor as textcolor' { id `Ptr ()' } -> `Color' cToColor #}
instance (impl ~ ( IO (Color))) => Op (GetTextcolor ()) Spinner orig impl where
  runOp _ _ spinner = withRef spinner $ \spinnerPtr -> textcolor' spinnerPtr
{# fun Fl_Spinner_set_type as setType' { id `Ptr ()',`Word8' } -> `()' supressWarningAboutRes #}
instance (impl ~ (SpinnerType ->  IO ())) => Op (SetType ()) Spinner orig impl where
  runOp _ _ widget t = withRef widget $ \widgetPtr -> setType' widgetPtr (fromInteger $ toInteger $ fromEnum t)
{# fun Fl_Spinner_type as type' { id `Ptr ()' } -> `Word8' #}
instance (impl ~ IO (SpinnerType)) => Op (GetType_ ()) Spinner orig impl where
  runOp _ _ widget = withRef widget $ \widgetPtr -> type' widgetPtr >>= return . toEnum . fromInteger . toInteger
{# fun Fl_Spinner_set_format as set_format' { id `Ptr ()', `String' } -> `()' supressWarningAboutRes #}
instance (impl ~ (String ->  IO ())) => Op (SetFormat ()) Spinner orig impl where
  runOp _ _ spinner f = withRef spinner $ \spinnerPtr -> set_format' spinnerPtr f
{# fun Fl_Spinner_format as format' { id `Ptr ()' } -> `String' unsafeFromCString #}
instance (impl ~ ( IO (Maybe String))) => Op (GetFormat ()) Spinner orig impl where
   runOp _ _ spinner = withRef spinner $ \spinnerPtr -> format' spinnerPtr >>= \s ->
     if (null s) then return Nothing else return (Just s)
{# fun Fl_Spinner_value as value' { id `Ptr ()' } -> `Double' #}
instance (impl ~ ( IO (Double))) => Op (GetValue ()) Spinner orig impl where
  runOp _ _ spinner = withRef spinner $ \spinnerPtr -> value' spinnerPtr
{# fun Fl_Spinner_set_value as setValue' { id `Ptr ()',`Double' } -> `()' supressWarningAboutRes #}
instance (impl ~ (Double ->  IO ())) => Op (SetValue ()) Spinner orig impl where
  runOp _ _ spinner v = withRef spinner $ \spinnerPtr -> setValue' spinnerPtr v
{# fun Fl_Spinner_set_step as setStep' { id `Ptr ()', `Double'} -> `()' supressWarningAboutRes #}
instance (impl ~ (Double -> IO ())) => Op (SetStep ()) Spinner orig impl where
  runOp _ _ spinner r = withRef spinner $ \spinnerPtr -> setStep' spinnerPtr r
{# fun Fl_Spinner_step as step' { id `Ptr ()' } -> `Double' #}
instance (impl ~ ( IO (Double))) => Op (GetStep ()) Spinner orig impl where
  runOp _ _ spinner = withRef spinner $ \spinnerPtr -> step' spinnerPtr
{# fun Fl_Spinner_maximum as maximum' { id `Ptr ()' } -> `Double' #}
instance (impl ~ ( IO (Double))) => Op (GetMaximum ()) Spinner orig impl where
  runOp _ _ valuator = withRef valuator $ \valuatorPtr -> maximum' valuatorPtr
{# fun Fl_Spinner_set_maximum as setMaximum' { id `Ptr ()',`Double' } -> `()' supressWarningAboutRes #}
instance (impl ~ (Double ->  IO ())) => Op (SetMaximum ()) Spinner orig impl where
  runOp _ _ valuator a = withRef valuator $ \valuatorPtr -> setMaximum' valuatorPtr a
{# fun Fl_Spinner_minimum as minimum' { id `Ptr ()' } -> `Double' #}
instance (impl ~ ( IO (Double))) => Op (GetMinimum ()) Spinner orig impl where
  runOp _ _ valuator = withRef valuator $ \valuatorPtr -> minimum' valuatorPtr
{# fun Fl_Spinner_set_minimum as setMinimum' { id `Ptr ()',`Double' } -> `()' supressWarningAboutRes #}
instance (impl ~ (Double ->  IO ())) => Op (SetMinimum ()) Spinner orig impl where
  runOp _ _ valuator a = withRef valuator $ \valuatorPtr -> setMinimum' valuatorPtr a
{# fun Fl_Spinner_range as range' { id `Ptr ()',`Double',`Double' } -> `()' supressWarningAboutRes #}
instance (impl ~ (Double -> Double ->  IO ())) => Op (Range ()) Spinner orig impl where
  runOp _ _ valuator a b = withRef valuator $ \valuatorPtr -> range' valuatorPtr a b

-- $hierarchy
-- @
--
-- "Graphics.UI.FLTK.LowLevel.Widget"
--  |
--  v
-- "Graphics.UI.FLTK.LowLevel.Group"
--  |
--  v
-- "Graphics.UI.FLTK.LowLevel.Spinner"
--
-- @

-- $functions
-- @
-- getFormat :: 'Ref' 'Spinner' -> 'IO' ('Maybe' 'String')
--
-- getMaximum :: 'Ref' 'Spinner' -> 'IO' ('Double')
--
-- getMinimum :: 'Ref' 'Spinner' -> 'IO' ('Double')
--
-- getStep :: 'Ref' 'Spinner' -> 'IO' ('Double')
--
-- getTextcolor :: 'Ref' 'Spinner' -> 'IO' ('Color')
--
-- getTextfont :: 'Ref' 'Spinner' -> 'IO' ('Font')
--
-- getTextsize :: 'Ref' 'Spinner' -> 'IO' ('FontSize')
--
-- getType_ :: 'Ref' 'Spinner' -> 'IO' ('SpinnerType')
--
-- getValue :: 'Ref' 'Spinner' -> 'IO' ('Double')
--
-- handle :: 'Ref' 'Spinner' -> 'Event' -> 'IO' 'Int'
--
-- range :: 'Ref' 'Spinner' -> 'Double' -> 'Double' -> 'IO' ()
--
-- setFormat :: 'Ref' 'Spinner' -> 'String' -> 'IO' ()
--
-- setMaximum :: 'Ref' 'Spinner' -> 'Double' -> 'IO' ()
--
-- setMinimum :: 'Ref' 'Spinner' -> 'Double' -> 'IO' ()
--
-- setStep :: 'Ref' 'Spinner' -> 'Double' -> 'IO' ()
--
-- setTextcolor :: 'Ref' 'Spinner' -> 'Color' -> 'IO' ()
--
-- setTextfont :: 'Ref' 'Spinner' -> 'Font' -> 'IO' ()
--
-- setTextsize :: 'Ref' 'Spinner' -> 'FontSize' -> 'IO' ()
--
-- setType :: 'Ref' 'Spinner' -> 'SpinnerType' -> 'IO' ()
--
-- setValue :: 'Ref' 'Spinner' -> 'Double' -> 'IO' ()
--
-- @