examples/times_table: V 0.0.8 fixes
							parent
							
								
									a439faf605
								
							
						
					
					
						commit
						941c069256
					
				|  | @ -2,24 +2,23 @@ import ui | ||||||
| import gx | import gx | ||||||
| 
 | 
 | ||||||
| const ( | const ( | ||||||
| 	WIN_SIZE     = 540 | 	WinSize     = 540 | ||||||
| 	MIN          = 1 | 	Min         = 1 | ||||||
| 	MAX          = 9 | 	Max         = 9 | ||||||
| 	FONT_SIZE    = 30 | 	FontSize    = 30 | ||||||
| 	N            = MAX - MIN + 1 | 	N           = Max - Min + 1 | ||||||
| 	CELL_SIZE    = WIN_SIZE / N | 	CellSize    = WinSize / N | ||||||
| 	TEXT_CFG     = gx.TextCfg { color: gx.BLACK, size: FONT_SIZE } | 	TextCfg     = gx.TextCfg { color: gx.BLACK, size: FontSize } | ||||||
| 	HEADER_COLOR = gx.rgb(240, 240, 240) | 	HeaderColor = gx.rgb(240, 240, 240) | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| fn main() { | fn main() { | ||||||
| 	cfg := ui.WinCfg { | 	ui.new_window(ui.WinCfg { | ||||||
| 		width: WIN_SIZE | 		width: WinSize | ||||||
| 		height: WIN_SIZE | 		height: WinSize | ||||||
| 		title: 'Times Table' | 		title: 'Times Table' | ||||||
| 		draw_fn: draw | 		draw_fn: draw | ||||||
| 	} | 	}) | ||||||
| 	wnd := ui.new_window(cfg) |  | ||||||
| 	for { | 	for { | ||||||
| 		ui.wait_events() | 		ui.wait_events() | ||||||
| 	} | 	} | ||||||
|  | @ -27,29 +26,29 @@ fn main() { | ||||||
| 
 | 
 | ||||||
| // ui.Window uses native drawing API (Core Graphics, GDI+)
 | // ui.Window uses native drawing API (Core Graphics, GDI+)
 | ||||||
| fn draw() { | fn draw() { | ||||||
| 	gx.draw_rect(0, 0, WIN_SIZE, CELL_SIZE, HEADER_COLOR) // Horizontal header
 | 	ui.draw_rect(0, 0, WinSize, CellSize, HeaderColor)// Horizontal header
 | ||||||
| 	gx.draw_rect(0, 0, CELL_SIZE, WIN_SIZE, HEADER_COLOR) // Vertical header
 | 	ui.draw_rect(0, 0, CellSize, WinSize, HeaderColor)// Vertical header
 | ||||||
| 	for i := MIN; i <= MAX; i++ { | 	for i := Min; i <= Max; i++ { | ||||||
| 		y := CELL_SIZE * (i - MIN) | 		y := CellSize * (i - Min) | ||||||
| 		for j := MIN; j <= MAX; j++ { | 		for j := Min; j <= Max; j++ { | ||||||
| 			// Skip top left corner
 | 			// Skip top left corner
 | ||||||
| 			if i == MIN && j == MIN { | 			if i == Min && j == Min { | ||||||
| 				continue | 				continue | ||||||
| 			} | 			} | ||||||
| 			// Draw the result
 | 			// Draw the result
 | ||||||
| 			x := CELL_SIZE * (j - MIN) | 			x := CellSize * (j - Min) | ||||||
| 			res := i * j | 			res := i * j | ||||||
| 			mut text_padding_x := (CELL_SIZE - FONT_SIZE) / 2 - 1 | 			mut text_padding_x := (CellSize - FontSize) / 2 - 1 | ||||||
| 			text_padding_y := text_padding_x - 3 | 			text_padding_y := text_padding_x - 3 | ||||||
| 			if res < 10 { | 			if res < 10 { | ||||||
| 				text_padding_x += 9 | 				text_padding_x += 9 | ||||||
| 			} | 			} | ||||||
| 			gx.draw_text(x + text_padding_x, y + text_padding_y, res.str(), TEXT_CFG) | 			ui.draw_text(x + text_padding_x, y + text_padding_y, res.str(), TextCfg) | ||||||
| 		} | 		} | ||||||
| 		// Horizontal lines
 | 		// Horizontal lines
 | ||||||
| 		gx.draw_line(0, y, WIN_SIZE, y) | 		ui.draw_line(0, y, WinSize, y) | ||||||
| 		// Vertical lines
 | 		// Vertical lines
 | ||||||
| 		gx.draw_line(y, 0, y, WIN_SIZE) | 		ui.draw_line(y, 0, y, WinSize) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue