Skip to content

Instantly share code, notes, and snippets.

@dockimbel
Last active July 8, 2017 15:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dockimbel/a6ad059854e8059147d23e5033b490d6 to your computer and use it in GitHub Desktop.
Save dockimbel/a6ad059854e8059147d23e5033b490d6 to your computer and use it in GitHub Desktop.
Dynamic View usage example: drawing a board of buttons
Red [
Title: "Dynamic View usage example"
Author: "Nenad Rakocevic"
Date: 08/07/2017
]
generate: function [board [pair!] sz [pair!] return: [block!]][
pane: make block! sz/x * sz/y
pos: 1x1
count: 1
loop board/y [
loop board/x [
append pane make face! [type: 'button size: sz offset: pos text: form count]
pos/x: pos/x + sz/x
count: count + 1
]
pos: as-pair 0 pos/y + sz/y
]
pane
]
board: 4x5 ;-- board's columns x rows
but-sz: 50x50 ;-- size of each piece
view center-face make face! [
type: 'window
size: as-pair board/x * but-sz/x board/y * but-sz/y
pane: generate board but-sz
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment