fn do_button(platform: &Platform,
             context: &mut UIContext,
             spec: &ButtonSpec,
             left_mouse_pressed: bool,
             left_mouse_released: bool)
             -> bool {
    let mut result = false;

    let mouse_pos = (platform.mouse_position)();
    let inside = inside_rect(mouse_pos, spec.x, spec.y, spec.w, spec.h);
    let id = spec.id;

    if context.active == id {
        if left_mouse_released {
            result = context.hot == id && inside;

            context.set_not_active();
        }
    } else if context.hot == id {
        if left_mouse_pressed {
            context.set_active(id);
        }
    }

    if inside {
        context.set_next_hot(id);
    }

    if context.active == id && left_mouse_pressed {
        draw_rect_with(platform,
                       spec.x,
                       spec.y,
                       spec.w,
                       spec.h,
                       ["╔", "═", "╕", "║", "│", "╙", "─", "┘"]);
    } else if context.hot == id {
        draw_rect_with(platform,
                       spec.x,
                       spec.y,
                       spec.w,
                       spec.h,
                       ["┌", "─", "╖", "│", "║", "╘", "═", "╝"]);
    } else {
        draw_rect(platform, spec.x, spec.y, spec.w, spec.h);
    }

    print_centered_line(platform, spec.x, spec.y, spec.w, spec.h, &spec.text);

    return result;
}
//calling this once will swallow multiple clicks on the button. We could either
//pass in and return the number of clicks to fix that, or this could simply be
//called multiple times per frame (once for each click).
calling this once will swallow multiple clicks on the button. We could either
pass in and return the number of clicks to fix that, or this could simply be
called multiple times per frame (once for each click).
calling this once will swallow multiple clicks on the button . We could either pass in and return the number of clicks to fix that or this could simply be called multiple times per frame ( once for each click ) .
fn do_button(platform: &Platform,
             context: &mut UIContext,
             spec: &ButtonSpec,
             left_mouse_pressed: bool,
             left_mouse_released: bool)
             -> bool {
    let mut result = false;
    let mouse_pos = (platform.mouse_position)();
    let inside = inside_rect(mouse_pos, spec.x, spec.y, spec.w, spec.h);
    let id = spec.id;
    if context.active == id {
        if left_mouse_released {
            result = context.hot == id && inside;
            context.set_not_active();
        }
    } else if context.hot == id {
        if left_mouse_pressed {
            context.set_active(id);
        }
    }
    if inside {
        context.set_next_hot(id);
    }
    if context.active == id && left_mouse_pressed {
        draw_rect_with(platform,
                       spec.x,
                       spec.y,
                       spec.w,
                       spec.h,
                       ["╔", "═", "╕", "║", "│", "╙", "─", "┘"]);
    } else if context.hot == id {
        draw_rect_with(platform,
                       spec.x,
                       spec.y,
                       spec.w,
                       spec.h,
                       ["┌", "─", "╖", "│", "║", "╘", "═", "╝"]);
    } else {
        draw_rect(platform, spec.x, spec.y, spec.w, spec.h);
    }
    print_centered_line(platform, spec.x, spec.y, spec.w, spec.h, &spec.text);
    return result;
}
fn do_button ( platform : & Platform , context : & mut UIContext , spec : & ButtonSpec , left_mouse_pressed : bool , left_mouse_released : bool ) -> bool { let mut result = false ; let mouse_pos = ( platform . mouse_position ) ( ) ; let inside = inside_rect ( mouse_pos , spec . x , spec . y , spec . w , spec . h ) ; let id = spec . id ; if context . active == id { if left_mouse_released { result = context . hot == id && inside ; context . set_not_active ( ) ; } } else if context . hot == id { if left_mouse_pressed { context . set_active ( id ) ; } } if inside { context . set_next_hot ( id ) ; } if context . active == id && left_mouse_pressed { draw_rect_with ( platform , spec . x , spec . y , spec . w , spec . h , [ " " " ╕ " , │ " ╙ , " , " ) ; } else if context . hot == id { draw_rect_with ( platform , spec . x , spec . y , spec . w , spec . h , [ " " " ╖ " , ║ " ╘ , " , " ) ; } else { draw_rect ( platform , spec . x , spec . y , spec . w , spec . h ) ; } print_centered_line ( platform , spec . x , spec . y , spec . w , spec . h , & spec . text ) ; return result ; }
calling this once will swallow multiple clicks on the button.
calling this once will swallow multiple clicks on the button .
platform
&Platform
context
&mut UIContext
spec
&ButtonSpec
left_mouse_pressed
bool
left_mouse_released
bool
platform
&Platform
context
&mut UIContext
spec
&ButtonSpec
left_mouse_pressed
bool
left_mouse_released
bool