summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-07-22 18:02:25 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-07-22 18:02:25 +0300
commit8fa777a1a633e4b09e02c3725880447c6f37dcb3 (patch)
tree6351c8a048abe98126d871ff5122f2b3639f085d /src/ui
parentbc07d618e27147a8510f2077d0e3708aaa467e27 (diff)
Preferences: Added setting for Return key behavior
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/util.c70
1 files changed, 57 insertions, 13 deletions
diff --git a/src/ui/util.c b/src/ui/util.c
index 63600557..152df0bd 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -1607,6 +1607,22 @@ static void addPrefsInputWithHeading_(iWidget *headings, iWidget *values,
1607 addDialogInputWithHeading_(headings, values, format_CStr("${%s}", id), id, input); 1607 addDialogInputWithHeading_(headings, values, format_CStr("${%s}", id), id, input);
1608} 1608}
1609 1609
1610static size_t findWidestItemLabel_(const iMenuItem *items, size_t num) {
1611 int widest = 0;
1612 size_t widestPos = iInvalidPos;
1613 for (size_t i = 0; i < num; i++) {
1614 const int width =
1615 measure_Text(uiLabel_FontId,
1616 translateCStr_Lang(items[i].label))
1617 .advance.x;
1618 if (widestPos == iInvalidPos || width > widest) {
1619 widest = width;
1620 widestPos = i;
1621 }
1622 }
1623 return widestPos;
1624}
1625
1610iWidget *makePreferences_Widget(void) { 1626iWidget *makePreferences_Widget(void) {
1611 iWidget *dlg = makeSheet_Widget("prefs"); 1627 iWidget *dlg = makeSheet_Widget("prefs");
1612 addChildFlags_Widget(dlg, 1628 addChildFlags_Widget(dlg,
@@ -1661,20 +1677,8 @@ iWidget *makePreferences_Widget(void) {
1661 { "${lang.zh.hant} - zh", 0, 0, "uilang id:zh_Hant" }, 1677 { "${lang.zh.hant} - zh", 0, 0, "uilang id:zh_Hant" },
1662 }; 1678 };
1663 pushBackN_Array(uiLangs, langItems, iElemCount(langItems)); 1679 pushBackN_Array(uiLangs, langItems, iElemCount(langItems));
1664 //sort_Array(uiLangs, cmp_MenuItem_);
1665 /* TODO: Add an arrange flag for resizing parent to widest child. */ 1680 /* TODO: Add an arrange flag for resizing parent to widest child. */
1666 int widest = 0; 1681 size_t widestPos = findWidestItemLabel_(data_Array(uiLangs), size_Array(uiLangs));
1667 size_t widestPos = iInvalidPos;
1668 iConstForEach(Array, i, uiLangs) {
1669 const int width =
1670 measure_Text(uiLabel_FontId,
1671 translateCStr_Lang(((const iMenuItem *) i.value)->label))
1672 .advance.x;
1673 if (widestPos == iInvalidPos || width > widest) {
1674 widest = width;
1675 widestPos = index_ArrayConstIterator(&i);
1676 }
1677 }
1678 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.uilang}"))); 1682 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.uilang}")));
1679 setId_Widget(addChildFlags_Widget(values, 1683 setId_Widget(addChildFlags_Widget(values,
1680 iClob(makeMenuButton_LabelWidget( 1684 iClob(makeMenuButton_LabelWidget(
@@ -1691,6 +1695,46 @@ iWidget *makePreferences_Widget(void) {
1691 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.customframe}"))); 1695 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.customframe}")));
1692 addChild_Widget(values, iClob(makeToggle_Widget("prefs.customframe"))); 1696 addChild_Widget(values, iClob(makeToggle_Widget("prefs.customframe")));
1693#endif 1697#endif
1698 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.returnkey}")));
1699 /* Return key behaviors. */ {
1700 const iMenuItem returnKeyBehaviors[] = {
1701 { "${prefs.returnkey.linebreak} "
1702 uiTextAction_ColorEscape shift_Icon return_Icon restore_ColorEscape
1703 " ${prefs.returnkey.accept} "
1704 uiTextAction_ColorEscape return_Icon,
1705 0,
1706 0,
1707 format_CStr("returnkey.set arg:%d", default_ReturnKeyBehavior) },
1708 { "${prefs.returnkey.linebreak} "
1709 uiTextAction_ColorEscape return_Icon restore_ColorEscape
1710 " ${prefs.returnkey.accept} "
1711 uiTextAction_ColorEscape shift_Icon return_Icon,
1712 0,
1713 0,
1714 format_CStr("returnkey.set arg:%d", acceptWithShift_ReturnKeyBehavior) },
1715 { "${prefs.returnkey.linebreak} "
1716 uiTextAction_ColorEscape return_Icon restore_ColorEscape
1717 " ${prefs.returnkey.accept} " uiTextAction_ColorEscape
1718#if defined (iPlatformApple)
1719 "\u2318" return_Icon,
1720#else
1721 "Ctrl" return_Icon,
1722#endif
1723 0,
1724 0,
1725 format_CStr("returnkey.set arg:%d", acceptWithPrimaryMod_ReturnKeyBehavior) },
1726 };
1727 iLabelWidget *returnKey = makeMenuButton_LabelWidget(
1728 returnKeyBehaviors[findWidestItemLabel_(returnKeyBehaviors,
1729 iElemCount(returnKeyBehaviors))]
1730 .label,
1731 returnKeyBehaviors,
1732 iElemCount(returnKeyBehaviors));
1733 setBackgroundColor_Widget(findChild_Widget(as_Widget(returnKey), "menu"),
1734 uiBackgroundMenu_ColorId);
1735 setId_Widget(addChildFlags_Widget(values, iClob(returnKey), alignLeft_WidgetFlag),
1736 "prefs.returnkey");
1737 }
1694 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.animate}"))); 1738 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.animate}")));
1695 addChild_Widget(values, iClob(makeToggle_Widget("prefs.animate"))); 1739 addChild_Widget(values, iClob(makeToggle_Widget("prefs.animate")));
1696 makeTwoColumnHeading_("${heading.prefs.scrolling}", headings, values); 1740 makeTwoColumnHeading_("${heading.prefs.scrolling}", headings, values);