Revision: 4504 http://sourceforge.net/p/vexi/code/4504 Author: clrg Date: 2013-03-31 20:20:09 +0000 (Sun, 31 Mar 2013) Log Message: ----------- WIP
Modified Paths: -------------- branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/lib/text/edit.t branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/lib/widget/scrollbar.t branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/theme/classic/textarea.t Added Paths: ----------- branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/lib/text/default.t branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/lib/widget/textarea.t Added: branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/lib/text/default.t =================================================================== --- branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/lib/text/default.t (rev 0) +++ branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/lib/text/default.t 2013-03-31 20:20:09 UTC (rev 4504) @@ -0,0 +1,74 @@ +<!-- Copyright 2012 - see COPYING for details [LGPL] --> + +<vexi xmlns:ui="vexi://ui" xmlns:meta="vexi://meta" xmlns="org.vexi.lib"> + <meta:doc> + <author>Charles Goodwin</author> + <desc>A sane fallback text implementation</desc> + </meta:doc> + + <ui:box redirect=":$edit"> + // need a separate containing box because this template is designed to + // be pre-applied and the topmost-box layout properties may get altered + <ui:box align="topleft" layout="layer"> + <ui:box> + <text.edit id="edit" /> + // spacer for cursor in case of right alignment + <ui:box width="2" /> + </ui:box> + <role.repeatable id="cursor" display="false" fill="black" interval="300" width="1"> + + var counter = 0; // counter used to implement blinking + thisbox.moved = false; // used to track recent cursor movement + + /** the repeating action, makes the cursor blink */ + thisbox.action ++= function(v) { + // blink counter + counter = (++counter)%3; + if (moved) { + // reset counter / blink + counter = 1; + display = true; + + } else { + // blink + display = (counter != 0); + } + // reset moved; + moved = false; + cascade = v; + } + + /** display cursor if it's activated */ + thisbox.repeat ++= function(v) { cascade = v; display = repeat; } + + </role.repeatable> + </ui:box> + + thisbox.v_cursor = $cursor; + thisbox.v_edit = $edit; + + // assigned by imeplementation + $edit.v_scroll = thisbox.th_scroll; + + /** syncCursor function called by edit.t */ + $edit.syncCursor = function(cx, cy, cheight) { + $cursor.x = cx; + $cursor.y = cy; + $cursor.height = cheight; + + // temporarily delays the cursor flashing + $cursor.moved = true; + } + + /** activate cursor when focused */ + $edit.focused ++= function(v) { cascade = v; $cursor.repeat = v; } + + thisbox.cursorcolor ++= static.cursorcolorWrite; + + .util.redirect..addRedirect(thisbox, v_edit, "multiline", "textalign", "wraptext", "wrapwidth"); + + </ui:box> + + static.cursorcolorWrite = function(v) { cascade = v; trapee.v_cursor.fill = v; } + +</vexi> Modified: branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/lib/text/edit.t =================================================================== --- branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/lib/text/edit.t 2013-03-26 17:41:17 UTC (rev 4503) +++ branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/lib/text/edit.t 2013-03-31 20:20:09 UTC (rev 4504) @@ -4,6 +4,7 @@ <ui:box layout="place" align="topleft"> thisbox.multiline = true; + thisbox.scroll = null; thisbox.v_text = ""; var tip = false; @@ -52,73 +53,102 @@ return NON_ALPHA_NUMERIC; } - const mh = vexi.ui.font.height(font, fontsize, "dy"); + const line_height = vexi.ui.font.height(font, fontsize, "dy"); thisbox.reflowText = function() { + trace("reflowText"); clear(); if (!multiline) { addLine(v_text); return; } + var from_y = scroll.viewy; + var t = v_text; - var lasti = 0; - var nexti = 0; - var linen = 0; - var linew = 0; - var firstword = true; - var wordend, wordstart; - - const addLine = function(v) { - const b = new text.line(); - b.text = v; - b.minheight = mh; - b.x = 0; - b.y = mh * linen; - add(b); - linen ++; - linew = 0; - firstword = true; - } - - trace(width); - - for (var i=0; t.length>i; i++) { + var line_start = 0; + var line_end = 0; + var line_count = 0; + var line_width = 0; + var word_start = 0; + var word_width = 0; + var first_word = true; + + const addLine = function(v) { + const line_y = line_height * line_count; + if ((line_y + line_height > from_y) and (from_y + height > line_y)) { +// trace("adding: "+v); + const b = new text.line(); + b.text = v; + b.minheight = line_height; + b.x = 0; + b.y = line_y; + add(b); + } + line_count ++; + first_word = true; + } + + var word_type; + + for (var i=0; t.length>i; i++) { const c = t.charAt(i); - const n = t.charCodeAt(i); - const w = vexi.ui.font.width(font, fontsize, c); + const n = t.charCodeAt(i); const n_type = getCharType(n); - if (300>i) trace(i+":"+c+", "+n+", "+w+" ("+linew+"), "+n_type+", "+wordend+", "+wordstart); - if (n_type == NEWLINE) { - addLine(t.substring(lasti, i)); - lasti = i+1; - linew = 0; - continue; - } - - if (linew + w > width) { - addLine(t.substring(lasti, wordend?:i)+" "); - wordend = null; - lasti = wordstart?:i; - } - - if (n_type != wordtype) { - // new word; mark break point if necessary - if (wordtype != WHITESPACE) { - wordend = i; - } else { - wordstart = i; - } - wordtype = n_type; - } - - linew += w; - firstword = false; - } - - thisbox.scrollheight = (linen+1) * mh; - } - +// if (600 >= i) +// trace(i+": "+c+", "+n_type+", ("+line_width+" / "+width+"), ("+line_start+"->"+line_end+")"); + + // NEWLINE immediately breaks + // and resets everything to that point + if (n_type == NEWLINE) { + addLine(t.substring(line_start, i)); + line_start = i+1; + line_width = 0; + word_width = 0; + word_type = null; + continue; + } + + const w = vexi.ui.font.width(font, fontsize, c); + + if (first_word) { + word_type = n_type; + first_word = false; + } + + if (n_type == word_type) { + word_width += w; + word_type = n_type; + continue; + } + // else n_type != word_type + // i.e. new word/whitespace + + line_width += word_width; + + if (word_type != WHITESPACE) { + if (line_width >= width) { + addLine(t.substring(line_start, word_end)+" "); + line_start = word_start; + line_width = word_width; + } + word_end = i; + } else + if (n_type != WHITESPACE) { + word_start = i; + } + + word_type = n_type; + word_width = w; + } + + if (word_type != NEWLINE) { + addLine(t.substring(line_start, line_end)+" "); + } + + thisbox.scrollheight = (line_count+1) * line_height; + } + </ui:box> </vexi> Modified: branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/lib/widget/scrollbar.t =================================================================== --- branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/lib/widget/scrollbar.t 2013-03-26 17:41:17 UTC (rev 4503) +++ branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/lib/widget/scrollbar.t 2013-03-31 20:20:09 UTC (rev 4504) @@ -251,7 +251,7 @@ // theme trap assignments /** move up a line */ - const backAction = function(a) { shift = -lineshift; cascade = a; } + const backAction = function(a) { shift = -(mwheelshift * lineheight); cascade = a; } /** set up back button */ th_back ++= function(v) { @@ -261,7 +261,7 @@ } /** move down a line */ - const nextAction = function(a) { shift = lineshift; cascade = a; } + const nextAction = function(a) { shift = mwheelshift * lineheight; cascade = a; } /** set up next button */ th_next ++= function(v) { Added: branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/lib/widget/textarea.t =================================================================== --- branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/lib/widget/textarea.t (rev 0) +++ branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/lib/widget/textarea.t 2013-03-31 20:20:09 UTC (rev 4504) @@ -0,0 +1,94 @@ +<!-- Copyright 2012 - see COPYING for details [LGPL] --> + +<vexi xmlns:ui="vexi://ui" + xmlns="org.vexi.lib"> + + <role.focusable /> + <role.tooltipable /> + <text.contextmenu /> + <ui:box> + + thisbox.liveValuePut = true; + thisbox.th_scroll; + + thisbox.KeyPressed ++= static.keypressWrite; + thisbox.enabled ++= static.enableWrite; + thisbox.focused ++= static.focusWrite; + thisbox.value ++= static.valueRead; + thisbox.value ++= static.valueWrite; + thisbox.v_edit ++= static.v_editWrite; + + </ui:box> + + /** return text as value */ + static.valueRead = function() { return trapee.v_edit.text; } + + /** set text on value writes */ + static.valueWrite = function(v) { + if (!trapee.v_valueput) + trapee.v_edit.text = v; + return; + } + + /** pass on focus notification to editbox */ + static.enableWrite = function(v) { cascade = v; trapee.v_edit.enabled = trapee.enabled; } + + /** passon keypress to editbox */ + static.keypressWrite = function(v) { + cascade = v; + trapee.v_edit.KeyPressed = v; +// if (trapee.liveValuePut) { +// trapee.v_valueput = true; +// trapee.value = trapee.value; +// trapee.v_valueput = false; +// } + } + + /** set up editbox */ + static.v_editWrite = function(v) { + cascade = v; + trace("here "+v+", "+trapee.th_scroll); + v.multiline = true; + v.scroll = trapee.th_scroll; + } + + /** pass on focus notification to editbox */ + static.focusWrite = function(f) { + cascade = f; +// var focused = trapee.focused; +// trapee.v_edit.focused = focused; +// +// var cursor = trapee.v_cursor; +// var scroll = trapee.th_scroll; +// +// if (!focused) { +// if (!trapee.liveValuePut); +// trapee.value = trapee.value; +// } else if (focused and cursor!=null and scroll!=null) { +// /** syncs the view to be make sure the cursor is visible */ +// var sync = function(v) { +// cascade = v; +// // .-------------. edit/view - +// // | | | viewy +// // .-+-------------+-. - +// // | | | | viewport | viewheight +// // | | | | | +// // '-+-------------+-' - +// // | | +// // '-------------' +// if (scroll.viewy > v) +// scroll.viewy = v; +// else if (v + cursor.height + 6 > scroll.viewy + scroll.viewheight) +// scroll.viewy = v + 6 + cursor.height - scroll.viewheight; +// } +// // assign trap +// cursor.y ++= sync; +// // clean up trap +// trapee.focused ++= function(v) { +// cascade = v; +// if (!v) cursor.y --= sync; +// } +// } + } + +</vexi> Modified: branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/theme/classic/textarea.t =================================================================== --- branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/theme/classic/textarea.t 2013-03-26 17:41:17 UTC (rev 4503) +++ branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/theme/classic/textarea.t 2013-03-31 20:20:09 UTC (rev 4504) @@ -1,12 +1,14 @@ <!-- Copyright 2013 - see COPYING for details [LGPL] --> -<vexi xmlns:lib="org.vexi.lib.text" +<vexi xmlns:lib="org.vexi.lib.widget" xmlns="vexi.theme"> + <lib:textarea /> <bevel redirect=":$content" fill="white" form="down"> <scrollpane id="content" autohide="true" /> - th_scroll = $scroll; + trace("here"); + th_scroll = $content; </bevel> </vexi> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Own the Future-Intel(R) Level Up Game Demo Contest 2013 Rise to greatness in Intel's independent game demo contest. Compete for recognition, cash, and the chance to get your game on Steam. $5K grand prize plus 10 genre and skill prizes. Submit your demo by 6/6/13. http://altfarm.mediaplex.com/ad/ck/12124-176961-30367-2 _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn