feat: add time zone configuration applet to System Configuration
This commit is contained in:
@@ -53,32 +53,6 @@ void settings_draw_display(Canvas& c, SettingsState* st) {
|
||||
mtk::widget_state(s.ui_scale == 1), theme);
|
||||
mtk::draw_button(c, {bx + (sbw + 8) * 2, y, sbw, btn_h}, "Large", mtk::BUTTON_SECONDARY,
|
||||
mtk::widget_state(s.ui_scale == 2), theme);
|
||||
y += btn_h + 20;
|
||||
|
||||
mtk::draw_separator(c, x, y, c.w - 2 * x, theme);
|
||||
y += 16;
|
||||
|
||||
c.text(x, y + 6, "UTC Offset", theme.text);
|
||||
Rect minus_btn = {bx, y, 36, btn_h};
|
||||
Rect plus_btn = {bx + 36 + 90, y, 36, btn_h};
|
||||
mtk::draw_button(c, minus_btn, "-", mtk::BUTTON_SECONDARY, mtk::widget_state(), theme);
|
||||
mtk::draw_button(c, plus_btn, "+", mtk::BUTTON_SECONDARY, mtk::widget_state(), theme);
|
||||
|
||||
int off = s.tz_offset_minutes;
|
||||
int off_h = off / 60;
|
||||
int off_m = off % 60;
|
||||
if (off_m < 0) off_m = -off_m;
|
||||
|
||||
char tz_label[16];
|
||||
if (off_m) {
|
||||
snprintf(tz_label, sizeof(tz_label), "UTC%s%d:%02d", off_h >= 0 ? "+" : "", off_h, off_m);
|
||||
} else {
|
||||
snprintf(tz_label, sizeof(tz_label), "UTC%s%d", off_h >= 0 ? "+" : "", off_h);
|
||||
}
|
||||
|
||||
int tw = text_width(tz_label);
|
||||
int label_w = 90;
|
||||
c.text(bx + 36 + (label_w - tw) / 2, y + 6, tz_label, theme.text);
|
||||
}
|
||||
|
||||
bool settings_handle_display_click(SettingsState* st, int mx, int cy) {
|
||||
@@ -142,26 +116,6 @@ bool settings_handle_display_click(SettingsState* st, int mx, int cy) {
|
||||
settings_persist(st);
|
||||
return true;
|
||||
}
|
||||
y += btn_h + 20 + 16;
|
||||
|
||||
Rect minus_btn = {bx, y, 36, btn_h};
|
||||
Rect plus_btn = {bx + 36 + 90, y, 36, btn_h};
|
||||
if (minus_btn.contains(mx, cy)) {
|
||||
if (s.tz_offset_minutes > -720) {
|
||||
s.tz_offset_minutes -= 60;
|
||||
montauk::settz(s.tz_offset_minutes);
|
||||
settings_persist_tz(st);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (plus_btn.contains(mx, cy)) {
|
||||
if (s.tz_offset_minutes < 840) {
|
||||
s.tz_offset_minutes += 60;
|
||||
montauk::settz(s.tz_offset_minutes);
|
||||
settings_persist_tz(st);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -45,12 +45,4 @@ void settings_persist(SettingsState* st) {
|
||||
doc.destroy();
|
||||
}
|
||||
|
||||
void settings_persist_tz(SettingsState* st) {
|
||||
montauk::toml::Doc doc;
|
||||
doc.init();
|
||||
montauk::config::set_int(&doc, "timezone.offset_minutes", st->desktop->settings.tz_offset_minutes);
|
||||
montauk::config::save("timezone", &doc);
|
||||
doc.destroy();
|
||||
}
|
||||
|
||||
} // namespace settings_app
|
||||
|
||||
@@ -91,6 +91,5 @@ bool settings_handle_display_click(SettingsState* st, int mx, int cy);
|
||||
void settings_draw_about(Canvas& c, SettingsState* st);
|
||||
|
||||
void settings_persist(SettingsState* st);
|
||||
void settings_persist_tz(SettingsState* st);
|
||||
|
||||
} // namespace settings_app
|
||||
|
||||
Reference in New Issue
Block a user