Skip to content

Commit 70dd8cd

Browse files
committed
Merge branch 'master' into globals
2 parents 5e0973f + 6eaedd1 commit 70dd8cd

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

nimx/formatted_text.nim

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -665,17 +665,24 @@ void compose()
665665
""", false, "mediump")
666666

667667
type ForEachLineAttributeCallback = proc(gfx: GraphicsContext, t: FormattedText, p: var Point, curLine, endIndex: int, str: string) {.nimcall.}
668-
proc forEachLineAttribute(gfx: GraphicsContext, origP: Point, t: FormattedText, cb: ForEachLineAttributeCallback) =
668+
proc forEachLineAttribute(gfx: GraphicsContext, inRect: Rect, origP: Point, t: FormattedText, cb: ForEachLineAttributeCallback) =
669669
template fontCtx: untyped = gfx.fontCtx
670670
template gl: untyped = gfx.gl
671671
var p = origP
672672
let numLines = t.lines.len
673673
var curLine = 0
674674
let top = topOffset(fontCtx, gl, t) + origP.y
675+
let inRectValid = (inRect.y + inRect.height) > 0.01
675676

676677
while curLine < numLines:
677678
p.x = origP.x + lineLeft(fontCtx, gl, t, curLine)
678679
p.y = t.lines[curLine].top + t.lines[curLine].baseline + top
680+
if inRectValid:
681+
if p.y < inRect.y:
682+
curLine.inc
683+
continue
684+
elif p.y > inRect.height:
685+
break
679686

680687
var lastCurAttrIndex: int
681688
var lastAttrStartIndex: int
@@ -741,9 +748,9 @@ proc forEachLineAttribute(gfx: GraphicsContext, origP: Point, t: FormattedText,
741748
curLine.inc
742749

743750

744-
proc drawShadow(gfx: GraphicsContext, origP: Point, t: FormattedText) =
751+
proc drawShadow(gfx: GraphicsContext, inRect: Rect, origP: Point, t: FormattedText) =
745752
# TODO: Optimize heavily
746-
forEachLineAttribute(gfx, origP, t) do(gfx: GraphicsContext, t: FormattedText, p: var Point, curLine, curAttrIndex: int, str: string):
753+
forEachLineAttribute(gfx, inRect, origP, t) do(gfx: GraphicsContext, t: FormattedText, p: var Point, curLine, curAttrIndex: int, str: string):
747754
template gl: untyped = gfx.gl
748755
gfx.fillColor = t.mAttributes[curAttrIndex].shadowColor
749756
let font = t.mAttributes[curAttrIndex].font
@@ -784,9 +791,9 @@ proc drawShadow(gfx: GraphicsContext, origP: Point, t: FormattedText) =
784791
font.baseline = oldBaseline
785792
p.x += pp.x - ppp.x
786793

787-
proc drawStroke(gfx: GraphicsContext, origP: Point, t: FormattedText) =
794+
proc drawStroke(gfx: GraphicsContext, inRect: Rect, origP: Point, t: FormattedText) =
788795
# TODO: Optimize heavily
789-
forEachLineAttribute(gfx, origP, t) do(gfx: GraphicsContext, t: FormattedText, p: var Point, curLine, curAttrIndex: int, str: string):
796+
forEachLineAttribute(gfx, inRect, origP, t) do(gfx: GraphicsContext, t: FormattedText, p: var Point, curLine, curAttrIndex: int, str: string):
790797
const magicStrokeMaxSizeCoof = 0.46
791798
let font = t.mAttributes[curAttrIndex].font
792799

@@ -828,16 +835,16 @@ proc drawStroke(gfx: GraphicsContext, origP: Point, t: FormattedText) =
828835
# Dirty hack to advance x position. Should be optimized, of course.
829836
gfx.drawText(font, p, str)
830837

831-
proc drawText*(gfx: GraphicsContext, origP: Point, t: FormattedText) =
838+
proc drawText*(gfx: GraphicsContext, origP: Point, t: FormattedText, inRect: Rect = zeroRect) =
832839
template fontCtx: untyped = gfx.fontCtx
833840
template gl: untyped = gfx.gl
834841
updateCacheIfNeeded(fontCtx, gl, t)
835842

836843
if t.overrideColor.a == 0:
837-
if t.shadowAttrs.len > 0: gfx.drawShadow(origP, t)
838-
if t.strokeAttrs.len > 0: gfx.drawStroke(origP, t)
844+
if t.shadowAttrs.len > 0: gfx.drawShadow(inRect, origP, t)
845+
if t.strokeAttrs.len > 0: gfx.drawStroke(inRect, origP, t)
839846

840-
forEachLineAttribute(gfx, origP, t) do(gfx: GraphicsContext, t: FormattedText, p: var Point, curLine, curAttrIndex: int, str: string):
847+
forEachLineAttribute(gfx, inRect, origP, t) do(gfx: GraphicsContext, t: FormattedText, p: var Point, curLine, curAttrIndex: int, str: string):
841848
let font = t.mAttributes[curAttrIndex].font
842849
let oldBaseline = font.baseline
843850
font.baseline = bAlphabetic

nimx/scroll_bar.nim

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@ type ScrollBar* = ref object of Slider
1010
# document is 0.5.
1111
trackingPos: Coord # Position of mouse coordinate (x or y depending on orientation) within knob
1212

13+
const minKnobSize = 0.05
1314
method init*(s: ScrollBar, gfx: GraphicsContext, r: Rect) =
1415
procCall s.Slider.init(gfx, r)
1516
s.mKnobSize = 0.2
1617

1718
proc knobRect(s: ScrollBar): Rect =
1819
result = s.bounds
1920
if s.isHorizontal:
20-
result.size.width *= s.mKnobSize
21+
result.size.width *= max(s.mKnobSize, minKnobSize)
2122
result.origin.x = max((s.bounds.width - result.width) * s.value, 3)
2223
if result.maxX > s.bounds.width - 3:
2324
result.size.width = s.bounds.width - result.x - 3
2425
result = inset(result, 0, 2)
2526
else:
26-
result.size.height *= s.mKnobSize
27+
result.size.height *= max(s.mKnobSize, minKnobSize)
2728
result.origin.y = max((s.bounds.height - result.height) * s.value, 3)
2829
if result.maxY > s.bounds.height - 3:
2930
result.size.height = s.bounds.height - result.y - 3

nimx/text_field.nim

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,15 @@ proc drawSelection(t: TextField) {.inline.} =
262262
r.size.width = endOff
263263
gfx.drawRect(r)
264264

265+
#todo: replace by generic visibleRect which should be implemented in future
266+
proc visibleRect(t: TextField): Rect =
267+
let wndRect = t.convertRectToWindow(t.bounds)
268+
let wndBounds = t.window.bounds
269+
270+
result.origin.y = if wndRect.y < 0.0: abs(wndRect.y) else: 0.0
271+
result.size.width = t.bounds.width
272+
result.size.height = min(t.bounds.height, wndBounds.height) + result.y - max(wndRect.y, 0.0)
273+
265274
method draw*(t: TextField, r: Rect) =
266275
procCall t.View.draw(r)
267276

@@ -284,7 +293,11 @@ method draw*(t: TextField, r: Rect) =
284293
t.mText.overrideColor = whiteColor()
285294
else:
286295
t.mText.overrideColor.a = 0
287-
gfx.drawText(pt, t.mText)
296+
297+
if t.bounds.height > t.window.bounds.height:
298+
gfx.drawText(pt, t.mText, t.visibleRect())
299+
else:
300+
gfx.drawText(pt, t.mText)
288301

289302
if t.isEditing:
290303
if t.hasBezel:

0 commit comments

Comments
 (0)