From 8b27681de024bc1a74188da7a1c1fc909a3621bc Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sun, 14 Apr 2019 08:31:13 +0200 Subject: [PATCH] examples/times_table: simplify --- examples/times_table/times_table.v | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/examples/times_table/times_table.v b/examples/times_table/times_table.v index 046b953983..58e6891677 100644 --- a/examples/times_table/times_table.v +++ b/examples/times_table/times_table.v @@ -27,20 +27,16 @@ fn main() { // ui.Window uses native drawing API (Core Graphics, GDI+) fn draw() { + // Horizontal header + gx.draw_rect(0, 0, WIN_SIZE, CELL_SIZE, HEADER_COLOR) + // Vertical header + gx.draw_rect(0, 0, CELL_SIZE, WIN_SIZE, HEADER_COLOR) for i := MIN; i <= MAX; i++ { y := CELL_SIZE * (i - MIN) for j := MIN; j <= MAX; j++ { x := CELL_SIZE * (j - MIN) - // Horizontal header - if i == MIN { - gx.draw_rect(x, y, CELL_SIZE, CELL_SIZE, HEADER_COLOR) - } - // Vertical header - if j == MIN { - gx.draw_rect(x, y, CELL_SIZE, CELL_SIZE, HEADER_COLOR) - } // Draw the result - if !(i == MIN && j == MIN) { + if ! (i == MIN && j == MIN) { res := i * j mut text_padding_x := (CELL_SIZE - FONT_SIZE) / 2 - 1 text_padding_y := text_padding_x - 3 @@ -49,13 +45,11 @@ fn draw() { } gx.draw_text(x + text_padding_x, y + text_padding_y, res.str(), TEXT_CFG) } - // Vertical lines - if i == MIN { - gx.draw_line(x, 0, x, WIN_SIZE) - } } // Horizontal lines gx.draw_line(0, y, WIN_SIZE, y) + // Vertical lines + gx.draw_line(y, 0, y, WIN_SIZE) } }