summaryrefslogtreecommitdiff
path: root/src/lib/edje/edje_calc.c
diff options
context:
space:
mode:
authorYoungbok Shin <youngb.shin@samsung.com>2017-02-14 16:16:45 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2017-02-14 16:17:02 +0900
commita6fff5bc1e5e30a946e435369bcbaa406dd5d5ba (patch)
tree83d082c44c74dfccc9d5bb18048bd796e4eb8051 /src/lib/edje/edje_calc.c
parentc39855a8ac6f86c2dd8b1856ed70f85e0e521f3e (diff)
Edje calc: Fix textblock size calculation logic
Summary: In singleline textblock, using "text.min: 1 0" and min, max width, Edje allows to use expandable text with ellipsis. It shows ellipsis when only text's width reach the max width. But, Edje couldn't support same feature on multiline textblock. Edje dose not use max height or text.max properly if ellipsis is enabled. This feature is very useful to make a layout with dynamically aligned text. @fix Reviewers: cedric, tasn, woohyun, raster, herdsman Subscribers: z-wony, eagleeye, jpeg Differential Revision: https://phab.enlightenment.org/D3595
Diffstat (limited to 'src/lib/edje/edje_calc.c')
-rw-r--r--src/lib/edje/edje_calc.c305
1 files changed, 267 insertions, 38 deletions
diff --git a/src/lib/edje/edje_calc.c b/src/lib/edje/edje_calc.c
index 320fbffc89..d52069d85c 100644
--- a/src/lib/edje/edje_calc.c
+++ b/src/lib/edje/edje_calc.c
@@ -1445,9 +1445,17 @@ _edje_part_recalc_single_textblock(FLOAT_T sc,
1445 int *minw, int *minh, 1445 int *minw, int *minh,
1446 int *maxw, int *maxh) 1446 int *maxw, int *maxh)
1447{ 1447{
1448 int min_calc_w = 0, min_calc_h = 0;
1449
1448 if ((ep->type != EDJE_RP_TYPE_TEXT) || 1450 if ((ep->type != EDJE_RP_TYPE_TEXT) ||
1449 (!ep->typedata.text)) 1451 (!ep->typedata.text))
1450 return; 1452 return;
1453
1454 /* min_calc_* values need to save calculated minumum size
1455 * for maximum size calculation */
1456 if (minw) min_calc_w = *minw;
1457 if (minh) min_calc_h = *minh;
1458
1451 if (chosen_desc) 1459 if (chosen_desc)
1452 { 1460 {
1453 Evas_Coord tw, th, ins_l, ins_r, ins_t, ins_b; 1461 Evas_Coord tw, th, ins_l, ins_r, ins_t, ins_b;
@@ -1592,56 +1600,277 @@ _edje_part_recalc_single_textblock(FLOAT_T sc,
1592 } 1600 }
1593 if ((chosen_desc->text.min_x) || (chosen_desc->text.min_y)) 1601 if ((chosen_desc->text.min_x) || (chosen_desc->text.min_y))
1594 { 1602 {
1595 int mw = 0, mh = 0; 1603 evas_object_textblock_style_insets_get(ep->object, &ins_l,
1604 &ins_r, &ins_t, &ins_b);
1596 1605
1597 tw = th = 0; 1606 tw = th = 0;
1598 if (!chosen_desc->text.min_x) 1607 if (!chosen_desc->text.min_x)
1599 { 1608 {
1600 efl_gfx_size_set(ep->object, TO_INT(params->eval.w), TO_INT(params->eval.h)); 1609 /* text.min: 0 1
1601 efl_canvas_text_size_formatted_get(ep->object, &tw, &th); 1610 * text.max: X X */
1611 int temp_h = TO_INT(params->eval.h);
1612 int temp_w = TO_INT(params->eval.w);
1613
1614 if (min_calc_w > temp_w)
1615 temp_w = min_calc_w;
1616 if ((!chosen_desc->text.max_x) &&
1617 maxw && (*maxw > -1) && (*maxw < temp_w))
1618 temp_w = *maxw;
1619
1620 if (chosen_desc->text.max_y)
1621 {
1622 /* text.min: 0 1
1623 * text.max: X 1 */
1624 temp_h = INT_MAX / 10000;
1625 }
1626 else if (maxh && (*maxh > TO_INT(params->eval.h)))
1627 {
1628 /* text.min: 0 1
1629 * text.max: X 0
1630 * And there is a limit for height. */
1631 temp_h = *maxh;
1632 }
1633
1634 /* If base width for calculation is 0,
1635 * don't get meaningless height for multiline */
1636 if (temp_w > 0)
1637 {
1638 efl_gfx_size_set(ep->object, temp_w, temp_h);
1639 efl_canvas_text_size_formatted_get(ep->object, &tw, &th);
1640
1641 tw += ins_l + ins_r;
1642 th += ins_t + ins_b;
1643 }
1644 else
1645 {
1646 efl_canvas_text_size_native_get(ep->object, NULL, &th);
1647
1648 th += ins_t + ins_b;
1649 }
1602 } 1650 }
1603 else 1651 else
1604 evas_object_textblock_size_native_get(ep->object, &tw, &th);
1605 evas_object_textblock_style_insets_get(ep->object, &ins_l,
1606 &ins_r, &ins_t, &ins_b);
1607 mw = ins_l + tw + ins_r;
1608 mh = ins_t + th + ins_b;
1609 if (minw && chosen_desc->text.min_x)
1610 { 1652 {
1611 if (mw > *minw) *minw = mw; 1653 /* text.min: 1 X
1654 * text.max: X X */
1655 if (chosen_desc->text.min_y && (!chosen_desc->text.max_x) &&
1656 maxw && (*maxw > -1))
1657 {
1658 /* text.min: 1 1
1659 * text.max: 0 X */
1660 int temp_w, temp_h;
1661
1662 temp_w = *maxw;
1663 temp_h = INT_MAX / 10000;
1664
1665 if (min_calc_w > temp_w)
1666 temp_w = min_calc_w;
1667
1668 if ((!chosen_desc->text.max_y) && maxh && (*maxh > -1))
1669 {
1670 /* text.min: 1 1
1671 * text.max: 0 0
1672 * There is limit for height. */
1673 temp_h = *maxh;
1674 }
1675
1676 efl_gfx_size_set(ep->object, temp_w, temp_h);
1677 efl_canvas_text_size_formatted_get(ep->object, &tw, &th);
1678
1679 tw += ins_l + ins_r;
1680 th += ins_t + ins_b;
1681
1682 /* If base width for calculation is 0,
1683 * don't get meaningless height for multiline */
1684 if (temp_w <= 0)
1685 {
1686 efl_canvas_text_size_native_get(ep->object, NULL, &th);
1687
1688 th += ins_t + ins_b;
1689 }
1690 }
1691 else
1692 {
1693 /* text.min: 1 X
1694 * text.max: 1 X
1695 * Or,
1696 * text.min: 1 X
1697 * text.max: 0 X without max width.
1698 * It is a singleline Textblock. */
1699 efl_canvas_text_size_native_get(ep->object, &tw, &th);
1700
1701 tw += ins_l + ins_r;
1702 th += ins_t + ins_b;
1703
1704 if (!chosen_desc->text.max_x &&
1705 (maxw && (*maxw > -1) && (*maxw < tw)))
1706 {
1707 /* text.min: 1 0
1708 * text.max: 0 X */
1709 tw = *maxw;
1710 }
1711 }
1612 } 1712 }
1613 if (minh && chosen_desc->text.min_y) 1713
1714 if (tw > min_calc_w) min_calc_w = tw;
1715 if (th > min_calc_h) min_calc_h = th;
1716 if (chosen_desc->text.min_x && minw) *minw = min_calc_w;
1717 if (chosen_desc->text.min_y && minh) *minh = min_calc_h;
1718 }
1719
1720 if ((chosen_desc->text.max_x) || (chosen_desc->text.max_y))
1721 {
1722 evas_object_textblock_style_insets_get(ep->object, &ins_l, &ins_r,
1723 &ins_t, &ins_b);
1724
1725 tw = th = 0;
1726 if (!chosen_desc->text.max_x)
1614 { 1727 {
1615 if (mh > *minh) *minh = mh; 1728 /* text.min: X X
1729 * text.max: 0 1 */
1730 int temp_w, temp_h;
1731
1732 if (chosen_desc->text.min_y)
1733 {
1734 /* text.min: X 1
1735 * text.max: 0 1
1736 * Already calculated in text for height. */
1737 tw = TO_INT(params->eval.w);
1738 if (min_calc_w > tw)
1739 tw = min_calc_w;
1740
1741 th = min_calc_h;
1742 }
1743 else
1744 {
1745 /* text.min: X 0
1746 * text.max: 0 1 */
1747 temp_w = TO_INT(params->eval.w);
1748 temp_h = TO_INT(params->eval.h);
1749
1750 if (min_calc_w > temp_w)
1751 temp_w = min_calc_w;
1752 if (maxw && (*maxw > -1) && (*maxw < temp_w))
1753 temp_w = *maxw;
1754 if (min_calc_h > temp_h)
1755 temp_h = min_calc_h;
1756
1757 /* If base width for calculation is 0,
1758 * don't get meaningless height for multiline */
1759 if (temp_w > 0)
1760 {
1761 efl_gfx_size_set(ep->object, temp_w, temp_h);
1762 efl_canvas_text_size_formatted_get(ep->object, &tw, &th);
1763
1764 tw += ins_l + ins_r;
1765 th += ins_t + ins_b;
1766 }
1767 else
1768 {
1769 efl_canvas_text_size_native_get(ep->object, NULL, &th);
1770
1771 th += ins_t + ins_b;
1772 }
1773 }
1616 } 1774 }
1617 } 1775 else
1618 } 1776 {
1777 /* text.max: 1 X */
1778 if (chosen_desc->text.min_x)
1779 {
1780 /* text.min: 1 X
1781 * text.max: 1 X
1782 * Singleline. */
1783 efl_canvas_text_size_native_get(ep->object, &tw, &th);
1619 1784
1620 if ((chosen_desc->text.max_x) || (chosen_desc->text.max_y)) 1785 tw += ins_l + ins_r;
1621 { 1786 th += ins_t + ins_b;
1622 int mw = 0, mh = 0; 1787 }
1788 else
1789 {
1790 /* text.min: 0 X
1791 * text.max: 1 X */
1792 if (chosen_desc->text.max_y)
1793 {
1794 /* text.min: 0 X
1795 * text.max: 1 1 */
1796 int temp_w, temp_h;
1797
1798 temp_w = TO_INT(params->eval.w);
1799 temp_h = TO_INT(params->eval.h);
1800
1801 if (min_calc_w > temp_w)
1802 temp_w = min_calc_w;
1803 if (min_calc_h > temp_h)
1804 temp_h = min_calc_h;
1805
1806 if (chosen_desc->text.min_y)
1807 {
1808 /* text.min: 0 1
1809 * text.max: 1 1
1810 * There is no need to calculate it again. */
1811 tw = min_calc_w;
1812 th = min_calc_h;
1813 }
1814 else
1815 {
1816 /* text.min: 0 0
1817 * text.max: 1 1 */
1818
1819 efl_gfx_size_set(ep->object, temp_w, temp_h);
1820 efl_canvas_text_size_formatted_get(ep->object, &tw, &th);
1821
1822 tw += ins_l + ins_r;
1823 th += ins_t + ins_b;
1824
1825 /* If base width for calculation is 0,
1826 * don't get meaningless height for multiline */
1827 if (temp_w <= 0)
1828 {
1829 efl_canvas_text_size_native_get(ep->object, NULL, &th);
1830
1831 th += ins_t + ins_b;
1832 }
1833 }
1834 }
1835 else
1836 {
1837 /* text.min: 0 X
1838 * text.max: 1 0 */
1839 int temp_w, temp_h;
1623 1840
1624 tw = th = 0; 1841 temp_w = TO_INT(params->eval.w);
1625 if (!chosen_desc->text.max_x) 1842 if (min_calc_w > temp_w)
1626 { 1843 temp_w = min_calc_w;
1627 efl_gfx_size_set(ep->object, TO_INT(params->eval.w), TO_INT(params->eval.h)); 1844
1628 efl_canvas_text_size_formatted_get(ep->object, &tw, &th); 1845 efl_gfx_size_get(ep->object, NULL, &temp_h);
1629 } 1846 efl_gfx_size_set(ep->object, temp_w, temp_h);
1630 else 1847 efl_canvas_text_size_formatted_get(ep->object, &tw, &th);
1631 evas_object_textblock_size_native_get(ep->object, &tw, &th); 1848
1632 evas_object_textblock_style_insets_get(ep->object, &ins_l, &ins_r, 1849 tw += ins_l + ins_r;
1633 &ins_t, &ins_b); 1850 th += ins_t + ins_b;
1634 mw = ins_l + tw + ins_r; 1851
1635 mh = ins_t + th + ins_b; 1852 /* If base width for calculation is 0,
1636 if (maxw && chosen_desc->text.max_x) 1853 * don't get meaningless height for multiline */
1637 { 1854 if (temp_w <= 0)
1638 if (mw > *maxw) *maxw = mw; 1855 {
1639 if (minw && (*maxw < *minw)) *maxw = *minw; 1856 efl_canvas_text_size_native_get(ep->object, NULL, &th);
1640 } 1857
1641 if (maxh && chosen_desc->text.max_y) 1858 th += ins_t + ins_b;
1642 { 1859 }
1643 if (mh > *maxh) *maxh = mh; 1860 }
1644 if (minh && (*maxh < *minh)) *maxh = *minh; 1861 }
1862 }
1863
1864 if (maxw && chosen_desc->text.max_x)
1865 {
1866 if (tw > *maxw) *maxw = tw;
1867 if (minw && (*maxw < *minw)) *maxw = *minw;
1868 }
1869 if (maxh && chosen_desc->text.max_y)
1870 {
1871 if (th > *maxh) *maxh = th;
1872 if (minh && (*maxh < *minh)) *maxh = *minh;
1873 }
1645 } 1874 }
1646 } 1875 }
1647 1876