@@ -39,6 +39,17 @@ import qualified Potato.Data.Text.Zipper as TZ
39
39
import qualified Text.Pretty.Simple as Pretty
40
40
import qualified Data.Text.Lazy as LT
41
41
42
+ data BoxTextHandler = BoxTextHandler {
43
+ -- TODO Delete this
44
+ _boxTextHandler_isActive :: Bool
45
+
46
+ , _boxTextHandler_state :: TextInputState
47
+ -- TODO you can prob delete this now, we don't persist state between sub handlers in this case
48
+ , _boxTextHandler_prevHandler :: SomePotatoHandler
49
+ , _boxTextHandler_undoFirst :: Bool
50
+
51
+ , _boxTextHandler_commitOnMouseUp :: Bool
52
+ }
42
53
43
54
getSBox :: CanvasSelection -> (REltId , SBox )
44
55
getSBox selection = case superOwl_toSElt_hack sowl of
@@ -98,18 +109,6 @@ makeTextInputState = makeOwlItemTextInputState boxTextImpl
98
109
inputBoxText :: TextInputState -> SuperOwl -> KeyboardKey -> (TextInputState , Maybe Llama )
99
110
inputBoxText tais sowl kk = inputOwlItem boxTextImpl tais sowl kk
100
111
101
- data BoxTextHandler = BoxTextHandler {
102
- -- TODO Delete this
103
- _boxTextHandler_isActive :: Bool
104
-
105
- , _boxTextHandler_state :: TextInputState
106
- -- TODO you can prob delete this now, we don't persist state between sub handlers in this case
107
- , _boxTextHandler_prevHandler :: SomePotatoHandler
108
- , _boxTextHandler_undoFirst :: Bool
109
-
110
- , _boxTextHandler_commitOnMouseUp :: Bool
111
- }
112
-
113
112
makeBoxTextHandler :: Bool -> SomePotatoHandler -> CanvasSelection -> RelMouseDrag -> BoxTextHandler
114
113
makeBoxTextHandler commit prev selection rmd = BoxTextHandler {
115
114
_boxTextHandler_isActive = False
@@ -250,78 +249,48 @@ lBox_to_boxLabelBox lbx = r where
250
249
width = max 0 (w - 2 )
251
250
r = LBox (V2 (x+ 1 ) y) (V2 width 1 )
252
251
252
+ makeBoxLableController :: Text -> Text -> Controller
253
+ makeBoxLableController orig new = CTagBoxLabelText :=> (Identity $ CMaybeText (DeltaMaybeText (if orig == " " then Nothing else Just orig, if new == " " then Nothing else Just new)))
253
254
254
-
255
+ boxLabelImpl :: TextImpl SBox
256
+ boxLabelImpl = TextImpl {
257
+ _textImpl_mustGetOwlItem = getSBox
258
+ , _textImpl_owlItemText = fromMaybe " " . _sBoxTitle_title . _sBox_title
259
+ , _textImpl_owlItemBox = canonicalLBox_from_lBox . lBox_to_boxLabelBox . _sBox_box
260
+ , _textImpl_owlItemAlignment = _sBoxTitle_align . _sBox_title
261
+ , _textImpl_inputOwlItemZipper = inputSingleLineZipper
262
+ , _textImpl_makeController = makeBoxLableController
263
+ }
255
264
256
265
updateBoxLabelInputStateWithSBox :: SBox -> TextInputState -> TextInputState
257
- updateBoxLabelInputStateWithSBox sbox btis = r where
258
- alignment = convertTextAlignToTextZipperTextAlignment . _sBoxTitle_align . _sBox_title $ sbox
259
- newBox = lBox_to_boxLabelBox $ _sBox_box sbox
260
- width = maxBound :: Int -- box label text always overflows
261
- r = btis {
262
- _textInputState_box = newBox
263
- , _textInputState_displayLines = TZ. displayLinesWithAlignment alignment width () () (_textInputState_zipper btis)
264
- }
266
+ updateBoxLabelInputStateWithSBox = updateTextInputStateWithOwlItem boxLabelImpl
265
267
266
268
makeBoxLabelInputState :: REltId -> SBox -> RelMouseDrag -> TextInputState
267
- makeBoxLabelInputState rid sbox rmd = r where
268
- mogtext = _sBoxTitle_title . _sBox_title $ sbox
269
- ogtz = TZ. fromText (fromMaybe " " mogtext)
270
- r' = TextInputState {
271
- _textInputState_rid = rid
272
- , _textInputState_original = mogtext
273
- , _textInputState_zipper = ogtz
274
-
275
- -- these fields get updated in next pass
276
- , _textInputState_box = error " expected to be filled"
277
- , _textInputState_displayLines = error " expected to be filled"
278
- }
279
- r'' = updateBoxLabelInputStateWithSBox sbox r'
280
- r = mouseText r'' rmd
269
+ makeBoxLabelInputState = makeOwlItemTextInputState boxLabelImpl
281
270
282
271
makeBoxLabelHandler :: SomePotatoHandler -> CanvasSelection -> RelMouseDrag -> BoxLabelHandler
283
272
makeBoxLabelHandler prev selection rmd = BoxLabelHandler {
284
273
_boxLabelHandler_active = False
285
- , _boxLabelHandler_state = uncurry makeBoxLabelInputState (getSBox selection) rmd
274
+ , _boxLabelHandler_state = uncurry makeBoxLabelInputState (_textImpl_mustGetOwlItem boxLabelImpl selection) rmd
286
275
, _boxLabelHandler_prevHandler = prev
287
276
, _boxLabelHandler_undoFirst = False
288
277
}
289
278
290
279
291
280
-- UNTESTED
292
281
updateBoxLabelHandlerState :: Bool -> CanvasSelection -> BoxLabelHandler -> BoxLabelHandler
293
- updateBoxLabelHandlerState reset selection tah@ BoxLabelHandler {.. } = assert tzIsCorrect r where
294
- (_, sbox) = getSBox selection
295
-
296
- mNewText = _sBoxTitle_title . _sBox_title $ sbox
297
-
298
- recomputetz = TZ. fromText (fromMaybe " " mNewText)
299
- oldtz = _textInputState_zipper _boxLabelHandler_state
300
- -- NOTE that recomputetz won't have the same cursor position
301
- -- TODO delete this check, not very meaningful, but good for development purposes I guess
302
- tzIsCorrect = TZ. value oldtz == TZ. value recomputetz
303
- nextstate = updateBoxLabelInputStateWithSBox sbox _boxLabelHandler_state
304
-
282
+ updateBoxLabelHandlerState reset selection tah@ BoxLabelHandler {.. } = r where
283
+ nextstate = updateOwlItemTextInputState boxLabelImpl reset selection _boxLabelHandler_state
305
284
r = tah {
306
- _boxLabelHandler_state = if reset
307
- then nextstate {
308
- _textInputState_original = mNewText
309
- }
310
- else nextstate
285
+ _boxLabelHandler_state = nextstate
311
286
, _boxLabelHandler_undoFirst = if reset
312
287
then False
313
288
else _boxLabelHandler_undoFirst
314
289
}
315
290
316
291
317
292
inputBoxLabel :: TextInputState -> SuperOwl -> KeyboardKey -> (TextInputState , Maybe Llama )
318
- inputBoxLabel tais sowl kk = (newtais, mop) where
319
- (changed, newtais) = inputSingleLineZipper tais kk
320
- newtext = TZ. value (_textInputState_zipper newtais)
321
- controller = CTagBoxLabelText :=> (Identity $ CMaybeText (DeltaMaybeText (_textInputState_original tais, if newtext == " " then Nothing else Just newtext)))
322
- mop = if changed
323
- then Just $ makePFCLlama . OwlPFCManipulate $ IM. fromList [(_superOwl_id sowl,controller)]
324
- else Nothing
293
+ inputBoxLabel tais sowl kk = inputOwlItem boxLabelImpl tais sowl kk
325
294
326
295
327
296
-- | just a helper for pHandleMouse
0 commit comments