Skip to content

Commit b13f3dc

Browse files
authored
Improvements v12.8 (#90)
* fix css apply for text * fix css rules * refactor css engine apply
1 parent c2fcbcb commit b13f3dc

File tree

9 files changed

+157
-124
lines changed

9 files changed

+157
-124
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,10 @@ type
262262
UiEnd ## marks end track of a CSS Grid layout
263263
```
264264

265+
### CSS Grid Layout Examples
266+
267+
Example layouts using CSS Grid:
268+
- https://css-irl.info/solving-a-tricky-layout-problem/
269+
- https://apiumhub.com/tech-blog-barcelona/css-grid/
270+
271+

examples/hnbrowser.css

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Button {
33
background: rgb(246, 246, 239);
44
border-width: 5;
5-
border-color: #ebc39a;
5+
border-color: #000000;
66
border-radius: 10;
77
/* color: #000000; */
88
box-shadow: none;
@@ -14,15 +14,29 @@ Button:hover {
1414
}
1515

1616
#story {
17-
background: #f5c480;
18-
border-width: 5;
19-
border-color: rgba(95, 84, 0, 0.45);
20-
border-radius: 10;
21-
color: #bdc0a0;
17+
background: black;
18+
border-width: 3;
19+
border-color: rgba(57, 50, 1, 0.45);
20+
border-radius: 6;
21+
color: #ddd;
2222
background: rgb(50, 50, 47);
2323
height: 40;
2424
}
2525

26+
#story:hover {
27+
background: rgba(255, 170, 50, 0.57);
28+
box-shadow: 5px 2px 4px rgba(47, 0, 75, 0.119);
29+
}
30+
31+
/* .subtext, .subtext * {
32+
color: #888;
33+
} */
34+
35+
#scroll {
36+
background-color: black;
37+
}
38+
2639
#main {
27-
background: #141414;
40+
background-color: black;
41+
color: #ddd;
2842
}

examples/hnbrowser.nim

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ proc hover*(self: Main, kind: EventKind) {.slot.} =
4343

4444
proc draw*(self: Main) {.slot.} =
4545
withRootWidget(self):
46-
# with this:
47-
# fill css"#0000AA"
4846

4947
rectangle "outer":
5048
with this:
@@ -65,15 +63,12 @@ proc draw*(self: Main) {.slot.} =
6563
size 0.5'fr, 50'ux
6664
gridRow "top" // "items"
6765
gridColumn "left" // "right"
68-
proc clickLoad(self: Main,
69-
kind: EventKind,
70-
buttons: UiButtonView) {.slot.} =
71-
echo "Load clicked"
72-
if kind == Init and not self.loading:
66+
onSignal(doMouseClick) do(self: Main, kind: EventKind, buttons: UiButtonView):
67+
echo "Load clicked: ", kind
68+
if kind == Done and not self.loading:
7369
emit self.htmlLoad()
74-
self.loading = true
75-
refresh(self)
76-
this.connect(doMouseClick, self, clickLoad)
70+
self.loading = true
71+
refresh(self)
7772

7873
Text.new "text":
7974
with this:
@@ -105,7 +100,6 @@ proc draw*(self: Main) {.slot.} =
105100
offset 2'pp, 2'pp
106101
cornerRadius 7.0'ux
107102
size 96'pp, 90'pp
108-
# fill css"white"
109103

110104
Vertical.new "items":
111105
with this:
@@ -115,22 +109,17 @@ proc draw*(self: Main) {.slot.} =
115109
capture story:
116110
Button.new "story":
117111
with this:
118-
size 1'fr, max(ux(2*lh), cx"min-content")
119-
# size 1'fr, cx"min-content"
120-
# fill blueColor.lighten(0.2)
121-
# if this.children.len() > 0:
122-
# this.cxMin = this.children[0].cxMin
112+
size 1'fr, ux(2*lh)
123113
Text.new "text":
124114
with this:
125-
size 1'fr, max(ux(1.5*lh.float), cx"min-content")
115+
size 1'fr, ux(2*lh)
116+
# size 1'fr, max(ux(1.5*lh.float), cx"min-content")
126117
offset 10'ux, 0'ux
127118
foreground blackColor
128119
justify Left
129120
align Middle
130121
text({font: $story.link.title})
131-
132-
133-
printLayout(this, cmTerminal)
122+
# printLayout(this, cmTerminal)
134123

135124
var main = Main(name: "main")
136125
var frame = newAppFrame(main, size=(600'ui, 280'ui))

figuro.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version = "0.12.7"
1+
version = "0.12.8"
22
author = "Jaremy Creechley"
33
description = "UI Engine for Nim"
44
license = "MIT"

src/figuro/common/nodes/basiccss.nim

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type
2727
CssTheme* = ref object
2828
rules*: seq[CssBlock]
2929

30-
CssBlock* = ref object
30+
CssBlock* = object
3131
selectors*: seq[CssSelector]
3232
properties*: seq[CssProperty]
3333

@@ -38,29 +38,29 @@ type
3838
skPseudo
3939
skSelectorList
4040

41-
CssSelector* = ref object
41+
CssSelector* = object
4242
cssType*: string
4343
class*: string
4444
id*: string
4545
combinator*: CssSelectorKind
4646

47-
CssProperty* = ref object
47+
CssProperty* = object
4848
name*: string
4949
value*: CssValue
5050

51-
proc `==`*(a, b: CssSelector): bool =
52-
if a.isNil and b.isNil:
53-
return true
54-
if a.isNil or b.isNil:
55-
return false
56-
a[] == b[]
57-
58-
proc `==`*(a, b: CssProperty): bool =
59-
if a.isNil and b.isNil:
60-
return true
61-
if a.isNil or b.isNil:
62-
return false
63-
a[] == b[]
51+
# proc `==`*(a, b: CssSelector): bool =
52+
# if a.isNil and b.isNil:
53+
# return true
54+
# if a.isNil or b.isNil:
55+
# return false
56+
# a[] == b[]
57+
58+
# proc `==`*(a, b: CssProperty): bool =
59+
# if a.isNil and b.isNil:
60+
# return true
61+
# if a.isNil or b.isNil:
62+
# return false
63+
# a[] == b[]
6464

6565
proc `$`*(val: CssValue): string =
6666
match val:

src/figuro/common/nodes/uinodes.nim

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type
2727
events*: EventFlags
2828
signals*: EventFlags
2929

30-
Theme* = ref object
30+
Theme* = object
3131
font*: UiFont
3232
css*: CssTheme
3333

@@ -122,17 +122,10 @@ type
122122
font*: UiFont
123123
color*: Color = parseHtmlColor("black")
124124

125-
# proc `=destroy`*(obj: type(Figuro()[])) =
126-
# ## destroy
127-
# let objPtr = unsafeWeakRef(cast[Figuro](addr(obj)))
128-
# for child in obj.children:
129-
# assert objPtr == child.parent
130-
# child.parent.pt = nil
131-
132-
# proc `box=`*[F](fig: F, box: Box) =
133-
# fig.box = box
134-
# proc box*[F](fig: F): var Box =
135-
# fig.box
125+
# proc changed*(f: Figuro): Hash =
126+
# var h = Hash(0)
127+
# h = h !& hash tp.filePath
128+
# result = !$h
136129

137130
proc children*(fig: WeakRef[Figuro]): seq[Figuro] =
138131
fig[].children
@@ -267,3 +260,14 @@ proc printFiguros*(n: Figuro, depth = 0) =
267260
$n.zlevel
268261
for ci in n.children:
269262
printFiguros(ci, depth + 1)
263+
264+
proc refresh*(node: Figuro) {.slot.} =
265+
## Request that the node and it's children be redrawn
266+
# echo "refresh: ", node.name, " :: ", getStackTrace()
267+
if node == nil:
268+
return
269+
# app.requestedFrame.inc
270+
assert not node.frame.isNil
271+
node.frame[].redrawNodes.incl(node)
272+
when defined(figuroDebugRefresh):
273+
echo "REFRESH: ", getStackTrace()

src/figuro/ui/apisImpl.nim

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,11 @@ proc setInnerText*(
231231
) =
232232
## Set the text on an item.
233233
if hasInnerTextChanged(node, spans, hAlign, vAlign):
234-
trace "setText: ", nodeName = node.name
234+
trace "setInnertText: ", name = node.name, uid= node.uid
235235
node.textLayout = system.getTypeset(node.box, spans, hAlign, vAlign)
236236
let maxPos = node.textLayout.maxPosition
237237
node.cxMin = [csFixed(maxPos.w), csFixed(maxPos.h)]
238-
debug "innertText:", node= node.name, cxMin= node.cxMin
239-
refresh(node)
238+
refresh(node.parent[])
240239

241240

242241
## ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

src/figuro/ui/core.nim

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,16 @@ proc removeExtraChildren*(node: Figuro) =
104104
echo nd(), "Disable:setlen: ", node.getId, " diff: ", node.diffIndex
105105
node.children.setLen(node.diffIndex)
106106

107-
proc refresh*(node: Figuro) {.slot.} =
108-
## Request that the node and it's children be redrawn
109-
# echo "refresh: ", node.name, " :: ", getStackTrace()
110-
if node == nil:
111-
return
112-
# app.requestedFrame.inc
113-
assert not node.frame.isNil
114-
node.frame[].redrawNodes.incl(node)
115-
when defined(figuroDebugRefresh):
116-
echo "REFRESH: ", getStackTrace()
107+
# proc refresh*(node: Figuro) {.slot.} =
108+
# ## Request that the node and it's children be redrawn
109+
# # echo "refresh: ", node.name, " :: ", getStackTrace()
110+
# if node == nil:
111+
# return
112+
# # app.requestedFrame.inc
113+
# assert not node.frame.isNil
114+
# node.frame[].redrawNodes.incl(node)
115+
# when defined(figuroDebugRefresh):
116+
# echo "REFRESH: ", getStackTrace()
117117

118118
proc changed*(self: Figuro) {.slot.} =
119119
refresh(self)
@@ -248,8 +248,7 @@ proc newAppFrame*[T](root: T, size: (UiScalar, UiScalar), style = DecoratedResiz
248248
root.diffIndex = 0
249249
let frame = AppFrame(root: root)
250250
root.frame = frame.unsafeWeakRef()
251-
if frame.theme.isNil:
252-
frame.theme = Theme(font: defaultFont)
251+
frame.theme = Theme(font: defaultFont)
253252
frame.setSize(size)
254253
frame.windowStyle = style
255254
refresh(root)
@@ -296,7 +295,7 @@ proc preNode*[T: Figuro](kind: NodeKind, nid: string, node: var T, parent: Figur
296295
trace "preNode:create:", nd = nd(),
297296
name= node.name, widget= node.widgetName,
298297
new = fmt"{$node.getId}/{node.parent.getId()}", n= node.name, parent= parent.uid
299-
# refresh(node)
298+
refresh(node)
300299
elif not (parent.children[parent.diffIndex] of T):
301300
# mismatched types, replace node
302301
createNewNode(T, node)

0 commit comments

Comments
 (0)