Revision: 4506 http://sourceforge.net/p/vexi/code/4506 Author: clrg Date: 2013-04-07 01:24:30 +0000 (Sun, 07 Apr 2013) Log Message: ----------- WIP - milestone 1; smooth scrolling with large text
Modified Paths: -------------- branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/lib/text/edit.t 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-04-05 02:07:22 UTC (rev 4505) +++ branches/org.vexi-vexi.widgets_editrefactor/src_main/org/vexi/lib/text/edit.t 2013-04-07 01:24:30 UTC (rev 4506) @@ -1,41 +1,51 @@ <!-- Copyright 2013 - see COPYING for details [LGPL] --> -<vexi xmlns:ui="vexi://ui" xmlns:text="org.vexi.lib.text"> +<vexi xmlns:ui="vexi://ui" xmlns:lib="org.vexi.lib.text"> <ui:box layout="place" align="topleft"> thisbox.from_y; thisbox.fullheight; thisbox.multiline = true; - thisbox.v_text = ""; - var tip = false; - thisbox.width ++= function(v) { - cascade = v; - if (tip) return; - trace(v); - tip = true; - vexi.thread = function() { - while (tip) { - reflowText(); - tip = false; - vexi.thread.yield(); - } - } - } + // INTERNAL - thisbox.text ++= function(v) { - v_text = v==null?"":v; - reflowText(); - // do not put - return; + var v_text = ""; + + var line_count = 0; + const line_markers = []; + + const line_height = vexi.ui.font.height(font, fontsize, "dy"); + + + + const addLine = function(str, line_num) { + const line_y = line_height * line_num; + const b = new lib.line(); + b.text = str; + b.minheight = line_height; + b.x = 0; + b.y = line_y; + add(b); } - thisbox.from_y ++= function(v) { - cascade = v; - reflowText(); + const max = vexi.math.max; + const floor = vexi.math.floor; + const layoutText = function() { + clear(); + var cur = max(0, floor((from_y - line_height) / line_height)); + const to = from_y + height; + while ((to > cur * line_height) and (line_count > cur)) { + const n1 = line_markers[2 * cur]; + const n2 = line_markers[2 * cur + 1]; + addLine(v_text.substring(n1, n2)+" ", cur); + cur++; + } } + + + const NEWLINE = 0; const WHITESPACE = 1; const ALPHA_NUMERIC = 2; @@ -60,9 +70,7 @@ return NON_ALPHA_NUMERIC; } - const line_height = vexi.ui.font.height(font, fontsize, "dy"); - - thisbox.reflowText = function() { + const reflowText = function() { clear(); if (!multiline) { addLine(v_text); @@ -71,25 +79,18 @@ const from_y = thisbox.from_y; + line_count = 0; + var t = v_text; 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)) { - const b = new text.line(); - b.text = v; - b.minheight = line_height; - b.x = 0; - b.y = line_y; - add(b); - } + const addMarkers = function(n1, n2) { + line_markers[2 * line_count] = n1; + line_markers[2 * line_count + 1] = n2; line_count ++; first_word = true; } @@ -104,7 +105,7 @@ // NEWLINE immediately breaks // and resets everything to that point if (n_type == NEWLINE) { - addLine(t.substring(line_start, i)); + addMarkers(line_start, i); line_start = i+1; line_width = 0; word_width = 0; @@ -131,7 +132,7 @@ if (word_type != WHITESPACE) { if (line_width >= width) { - addLine(t.substring(line_start, word_end)+" "); + addMarkers(line_start, word_end); line_start = word_start; line_width = word_width; } @@ -146,11 +147,43 @@ } if (word_type != NEWLINE) { - addLine(t.substring(line_start, line_end)+" "); + addMarkers(line_start, v_text.length); } fullheight = (line_count+1) * line_height; + + layoutText(); } + var tip = false; + thisbox.width ++= function(v) { + cascade = v; + if (tip) return; + tip = true; + vexi.thread = function() { + while (tip) { + reflowText(); + tip = false; + vexi.thread.yield(); + } + } + } + + thisbox.text ++= function(v) { + v_text = v==null?"":v; + reflowText(); + // do not put + return; + } + + thisbox.text ++= function() { + return v_text; + } + + thisbox.from_y ++= function(v) { + cascade = v; + layoutText(); + } + </ui:box> </vexi> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Minimize network downtime and maximize team effectiveness. Reduce network management and security costs.Learn how to hire the most talented Cisco Certified professionals. Visit the Employer Resources Portal http://www.cisco.com/web/learning/employer_resources/index.html _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn