差分
このページの2つのバージョン間の差分を表示します。
次のリビジョン | 前のリビジョン | ||
fltk:example-app-countdown_timer [2025/05/27 07:48] – 作成 freemikan | fltk:example-app-countdown_timer [2025/06/12 11:45] (現在) – [スクリーンショット] Remove imagebox freemikan | ||
---|---|---|---|
行 1: | 行 1: | ||
- | ====== | + | ====== |
- | {{: | + | [[fltk:|{{: |
===== スクリーンショット ===== | ===== スクリーンショット ===== | ||
- | + | {{ : | |
===== プロジェクトレイアウト ===== | ===== プロジェクトレイアウト ===== | ||
行 41: | 行 40: | ||
#include < | #include < | ||
#include < | #include < | ||
- | #include < | ||
#include < | #include < | ||
+ | #include < | ||
- | #include <array> | + | #include <format> |
- | #include <cstdio> | + | #include <string> |
struct AppContext { | struct AppContext { | ||
int start = 10; | int start = 10; | ||
int count = 0; | int count = 0; | ||
- | Fl_Box *countdown_digits; | + | Fl_Box *digits; |
Fl_Button *start_button; | Fl_Button *start_button; | ||
Fl_Button *reset_button; | Fl_Button *reset_button; | ||
- | std::array< | + | std::string sbuf; |
}; | }; | ||
- | AppContext *as_app_context(void *ptr) { | + | AppContext *as_app_context(void *ptr) { return static_cast< |
- | | + | |
- | } | + | |
- | void update_countdown_digits_label(AppContext *ctx) { | + | void update_digits_label(AppContext *ctx) { |
- | | + | ctx->sbuf.clear(); |
- | ctx->countdown_digits-> | + | std:: |
+ | ctx->digits-> | ||
} | } | ||
void timeout_cb(void *data) { | void timeout_cb(void *data) { | ||
auto ctx = as_app_context(data); | auto ctx = as_app_context(data); | ||
- | | + | |
if (ctx-> | if (ctx-> | ||
- | ctx-> | + | |
+ | | ||
return; | return; | ||
} | } | ||
行 75: | 行 74: | ||
--ctx-> | --ctx-> | ||
- | | + | |
- | + | ||
Fl:: | Fl:: | ||
} | } | ||
void start_button_cb(Fl_Widget *w, void *data) { | void start_button_cb(Fl_Widget *w, void *data) { | ||
- | Fl:: | + | |
- | w->deactivate(); | + | // Start button pressed |
+ | | ||
+ | w-> | ||
+ | | ||
+ | // Pause button pressed | ||
+ | Fl:: | ||
+ | | ||
+ | } | ||
} | } | ||
行 88: | 行 94: | ||
auto ctx = as_app_context(data); | auto ctx = as_app_context(data); | ||
ctx-> | ctx-> | ||
- | | + | |
} | } | ||
int main() { | int main() { | ||
- | auto window = new Fl_Window(600, 600, " | + | auto window = new Fl_Window(300, 300, "Countdown |
- | + | ||
- | auto countdown_digits | + | auto digits |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
+ | |||
+ | auto start_button = new Fl_Button(10, | ||
+ | auto reset_button = new Fl_Button(150, | ||
- | auto start_button = new Fl_Button(210, | ||
- | auto reset_button = new Fl_Button(310, | ||
- | | ||
int const countdown_start = 10; | int const countdown_start = 10; | ||
- | | + | |
AppContext ctx{ | AppContext ctx{ | ||
- | | + | |
- | .count = countdown_start, | + | .count = countdown_start, |
- | .countdown_digits | + | .digits |
- | .start_button = start_button, | + | .start_button = start_button, |
- | .reset_button = reset_button, | + | .reset_button = reset_button, |
}; | }; | ||
- | | + | |
- | | + | |
start_button-> | start_button-> | ||
reset_button-> | reset_button-> | ||
- | | + | |
window-> | window-> | ||
window-> | window-> |