Skip to content

Commit 0727f78

Browse files
committed
Update default WinUIBackend slider step, add slider to ControlsExample
1 parent baf48b3 commit 0727f78

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

Examples/Sources/ControlsExample/ControlsApp.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class ControlsState: Observable {
99
@Observed var count = 0
1010
@Observed var exampleButtonState = false
1111
@Observed var exampleSwitchState = false
12+
@Observed var sliderValue = 5.0
1213
}
1314

1415
@main
@@ -43,6 +44,13 @@ struct ControlsApp: App {
4344
.toggleStyle(.switch)
4445
Text("Currently enabled: \(state.exampleSwitchState)")
4546
}
47+
48+
VStack {
49+
Text("Slider")
50+
Slider(state.$sliderValue, minimum: 0, maximum: 10)
51+
.frame(maxWidth: 200)
52+
Text("Value: \(String(format: "%.02f", state.sliderValue))")
53+
}
4654
}
4755
}
4856
}

Sources/WinUIBackend/WinUIBackend.swift

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ public struct WinUIBackend: AppBackend {
409409

410410
public func createTextView() -> Widget {
411411
let textBlock = TextBlock()
412-
textBlock.textWrapping = __x_ABI_CMicrosoft_CUI_CXaml_CTextWrapping_Wrap
412+
textBlock.textWrapping = .wrap
413413
return textBlock
414414
}
415415

@@ -452,9 +452,8 @@ public struct WinUIBackend: AppBackend {
452452
public func createScrollContainer(for child: Widget) -> Widget {
453453
let scrollViewer = WinUI.ScrollViewer()
454454
scrollViewer.content = child
455-
child.horizontalAlignment =
456-
__x_ABI_CMicrosoft_CUI_CXaml_CHorizontalAlignment_Left
457-
child.verticalAlignment = __x_ABI_CMicrosoft_CUI_CXaml_CVerticalAlignment_Top
455+
child.horizontalAlignment = .left
456+
child.verticalAlignment = .top
458457
return scrollViewer
459458
}
460459

@@ -466,24 +465,12 @@ public struct WinUIBackend: AppBackend {
466465
let scrollViewer = scrollView as! WinUI.ScrollViewer
467466

468467
scrollViewer.isHorizontalRailEnabled = hasHorizontalScrollBar
469-
scrollViewer.horizontalScrollMode =
470-
hasHorizontalScrollBar
471-
? __x_ABI_CMicrosoft_CUI_CXaml_CControls_CScrollMode_Enabled
472-
: __x_ABI_CMicrosoft_CUI_CXaml_CControls_CScrollMode_Disabled
473-
scrollViewer.horizontalScrollBarVisibility =
474-
hasHorizontalScrollBar
475-
? __x_ABI_CMicrosoft_CUI_CXaml_CControls_CScrollBarVisibility_Visible
476-
: __x_ABI_CMicrosoft_CUI_CXaml_CControls_CScrollBarVisibility_Hidden
468+
scrollViewer.horizontalScrollMode = hasHorizontalScrollBar ? .enabled : .disabled
469+
scrollViewer.horizontalScrollBarVisibility = hasHorizontalScrollBar ? .visible : .hidden
477470

478471
scrollViewer.isVerticalRailEnabled = hasVerticalScrollBar
479-
scrollViewer.verticalScrollMode =
480-
hasVerticalScrollBar
481-
? __x_ABI_CMicrosoft_CUI_CXaml_CControls_CScrollMode_Enabled
482-
: __x_ABI_CMicrosoft_CUI_CXaml_CControls_CScrollMode_Disabled
483-
scrollViewer.verticalScrollBarVisibility =
484-
hasVerticalScrollBar
485-
? __x_ABI_CMicrosoft_CUI_CXaml_CControls_CScrollBarVisibility_Visible
486-
: __x_ABI_CMicrosoft_CUI_CXaml_CControls_CScrollBarVisibility_Hidden
472+
scrollViewer.verticalScrollMode = hasVerticalScrollBar ? .enabled : .disabled
473+
scrollViewer.verticalScrollBarVisibility = hasVerticalScrollBar ? .visible : .hidden
487474
}
488475

489476
public func createSlider() -> Widget {
@@ -495,6 +482,7 @@ public struct WinUIBackend: AppBackend {
495482
internalState.sliderChangeActions[ObjectIdentifier(slider)]?(
496483
Double(event?.newValue ?? 0))
497484
}
485+
slider.stepFrequency = 0.01
498486
return slider
499487
}
500488

@@ -610,7 +598,7 @@ public struct WinUIBackend: AppBackend {
610598
return
611599
}
612600

613-
if event?.key == __x_ABI_CWindows_CSystem_CVirtualKey_Enter {
601+
if event?.key == .enter {
614602
internalState.textFieldSubmitActions[ObjectIdentifier(textField)]?()
615603
}
616604
}
@@ -674,7 +662,7 @@ public struct WinUIBackend: AppBackend {
674662
splitView.pane = leadingChild
675663
splitView.content = trailingChild
676664
splitView.isPaneOpen = true
677-
splitView.displayMode = __x_ABI_CMicrosoft_CUI_CXaml_CControls_CSplitViewDisplayMode_Inline
665+
splitView.displayMode = .inline
678666
return splitView
679667
}
680668

0 commit comments

Comments
 (0)