Building a Drawing App in React - Pt 2: Moving Elements | Tutorial

Поділитися
Вставка
  • Опубліковано 5 жов 2024
  • Continuing on from this first drawing app tutorial this video looks into how we can move elements that we have created. Also, sorry my microphone is terrible, I think it's time to buy a decent one.
    Useful Links:
    GitHub: github.com/red...
    Check if a point is on a line: stackoverflow....
    Excalidraw: excalidraw.com/
    Roughjs: roughjs.com/
    HTML Canvas (MDN): developer.mozi...
    ▬▬▬▬▬
    Hey everyone! My name is Redhwan Nacef (Red for short). In this channel, I'm hoping to share my thoughts on software engineering, coding, management, and all things tech. I hope you enjoy!
  • Наука та технологія

КОМЕНТАРІ • 41

  • @yogajourney9519
    @yogajourney9519 3 роки тому +2

    This is such a great series! Looking forward to following along with parts 3 and 4.

    • @RedhwanNacef
      @RedhwanNacef  3 роки тому

      Thanks, appreciate the great feedback!

  • @mayaahmed
    @mayaahmed 4 роки тому +1

    Thank you so much for this upload. Learned so much. Invaluable.

    • @RedhwanNacef
      @RedhwanNacef  4 роки тому

      Anytime, thank you for the feedback.

  • @vishvkakadiya5014
    @vishvkakadiya5014 3 роки тому +2

    This is insane man. Thanks for uploading

  • @RanveerSingh-ug6lu
    @RanveerSingh-ug6lu 2 роки тому +1

    awesome tutorial 👍

  • @rugvedb9842
    @rugvedb9842 2 роки тому +1

    Thankssss a lot. This is so helpful!!!

  • @icediver6
    @icediver6 3 роки тому +1

    Thank you for this great tutorial series! Do you know of a way to make a pencil using rough or in the same style?

    • @RedhwanNacef
      @RedhwanNacef  3 роки тому

      Thanks, glad you enjoyed it. Hmm, with roughjs I think you could try out the path api (github.com/rough-stuff/rough/wiki#path-d--options), and continuously update the path while drawing. Alternatively using the context lineTo api (developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineTo), but this might not quite give the style you are looking for without additional logic. Let me know how it goes!

  • @dinkdonk61
    @dinkdonk61 8 місяців тому

    was wondering if adding state management tool would be a good idea for this project any thoughts? also splitting the logic for resizing and moving into an different component would be much cleaner ?

  • @Fanaro
    @Fanaro 5 місяців тому

    The code is too small, and this really doesn't feel 1080p. But thanks for the tutorial though.

  • @v.demchenko
    @v.demchenko Місяць тому

    I don't know why, but i have wrong coordinates for elements.

  • @dota2content755
    @dota2content755 Рік тому

    The part two is really confusing, but nailed it ! Good reuse of functions, can you tell me If I can achieve the same functionality with p5.js ? I started building with it but got stuck when selecting elements and dragging resizing them.

    • @dota2content755
      @dota2content755 Рік тому

      Please reply...

    • @RedhwanNacef
      @RedhwanNacef  Рік тому +1

      Thanks. Sorry I am not familiar with p5.js so not sure I can help there. If there is a specific question you have about the code I am happy to try help.

    • @dota2content755
      @dota2content755 Рік тому

      Math.max and Math.min funcs you used on drag event to check the mouse is within want to know what you did there

  • @francovedia5584
    @francovedia5584 3 місяці тому

    thanks

  • @allsunday1485
    @allsunday1485 2 роки тому

    What about having more than one element that could be selected at a given x, y coordinate? How do you pick between them?

    • @RedhwanNacef
      @RedhwanNacef  2 роки тому

      Good question, right now the way it works is the most recent item will always be picked as we are simply looping through the elements in order. I guess we would have to add some sort of order to the elements, (most apps have the "send backward/forward" option) then we can loop based on that. Hope that makes sense.

    • @allsunday1485
      @allsunday1485 2 роки тому

      @@RedhwanNacef Thanks for the reply mate. Care to elaborate a bit on that send backward/forward option?

    • @allsunday1485
      @allsunday1485 2 роки тому

      @@RedhwanNacef also if in part 4 you talked about there being two main approaches to implementing undo/redo. What's the other one?

    • @RedhwanNacef
      @RedhwanNacef  2 роки тому

      Sure. When I say "send backward/forward", from a technical point of view this just means a way to order the elements that are on the same position on the canvas. So for example, if you move an element "forwards" in this case it would bring the element higher in the "elements" array, that way it would be found first when iterating over the items and selecting. There are other ways to achieve this like adding a property similar to "z-index" the elements themselves too and using that.

    • @RedhwanNacef
      @RedhwanNacef  2 роки тому

      I talk about the two in the beginning of the video. The first one is storing "actions/events" and using them actions to generate the final state. The way we went with is taking a snapshot of the entire state every time.

  • @rideforworld
    @rideforworld 3 роки тому

    can i save those pictures?

    • @RedhwanNacef
      @RedhwanNacef  3 роки тому

      You can usually save the canvas as an image using the toDataURL method: developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL. Hope this helps.

  • @adamtak3128
    @adamtak3128 4 роки тому

    Hey bro, Do you know anything about SlateJS Rich text editor for React?

    • @RedhwanNacef
      @RedhwanNacef  4 роки тому

      Hey, nope not heard of it before. Looks interesting though.

    • @adamtak3128
      @adamtak3128 4 роки тому

      @@RedhwanNacef It seems like its really popular and one of the most up to date tools for React but It's impossible finding anyone teaching how to properly use it. Their docs are kinda bad for new developers to use and learn from. In cases like that I usually go look for articles/videos but I haven't really been able to find anything worthwhile.

    • @RedhwanNacef
      @RedhwanNacef  4 роки тому

      It’s not something I’m familiar with but If there is reasonable interest I would be happy to look into it. In the mean time I’m sure you could raise an issue with documentation you feel is missing?

    • @varun29
      @varun29 4 роки тому +1

      Can u add more tools like pencil , resize , and more shapes in the next video

    • @RedhwanNacef
      @RedhwanNacef  4 роки тому +1

      I’m working on a video for resizing, will have that up soon. I have a few other videos I will be working on after, but will definitely come back to other shapes and pencils if there is interest.