Back on the GUI programming, the timeline UI is a must for DAW. There were some implementations using ImGUI such as ImGuizmo’s ImSequencer or its improved version as ImNeoSequencer, or Sequentity.
The create our own we need do somthing like ruler and the cursor to indicate playback position.

The tricky part is understanding the cooridnate system in ImGui, its clipping region, and when window scrolling.
Let set padding to zero with ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ...), before start to create child window ImGui::BeginChild(..., ImGuiWindowFlags_HorizontalScrollbar).
Within child window block the ImGui::GetWindowDrawList will has its clipping region set for current child window. The cursor position should be on the top-left corner or {0, 0}.
Here the tricky part about coordinate system within child window block:
GetWindowPos()-> point in the screen coordinat for child window.GetWindowSize()-> size the visible child window area on screen.GetCursorPos()/SetCursorPos()-> point for current draw cursor in local coordinate for child window.GetCursorScreenPos()/SetCursorScreenPos-> point for current draw cursor in screen coordinate for child window.

Keep in mind that drawing using Draw List need to use screen coordinate. Since clipping already enabled, we may draw the ruler marker from the left or start of X position, even being clipped. The left side is in screen coordinate. The easy way to get the scrolled screen position is doing translate with SetCursorPos(0, ...) then GetCursorScreenPos().x.
Iterate during drawing along with moving the cursor in constant space until reach the right side. The right side is the length of contents but reaching only end of visible area is enough. For right side we need to get the right visible area on screen coordinate. Doing GetWindowPos + GetWindowSize will get the right side.

Drawing the playback cursor using AddConvexPolyFilled. To make cursor interactive such as able to receive mouse dragging, we can use InvisibleButton. Set the drawing cursor position with SetCursorPos into the left-corner of InvisibleButton with size w, h. Get the rect of InvisibleButton with GetItemRect{Min,Max}. Both functions will return a screen coordinate as an area for drawing a playback cursor.
ImVec2 points[] = {
{ rcmin.x, rcmin.y},
{ rcmin.x, rcmax.y - (cursor_wd/2)},
{ rcmin.x + (cursor_wd/2), rcmax.y},
{ rcmax.x, rcmax.y - (cursor_wd/2)},
{ rcmax.x, rcmin.y},
};
The order of polygon’s points should be in counter-clockwise. Draw the polygon with ImGuiCol_Button or ImGuiCol_SliderGrab color to use theme style.



