-
Notifications
You must be signed in to change notification settings - Fork 192
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
Fix widgets to behave like real elements #1475
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mainly not so sure I really wanna go with initialize and allocate :)
# turn (via handle_block above) will do the widget class's initialize. | ||
widget_instance = klass.allocate | ||
widget_instance.original_args = args | ||
widget_instance.actual_initialize(@__app__, @__app__.current_slot, container_args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I'm too happy with this magic of calling initialize
/allocate
ourselves - how do you feel about breaking compatibility and calling this method initialize_widget
instead or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or just require calling super... one of the 2. I dunno, seems like a little breaking change but one worth making imo - don't wanna dabble with initialize and allocate tbh :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So calling initialize_widget
would be the path (super
'ing doesn't really work well with how we have UIElement
set up). It would completely break anything using widgets, though, which seems like a bummer.
If I can suss out a way to give a more direct warning about the situation, I'd be happier about breaking compatibility. Let me see what I can find.
|
||
class << self | ||
attr_accessor :app | ||
def handle_block(*_) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just one thing, do we have redrawing etc. correctly setup for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you mean? Because of where this is called it wires into the startup sequence correctly, and after that it's just a slot so everything's happy.
class Widget | ||
include Common::Inspect | ||
|
||
class Widget < Shoes::Flow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we inherit from flow and not Slot? Cause flow is the default, makes sense, just checking though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the behavior on the old Widgets, and they acted like a Flow.
Closing this in favor #1476 |
Fixes #641
This PR changes
Widget
to behave essentially as aFlow
so it gets all the standard dimensions and styling it wasn't obeying before.This has a big challenge, though, as the contract for
Widget
derived classes in older Shoes didn't for callingsuper
from#initialize
. We must runUIElement#initialize
(or an equivalent) to get everything wired up, but we also need to run the user-definedinitialize
so the user's code runs.Ruby's flexibility to the rescue! ✨ We can take the odd step of actually skipping
new
calls for the widgets and justallocate
andinitialize
(in the order and timing we want, along with our base initialization) directly. 😱 Never thought I'd find a use for that bit of trivia, but here we are!Other tidbits:
Shoes::Swt::Flow
)Been using this app, in addition to the two samples with widgets (
samples/simple_menu.rb
andsamples/simple_guess_game.rb
):