Skip to content

Commit

Permalink
fix: some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
levovix0 committed Nov 4, 2024
1 parent e4ef13e commit aff6c66
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
5 changes: 5 additions & 0 deletions src/sigui/layouts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,13 @@ proc reposition(this: Layout) =
if not(child of InLayout) or not(child.InLayout.fillContainer[]):
h = max(h, child.get_h)
rows[^1].freeSpace -= child.get_w

if not this.wrapHugContent[]:
h = this.get_h

rows[^1].h = h


for x in rows.mitems:
x.spaceBetween =
if this.childs.len > 1: x.freeSpace / (x.childs.len - 1).float32
Expand Down
3 changes: 1 addition & 2 deletions src/sigui/textArea.nim
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,7 @@ method init*(this: TextArea) =
root.binding selectionEndX: positionOfCharacter(root.textObj{}.arrangement[], root.selectionEnd[])


root.cursorObj --- (let r = UiRect(); initIfNeeded(r); r.fillVertical root; r.UiObj):
w = 2
root.cursorObj --- (let r = UiRect(); initIfNeeded(r); r.fillVertical root; r.w[] = 2; r.UiObj):
x := root.cursorX[]

visibility = binding:
Expand Down
39 changes: 26 additions & 13 deletions src/sigui/uibase.nim
Original file line number Diff line number Diff line change
Expand Up @@ -415,39 +415,39 @@ proc pos*(anchor: Anchor, isY: bool, toObject: UiObj): float32 =
let p = case anchor.offsetFrom
of start:
if isY:
if anchor.obj.visibility == collapsed and anchor.obj.anchors.top.obj == nil and anchor.obj.anchors.bottom.obj != nil:
if anchor.obj.visibility[] == collapsed and anchor.obj.anchors.top.obj == nil and anchor.obj.anchors.bottom.obj != nil:
anchor.obj.h[] + anchor.offset
else:
anchor.offset
else:
if anchor.obj.visibility == collapsed and anchor.obj.anchors.left.obj == nil and anchor.obj.anchors.right.obj != nil:
if anchor.obj.visibility[] == collapsed and anchor.obj.anchors.left.obj == nil and anchor.obj.anchors.right.obj != nil:
anchor.obj.w[] + anchor.offset
else:
anchor.offset

of `end`:
if isY:
if anchor.obj.visibility == collapsed and anchor.obj.anchors.top.obj != nil and anchor.obj.anchors.bottom.obj == nil:
if anchor.obj.visibility[] == collapsed and anchor.obj.anchors.top.obj != nil and anchor.obj.anchors.bottom.obj == nil:
anchor.offset
else:
anchor.obj.h[] + anchor.offset
else:
if anchor.obj.visibility == collapsed and anchor.obj.anchors.left.obj != nil and anchor.obj.anchors.right.obj == nil:
if anchor.obj.visibility[] == collapsed and anchor.obj.anchors.left.obj != nil and anchor.obj.anchors.right.obj == nil:
anchor.offset
else:
anchor.obj.w[] + anchor.offset

of center:
if isY:
if anchor.obj.visibility == collapsed:
if anchor.obj.visibility[] == collapsed:
if anchor.obj.anchors.top.obj == nil and anchor.obj.anchors.bottom.obj != nil:
anchor.obj.h[] + anchor.offset
else:
anchor.offset
else:
anchor.obj.h[] / 2 + anchor.offset
else:
if anchor.obj.visibility == collapsed:
if anchor.obj.visibility[] == collapsed:
if anchor.obj.anchors.left.obj == nil and anchor.obj.anchors.right.obj != nil:
anchor.obj.w[] + anchor.offset
else:
Expand Down Expand Up @@ -635,6 +635,9 @@ method init*(obj: Uiobj) {.base.} =
proc initIfNeeded*(obj: Uiobj) =
if obj.initialized: return
init(obj)
if obj.parent != nil:
obj.recieve(ParentChanged(newParentInTree: obj.parent))
obj.parent.recieve(ChildAdded(child: obj))

#--- Anchors ---

Expand Down Expand Up @@ -697,8 +700,9 @@ method addChild*(parent: Uiobj, child: Uiobj) {.base.} =
let win = parent.parentUiWindow
if win != nil:
child.recieve(AttachedToWindow(window: win))
child.recieve(ParentChanged(newParentInTree: parent))
parent.recieve(ChildAdded(child: child))
if child.initialized:
child.recieve(ParentChanged(newParentInTree: parent))
parent.recieve(ChildAdded(child: child))


method addChangableChildUntyped*(parent: Uiobj, child: Uiobj): CustomProperty[Uiobj] {.base.} =
Expand All @@ -715,8 +719,9 @@ method addChangableChildUntyped*(parent: Uiobj, child: Uiobj): CustomProperty[Ui
let win = parent.parentUiWindow
if win != nil:
child.recieve(AttachedToWindow(window: win))
child.recieve(ParentChanged(newParentInTree: parent))
parent.recieve(ChildAdded(child: child))
if child.initialized:
child.recieve(ParentChanged(newParentInTree: parent))
parent.recieve(ChildAdded(child: child))

let i = parent.childs.high
result = CustomProperty[Uiobj](
Expand All @@ -726,8 +731,9 @@ method addChangableChildUntyped*(parent: Uiobj, child: Uiobj): CustomProperty[Ui
deteach parent.childs[i]
parent.childs[i] = v
v.parent = parent
v.recieve(ParentChanged(newParentInTree: parent))
parent.recieve(ChildAdded(child: v))
if v.initialized:
v.recieve(ParentChanged(newParentInTree: parent))
parent.recieve(ChildAdded(child: v))
),
)

Expand Down Expand Up @@ -1728,7 +1734,14 @@ macro makeLayout*(obj: Uiobj, body: untyped) =
call ident($name & "="):
ident "this"
val
Else: asgn(name, val)
elifBranch:
call bindSym"compiles":
asgn(name, val)
asgn(name, val)
Else:
call ident"[]=":
dotExpr(ident "this", name)
val

of ForStmt():
forStmt:
Expand Down

0 comments on commit aff6c66

Please sign in to comment.