-
Notifications
You must be signed in to change notification settings - Fork 19
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
Cleaning C side of Shoes #333
Comments
When you get a pile of C code handed to you to fix , you do not make it pass your style first before looking at it. _why liked opening '{' on separate lines. I prefer them at the end of the expression so I try to keep that _why standard. but nobody is consistent. I prefer putting {} around slngles line blocks in an if () { } when there is an else. I like tabs to be four spaces or two when the code is dense. Some folks actually indent to 5. Where did that come from? Ruby source likes 8 to a tab. Old battles, no winners. Leave it alone.
please send links to what should be done.
structs are local to file they are defined and lexically visible after declaration - not for whole file. That's just C. ruby private if you want think that way although it's more subtle. Perfectly legal, practical and doesn't pollute the larger C name space - use extern for that. |
The Obj-C style guides are are good looking tor documentation. Try writing code - unless you use xcode editor. Very confining an is anybody really going to care? |
_why has been long gone, abandoning ship. The thing is not even about who's coding style it is... the problem is inconsistency. It's messy. We could enforce YOUR preferences. It would be fine with me. AStyle is vim compatible.
A bit ahead. I had tagged this issue for 3.3.4 to have more time to work on it. We still haven't shipped 3.3.3. :)
What you write does make sense. So if it is not part of the whole thing and doesn't belong to the top where the declarations are, wouldn't it belong to its own module? For example, I was thinking to add a GtkSwitch to Shoes — should it go in Shoes internal has a steep learning curve despite that the concept is actually rather simple.
I'd say most people on MacOS X would use XCode. I apparently also use Xcode. haha
Shoes is a mess. So every bit helps. Astyle is a tool already doing it for all platforms Shoes is available on. This thing can be automated anyway. Your coding style preferences. |
You need Little bit's of code in all of the above because of the way C .h file and macros work. Other wise you'd have one giant file. When @passenger94 cleaned up the gtk3 converision. he took the route of creating many new shoes/native/gtk/ files
Shoes -> layer of independent C (ruby.c, canvas.c, primarily, app and world for global things and startup) -> 3 platform GUI implementations. However those 3 (now two) bleed across all layers because C has limitations is abstraction - supposedly solved by C++ and then later by java to clean up that mess which has grown into (insert your noun). Remember, Ruby also has include files and macro we need to mix in, It's a lot to learn. I don't think anyone here understands it all, myself included. |
Yes, exactly my point. Adding simple things involve several files.
It's not necessary. It should be possible to segment code that will be compiled into object files (.o) and the linker will resolve references.
Words of wisdom. |
We've add three widgets (svg, restored the vidoe, and plot). Figuring out where to put things was not particularly difficult - the compiler tells what you what you didn't do correctly. Minimal effort compared to writing the code to do it what ever it does. (cross platform --new widgets need a Cocoa implementation too). The internals of Shoes 4 is not a quick learn either and it's best practices. There hasen't been a swarm of new contributers to their efforts either. Why? Perhaps there is a limited number of people who dig deep and learn complex things? Are they writing code for their phones/tablets or cloud applications and they don't want to deal with ancient languages like C where their skills are really challenged because C doesn't work the way they are expecting. IMHO, the money, glory, fame and fortune are with iOS and Android, java and the 'cloud' - all deep dives. |
Because they aren't simple in the next layer down. Have you ever replace a garbage disposal in your sink? Looks easy. It almost is, but only after you learn some things by failing |
We don't have to strive to be Shoes4. Can't hurt to be inspired by them either. Have faith in me. This is not the first time I suggest things for Shoes that has benefited Shoes. :) I'm pretty sure I can present to you some proof of concept. |
Proof-of-concept you say? I managed to isolate slider and move it to Canvas related modifications:
Ruby related modifications:
Add shoes/video/video.c will not need to define
#include "shoes/ruby.h"
#include "shoes/canvas.h"
#include "shoes/app.h"
#include "shoes/internal.h"
#include "shoes/world.h"
#include "shoes/native.h"
#ifndef SLIDER_H
#define SLIDER_H
/* extern variables necessary to communicate with other parts of Shoes */
extern VALUE cShoes, cApp, cTypes, cCanvas, cWidget;
extern shoes_app _shoes_app;
/* Should be automatically available but ruby.c is not sharing enough information */
extern VALUE shoes_control_change(int argc, VALUE *argv, VALUE self);
/* each widget should have its own init function */
void shoes_slider_init();
// ruby
VALUE shoes_slider_draw(VALUE self, VALUE c, VALUE actual);
VALUE shoes_slider_get_fraction(VALUE self);
VALUE shoes_slider_set_fraction(VALUE self, VALUE _perc);
// canvas
VALUE shoes_canvas_slider(int, VALUE *, VALUE);
// from canvas.c, should be moved in canvas.h
#define SETUP_CANVAS() \
shoes_canvas *canvas; \
cairo_t *cr; \
Data_Get_Struct(self, shoes_canvas, canvas); \
cr = CCR(canvas)
#endif
#include "shoes/widget/slider.h"
// ruby
VALUE cSlider;
FUNC_M("+slider", slider, -1);
void shoes_slider_init() {
cSlider = rb_define_class_under(cTypes, "Slider", cNative);
rb_define_method(cSlider, "draw", CASTHOOK(shoes_slider_draw), 2);
rb_define_method(cSlider, "fraction", CASTHOOK(shoes_slider_get_fraction), 0);
rb_define_method(cSlider, "fraction=", CASTHOOK(shoes_slider_set_fraction), 1);
rb_define_method(cSlider, "change", CASTHOOK(shoes_control_change), -1);
RUBY_M("+slider", slider, -1);
}
VALUE shoes_slider_draw(VALUE self, VALUE c, VALUE actual) {
SETUP_CONTROL(0, 0, FALSE);
if (RTEST(actual)) {
if (self_t->ref == NULL) {
self_t->ref = shoes_native_slider(self, canvas, &place, self_t->attr, msg);
shoes_control_check_styles(self_t);
if (RTEST(ATTR(self_t->attr, fraction))) shoes_native_slider_set_fraction(self_t->ref, NUM2DBL(ATTR(self_t->attr, fraction)));
shoes_native_control_position(self_t->ref, &self_t->place, self, canvas, &place);
} else
shoes_native_control_repaint(self_t->ref, &self_t->place, canvas, &place);
}
FINISH();
return self;
}
VALUE shoes_slider_get_fraction(VALUE self) {
double perc = 0.;
GET_STRUCT(control, self_t);
if (self_t->ref != NULL)
perc = shoes_native_slider_get_fraction(self_t->ref);
return rb_float_new(perc);
}
VALUE shoes_slider_set_fraction(VALUE self, VALUE _perc) {
double perc = min(max(NUM2DBL(_perc), 0.0), 1.0);
GET_STRUCT(control, self_t);
if (self_t->ref != NULL)
shoes_native_slider_set_fraction(self_t->ref, perc);
return self;
}
// canvas
VALUE shoes_canvas_slider(int argc, VALUE *argv, VALUE self) {
rb_arg_list args;
VALUE slider;
SETUP_CANVAS();
rb_parse_args(argc, argv, "|h&", &args);
if (!NIL_P(args.a[1]))
ATTRSET(args.a[0], change, args.a[1]);
slider = shoes_control_new(cSlider, args.a[0], self);
shoes_add_ele(canvas, slider);
return slider;
} |
Don't forget to put the cocoa code in there. |
Uh? This proof-of-concept works with the inner layer of Shoes. It deals with Canvas and Ruby parts only. Gtk and Cocoa code absolutely untouched. Should work on MacOS X. |
My mistake - I thought you were add a new widget, not moving one around. I don't see much of simplification gain myself and a whole lot of work. |
The problem is we don't know for sure what is implied before moving one around. Remember, this comes from an idea without any certainty it would work without a major rewrite. This approach also need your feedback. It would use of a second pair of experienced eyes. Simplifications?
Not sure why you are not enthusiastic. It's at the very least interesting findings. Now that what needs to be proven is proven, it is possible to push the experiment further and implement a switch widget. I'm working with the broken MSYS2 target. Let's see how it goes. |
I'm not opposed if someone else does the work. Please create a branch for your experiments. |
Proof-of-concept and prototypes are my bread and butter. So, I get it, you're afraid to be stuck with the concept but no substance. You already know this is the way to go because you implemented svg and plot as module ... But still couldn't fully remove the strong ties to Ruby and Canvas. You have in fact now all you need for them to be truly module based on my work. Having common objectives. Aren't we a team? Sounds like a team... MSYS2 target will it be fixed? This would be a good news. |
Thanks, absolutely. Need to figure out how to do it first. :) |
* Decoupling Slider widget from Ruby and Canvas. * Improving ever so slightly Ruby and Canvas interface. * Removes duplicated call_cfunc from video. * shoes#333
|
* Decoupling Effect from Ruby and Canvas. * Improving ever so slightly Ruby and Canvas interface (again). * shoes#333
* Decoupling Button from Ruby and Canvas. * shoes#333
* Decoupling EditLine from Ruby and Canvas. * shoes#333
* Decoupling EditBox from Ruby and Canvas. * shoes#333
* Decoupling ListBox from Ruby and Canvas. * shoes#333
Most of them are relatively easy to move out of Ruby and Canvas. Some of them are a bit challenging, such as Ran AStyle on all the new files. Should be to your liking. What is |
TextEditBox is a future feature - there's an issue describing it and some thoughts. |
* Implementing Switch widget. * Implementing Switch native widget (GTK). * Improving ever so slightly Ruby and Canvas interface. * shoes#333
There is a new Sample code Shoes.app do
flow do
switch; para
end
flow do
@n = switch(active: true) do
@p.text = @n.active? unless @p.nil?
end
@p = para
end
flow do
@m = switch width: 80
@m.click do
@m.active? ? @e.start : @e.stop
end
@e = every(1) { |count| @q.text = count unless @q.nil? }
@q = para
end
start do
@e.stop
@p.text = @n.active?
@m.active = true
end
end |
Is it possible to change the on/off captions/labels that are displayed in the widget. More importanly, what's your assessment of whether moving all that code around leads to a better understanding of where to look for bugs - hard to assess, i know). |
I'm sorry about that. Refactoring Shoes comes with a price because Shoes is mostly monolithic. I had to start over several times while refactoring code. It is challenging now but it should make your life easier later. |
So you say. My life was fine. Your life might be easier. Do you happen to know a John Leake (perhaps in the UK but I suspect not, email header don't support that claim). I wasted a lot of time with that person and he's some sort of concern troll claiming he's 'very experienced' but can't be bothered to answer simple questions.
|
I spent a month on refactoring Shoes. It did worth every bit of efforts. Now you don't have to spend that amount of time on fixing errors, those you shown above are related to
Whaaat?! |
Along will all the new widgets and method needing implementation in Cocoa these look problematic
|
I do appreciate the effort, believe me. It will make fixing the all the Get_Struct changes we need to make to get to Ruby 2.3 become easier. Even better if when the rake files only compile changed .c/.h files. |
Thanks. Refactoring Rakefiles is also giving me a hard time. It's gonna take some time. I'm doing my best to avoid breaking builds but some is to be expected. MacOS X may have some different expectations when it comes to linking. My understanding from the last error you report is it needs function prototypes from canvas. I normally don't include canvas in types, just a very few necessary prototypes. |
OSX is compiling and linking with lots It Runs. Sadly It doesn't have any text in the buttons - but that's probably something silly on my part. |
Not so. shoes_native_button is unchanged in cocoa.m and lldb says the msg parameter points to "\b". Linux gdb has the correct value "Shoes Info". I'm confused. How could that happen the stack backtrace looks reasonable. |
* #ifdef GTK toolips in shoes/types widgets * add stubs for new widgets and app.methods - don't call them on OSX!
This is strange considering |
Found it. For shoes_native_button you added the attr parameter (to be consistent or tooltips or ..). Because I didn't include the shoes/types/type.h file properly, gcc didn't flag the signature change. So, it was my problem. |
While we are cleaning up I saw that in gtk.c shoes_open_browser won't work on Linux (or windows) . It doesn't seem to have any Shoes/ruby level api either. Delete or fix? |
What does it do? I was conservative with the changes. Tested features regularly. Most likely moves elsewhere. |
* remove #ifdef GTK, one widget at a time. * osx: no tips show up unless the OSX user moves the Shoes window refresh/paint issue? * osx hover delay is too long.
It open the given url in a browers - on osx it does an backticked I'm struggling with the switch widget. Why is the following line in shoes/native/gtk/gtkswitch.h
Should that be in shoes/native/switch.c (where cocoa/clang can find it). Actually cocoa sees the extern , it doesn't have the matching implementation. |
So we already have a replacement? Let's do as you deem best.
Actually, it should be in |
Thank you. Now compiling and linking for osx and linux. The widget code on OSX is stubbed out until I find a similar cocoa implementation on the interwebs. NSToggleButton or similar. |
* only tested for some widgets - it could fail for others. see Tests/tooltips.rb - make sure to click the window (focus/make active) first * makes switch widget visible for Cocoa implementation - to be done later. * add Tests/switch.rb
* 3.3.4? I don't see a complelling reason for this widget to require an OSX implementation.
* minimal OSX -- much to do since it's not a cocoa control its a Subclass of NSView so it doesn't get clicks and things with more code. doesn't work but harmless until called. * OSX switch widget is close but click handling is less than easy to understand and can be broken.
* someone should take away my obj->c programmer certificate assuming I have one. * had to fix some gtk stuff too. * It's good enough. Period. No Mas.
* doc changes * moving towards a 3.3.3 release.
* May become the downloaded Shoes once some problems are fixed * uses msys2 deps so it has a newer gtk3. MS-THEME needs it. Much tailoring of the Adwaita icons needs to be done. Bloat and slows Shoes. * Not Ready for prime time (xwin7 continues to work)
Shoes needs some refactoring and simplification in order to make it easier to understand and maintain. This issue is meant as notes for a future release.
We should enforce a coding style on every C and Objective-C files using
Artistic Style (astyle)
. This will ensure style consistency in the code.The
stub.c
is likely to be one of the reason antiviruses don't like Shoes.ShellExecute
is generally not welcome.It's hard to know where to start with this. It's not about rewriting the whole Shoes but we may consider restructuring, simplifying and splitting some code. Some code could be moved on Ruby side. Newest features like
svg
andplot
have their own module, which is excellent.There are oddities like struct definitions in the middle of
app.c
. There are also constant definitions a bit everywhere. There is dead code and commented code that would be best removed.The text was updated successfully, but these errors were encountered: