Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widget in alert not found by key #324

Open
o-schneider opened this issue Sep 19, 2024 · 0 comments
Open

Widget in alert not found by key #324

o-schneider opened this issue Sep 19, 2024 · 0 comments

Comments

@o-schneider
Copy link

Hi!

First of all, as it is my first message here, thanks for such a nice GUI library that respects Haskell! Having a blast using it.

To the issue I found then. I tried to send a message to a widget that is inside an alert and it doesn't work. When the message is sent, there's a log stating that Key WidgetKey "foo" not found for Message. Moving the message target outside the alert and in a custom hidden widget is working properly.

Here is a little demo of the issue. The vscroll within the "custom" fake dialog is properly reset on close, while the vscroll within the alert is not reset and not found (the error message quoted earlier is printed in the console).

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}

module Main where

import Control.Lens
import Data.Maybe
import Data.Text
import Monomer
import TextShow

import qualified Monomer.Lens as L

data AppModel = AppModel
  { _showAlert :: Bool
  , _showCustom :: Bool
  , _text :: Text
  }
  deriving (Eq, Show)

data AppEvent
  = Init
  | ShowAlert
  | ShowCustom
  | CloseAlert
  | CloseCustom
  deriving (Eq, Show)

makeLenses 'AppModel

buildUI ::
  WidgetEnv AppModel AppEvent ->
  AppModel ->
  WidgetNode AppModel AppEvent
buildUI wenv model = widgetTree
 where
  alertWithScroll =
    alert
      CloseAlert
      (vscroll (textArea_ text [readOnly] `styleBasic` [maxHeight 200]) `nodeKey` "alertScroll")

  customContent =
    box
      ( vstack
          [ box (vscroll (textArea_ text [readOnly]) `nodeKey` "customScroll") `styleBasic` [maxHeight 200]
          , button "close" CloseCustom
          ]
      )
      `styleBasic` [bgColor darkGray]

  widgetTree =
    zstack
      [ box $
          vstack
            [ button "Open Alert" ShowAlert
            , button "Open Custom" ShowCustom
            ]
      , alertWithScroll `nodeVisible` (model ^. showAlert)
      , customContent `nodeVisible` (model ^. showCustom)
      ]
      `styleBasic` [padding 10]

handleEvent ::
  WidgetEnv AppModel AppEvent ->
  WidgetNode AppModel AppEvent ->
  AppModel ->
  AppEvent ->
  [AppEventResponse AppModel AppEvent]
handleEvent wenv node model evt = case evt of
  Init -> []
  ShowAlert -> [Model $ model & showAlert .~ True]
  ShowCustom -> [Model $ model & showCustom .~ True]
  CloseAlert ->
    [ Model $ model & showAlert .~ False
    , Message "alertScroll" ScrollReset
    ]
  CloseCustom ->
    [ Model $ model & showCustom .~ False
    , Message "customScroll" ScrollReset
    ]

main :: IO ()
main = do
  startApp model handleEvent buildUI config
 where
  config =
    [ appWindowTitle "Alert NodeKey"
    , appWindowIcon "./assets/images/icon.png"
    , appTheme darkTheme
    , appFontDef "Regular" "./assets/fonts/Roboto-Regular.ttf"
    , appInitEvent Init
    ]
  model = AppModel False False longText

longText :: Text
longText =
  "Curabitur ut neque ac ligula tristique commodo eget eget nulla.\n\
  \Integer mattis nisi sed venenatis dictum.\n\
  \Praesent et sapien quis lorem lobortis iaculis lobortis sit amet enim.\n\
  \Donec porta libero in efficitur lacinia.\n\
  \Donec non nisl congue, ultrices lorem faucibus, feugiat augue.\n\
  \Proin in purus sed orci convallis pharetra.\n\
  \Suspendisse cursus nisi sed risus pharetra semper.\n\
  \Pellentesque nec elit at urna varius rutrum eu nec felis.\n\
  \Curabitur tincidunt ex tempus massa viverra pulvinar.\n\
  \Suspendisse sollicitudin nunc vitae velit mollis feugiat.\n\
  \Donec sit amet nisi a lorem laoreet consectetur vel et lorem.\n\
  \Fusce et tellus efficitur, tempor velit non, accumsan nisi.\n\
  \Nunc tincidunt magna a dolor venenatis hendrerit.\n\
  \Nunc id risus eu nisi consectetur suscipit.\n\
  \Suspendisse eu lectus eget risus scelerisque dignissim ut quis leo.\n\
  \Cras lacinia est sed arcu placerat, non mattis augue ultrices.\n\
  \Duis dapibus urna nec massa faucibus, at maximus augue laoreet.\n\
  \Morbi et nibh molestie mauris mattis efficitur sit amet id metus.\n\
  \Sed id lectus scelerisque, vehicula mauris eget, dapibus sem.\n\
  \Nam vel leo aliquet nibh faucibus ornare."

Am I missing something or is this a bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant