FTK Learning Record (a progress bar article)

Source: Internet
Author: User

" Disclaimer: Copyright All, welcome reprint, do not use for commercial purposes. Contact mailbox: feixiaoxing @163.com "


First of all. Before you start today's article. Let's show our friends the effect of the previous piece of code. Effects such as the following,


watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvzmvpeglhb3hpbmc=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast "/>


Interested friends can find this code and see how the performance works.


Today, we can look at the relevant code of the progress bar.

Progress bar, said simple also simple. The complexity is complicated, too.

I think the most impressive thing about the progress bar is the previous Windows XP boot situation, where there is a progress bar. The same, I prefer to use the code to illustrate the problem,

< /span>

#include "ftk.h" Static Ret button_quit_clicked (void* ctx, void* obj) {ftk_quit (); return RET_OK;} Static Ret update_progress (void* ctx) {int percent = 0; ftkwidget* Progress_bar = Ctx;percent = Ftk_progress_bar_get_percent (Progress_bar); if (percent = =) {return ret_ REMOVE;} Ftk_progress_bar_set_percent (Progress_bar, percent +); return RET_OK;} int ftk_main (int argc, char* argv[]) {int width = 0;int height = 0; ftkwidget* win = NULL; ftkwidget* button = NULL; ftkwidget* Progress_bar = NULL; ftksource* timer = null;ftk_init (argc, argv); win = Ftk_app_window_create (); width = ftk_widget_width (win); height = Ftk_ Widget_height (win); width = Width-20;progress_bar = Ftk_progress_bar_create (Win, ten, HEIGHT/6, width,); Ftk_progress_ Bar_set_percent (progress_bar); timer = Ftk_source_timer_create (update_progress, progress_bar); ftk_main_ Loop_add_source (Ftk_default_main_loop (), timer);p Rogress_bar = Ftk_progress_bar_create (Win, ten, HEIGHT/3, width, 20); Ftk_progress_bar_set_percent (Progress_bar, 20);Timer = ftk_source_timer_create (update_progress, Progress_bar); Ftk_main_loop_add_source (Ftk_default_main_ Loop (), timer);p Rogress_bar = Ftk_progress_bar_create (Win, ten, HEIGHT/2, width,); Ftk_progress_bar_set_percent ( Progress_bar); timer = Ftk_source_timer_create (update_progress, Progress_bar); Ftk_main_loop_add_source (FTK _default_main_loop (), timer), Button = Ftk_button_create (Win, WIDTH/4, 3*HEIGHT/4, WIDTH/2,); Ftk_widget_set_text ( button, "quit"); Ftk_button_set_clicked_listener (Button, button_quit_clicked, Win); Ftk_window_set_focus (Win, Button ); Ftk_widget_set_text (Win, "Progress_bar demo"); Ftk_widget_show_all (win, 1); Ftk_widget_set_attr (Win, Ftk_attr_quit _when_close); Ftk_run (); return 0;}


The FTK process. The previous articles have already been covered, and we will not repeat them here. This. We just need to focus on the relevant code of the progress bar. It's not hard to find it from the code. This is in addition to creating 1 buttons. 3 Progress bars have also been created. The initial value of the progress bar is 20%.

So how is the progress bar added? In fact, the code here also creates 3 timer.

It tells us that the update_progress function is called every once in a while. The progress bar will now have a corresponding Add.

Once 100%. It's over.



Same, the execution effect is reproduced next time.



Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

FTK Learning Record (a progress bar article)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.