Paste: Trying to add / remove buttons in grid

Author: Marcel
Mode: factor
Date: Thu, 2 Apr 2009 14:24:56
Plain Text |
! Copyright (C) 2009 Your name.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays kernel namespaces ui ui.gadgets.buttons
ui.gadgets.grids ui.tools.listener ;

IN: sokoban

SYMBOL: canvas

DEFER: button-42

: button-2 ( -- ) canvas get 1 0 grid-remove "2" [ drop [ button-42 ] call-listener ] <bevel-button> 1 0 grid-add drop ;
: button-42 ( -- ) canvas get 1 0 grid-remove "42" [ drop [ button-2 ] call-listener ] <bevel-button> 1 0 grid-add drop ;

: <sokoban-runner> ( -- gadget )
  ! Working one, but calling listener, focus on IDE:
  "1" [ ] <bevel-button> "2" [ drop [ button-42 ] call-listener ] <bevel-button> 2array
  ! Not working, does nothing:
  ! "1" [ ] <bevel-button> "2" [ drop [ button-42 ] call ] <bevel-button> 2array
  ! Throws "POSTPONE" Error message:
  ! "1" [ ] <bevel-button> "2" [ drop button-42 ] <bevel-button> 2array
  "3" [ ] <bevel-button> "4" [ ] <bevel-button> 2array
  2array <grid> ;

! run ui
: start-sokoban ( -- ) [ <sokoban-runner> dup canvas set "Sokoban" open-window ] with-ui ;

MAIN: start-sokoban

Annotation: Using locals, but not working

Author: Marcel
Mode: factor
Date: Thu, 2 Apr 2009 15:11:25
Plain Text |
! Copyright (C) 2009 Your name.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays kernel namespaces ui ui.gadgets.buttons
ui.gadgets.grids ui.tools.listener locals ;

IN: sokoban

:: button-2 ( canvas -- ) canvas 1 0 grid-remove drop ;

:: <sokoban-runner> ( canvas -- gadget )
  "1" [ ] <bevel-button> "2" [ drop [ canvas button-2 ] call ] <bevel-button> 2array
  "3" [ ] <bevel-button> "4" [ ] <bevel-button> 2array
  2array canvas new-grid ;

! run ui
: start-sokoban ( -- ) [ grid <sokoban-runner> "Sokoban" open-window ] with-ui ;

MAIN: start-sokoban

New Annotation

Summary:
Author:
Mode:
Body: