rewrite apple's HeadsUpUI to make the code more compact and the structure more clear